[BFD][PR21703]Override the new defined symbol with the old normal symbol when --allow...
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2017 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21
22 # Exclude non-ELF targets.
23
24 if ![is_elf_format] {
25 return
26 }
27
28 set old_ldflags $LDFLAGS
29 if { [istarget spu*-*-*] } {
30 set LDFLAGS "$LDFLAGS --local-store 0:0"
31 }
32
33 # hpux .comm differs from everyone else
34 set hpux ""
35 set old_asflags $ASFLAGS
36 if [istarget "*-*-hpux*"] {
37 set hpux "--defsym HPUX=1"
38 set ASFLAGS "$ASFLAGS --defsym HPUX=1"
39 }
40
41 if { [istarget alpha*-*-* ] } {
42 # The compress1 test is written expecting 32-bit addresses; force the
43 # executable down into the low address space to match.
44 # ??? How can we adjust just the one testcase?
45 set LDFLAGS "$LDFLAGS -Ttext-segment 0x1000000"
46 }
47
48 if { [istarget "*-*-nacl*"] } {
49 # The eh[1-4] cases are written to expect ELFCLASS64 layout on x86-64.
50 # But the target default is ELFCLASS32. So the cases explicitly use
51 # -melf_x86_64 to select that, but NaCl needs a different emulation name.
52 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_nacl}
53 }
54
55 if { [istarget "*-*-solaris*"] } {
56 # Same for Solaris
57 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
58 }
59
60 if { [is_remote host] } then {
61 remote_download host merge.ld
62 }
63
64 run_ld_link_tests [list \
65 [list "Build symbol3.a" \
66 "" "" $hpux \
67 {symbol3.s} {} "symbol3.a" ] \
68 [list "Build symbol3w.a" \
69 "" "" "" \
70 {symbol3w.s} {} "symbol3w.a" ] \
71 ]
72
73 run_ld_link_tests [list \
74 [list "PR ld/21703" \
75 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
76 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" ] \
77 [list "PR ld/21703 -r" \
78 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
79 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" ] \
80 [list "PR ld/21703 shared" \
81 "-shared --allow-multiple-definition --version-script pr21703.ver tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
82 {pr21703-3.s pr21703-4.s} {{readelf {--dyn-syms} pr21703-shared.sd}} "pr21703.so" ] \
83 ]
84
85 if { [check_shared_lib_support] } then {
86 run_ld_link_tests {
87 {"Build pr14170a.o" "" "" "" {pr14170a.s} {} "pr14170.a" }
88 }
89 setup_xfail "tic6x-*-*"
90 run_ld_link_tests {
91 {"Build shared library for pr14170"
92 "-shared" "" "" "pr14170b.s" {} "pr14170.so" }
93 }
94 # bfin does not currently support copy relocs.
95 setup_xfail "bfin-*-*"
96 run_ld_link_tests [list \
97 [list "PR ld/14170" \
98 "--no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" $hpux \
99 {pr14170c.s} { } "pr14170" ] \
100 ]
101 }
102
103 # Only run these tests on targets that support creating shared libraries.
104 if { [check_shared_lib_support] } then {
105 # This target requires extra GAS options when building non-PIC code
106 # for linking with shared libraries.
107 set AFLAGS_NONPIC ""
108 if [istarget "mips*-*-*"] {
109 append AFLAGS_NONPIC " -call_nonpic"
110 }
111
112 # Run a test to check linking a shared library with a broken linker
113 # script that accidentally marks dynamic sections as notes. The
114 # resulting executable is not expected to work, but the linker
115 # should not seg-fault whilst creating the binary.
116 setup_xfail "tic6x-*-*"
117 run_ld_link_tests {
118 {"Build shared library for next test"
119 "-shared --hash-style=sysv" "" "" "note-3.s" {} "note-3.so" }
120 {"Link using broken linker script"
121 "--script note-3.t tmpdir/note-3.so" "" "" ""
122 { { ld "note-3.l" } }
123 "a.out" }
124 }
125 setup_xfail "tic6x-*-*"
126 run_ld_link_tests {
127 {"Build pr17068.so"
128 "-shared" "" ""
129 {pr17068d.s} {} "pr17068.so"}
130 {"Build pr17068a.a"
131 "" "" ""
132 {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"}
133 {"Build pr17068b.a"
134 "" "" ""
135 {pr17068b.s pr17068e.s} {} "pr17068b.a"}
136 }
137 # bfin does not currently support copy relocs.
138 setup_xfail "bfin-*-*"
139 run_ld_link_tests {
140 {"pr17068 link --as-needed lib in group"
141 "--as-needed --no-dynamic-linker" "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a --end-group" ""
142 {start.s pr17068.s} {} "pr17068"}
143 }
144 # xfail on tic6x due to non-PIC/non-PID warnings
145 setup_xfail "tic6x-*-*"
146 # Fails on MIPS because ABI trickery means that a NULL reloc is also emitted.
147 setup_xfail "mips*-*-*"
148 # Fails on bfin because relocations are not created.
149 setup_xfail "bfin-*-*"
150 run_ld_link_tests {
151 {"-Bsymbolic-functions"
152 "-shared -Bsymbolic-functions" "" ""
153 {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}}
154 "symbolic-func.so"}
155 }
156 # xfail on tic6x due to non-PIC/non-PID warnings
157 setup_xfail "tic6x-*-*"
158 run_ld_link_tests {
159 {"Build pr20995.so"
160 "-shared" "" ""
161 {pr20995b.s} {} "pr20995.so"}
162 }
163 setup_xfail "tic6x-*-*"
164 # xfail on arm*-*-eabi*. The list can be enlarged to those targets that
165 # don't support GNU_RELRO. For more details, please see discussions at:
166 # https://sourceware.org/ml/binutils/2017-01/msg00441.html
167 setup_xfail "arm*-*-eabi*" "hppa*64*-*-hpux*"
168 run_ld_link_tests {
169 {"Build pr20995-2.so"
170 "-shared -z relro" "" ""
171 {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"}
172 }
173 # These targets don't copy dynamic variables into .bss.
174 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*"
175 # or don't have .data.rel.ro
176 setup_xfail "hppa*64*-*-hpux*"
177 run_ld_link_tests [list \
178 [list \
179 "pr20995" \
180 "" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \
181 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]]
182 # xfail on arm*-*-eabi* is particularly because of no support of GNU_RELRO.
183 # Please see the link above for details.
184 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" "arm*-*-eabi*"
185 setup_xfail "hppa*64*-*-hpux*"
186 run_ld_link_tests [list \
187 [list \
188 "pr20995-2" \
189 "" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \
190 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"]]
191 }
192
193 if [is_underscore_target] {
194 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
195 }
196
197 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
198 foreach t $test_list {
199 # We need to strip the ".d", but can leave the dirname.
200 verbose [file rootname $t]
201 run_dump_test [file rootname $t]
202 }
203
204 # Targets using the generic linker backend don't support generating
205 # an import library.
206 set xfail_implib ""
207 if [is_generic_elf] {
208 set xfail_implib "*-*-*"
209 }
210
211 # Check that the --out-implib option work correctly.
212 run_ld_link_tests [list \
213 [list "Generate empty import library" \
214 "--out-implib=tmpdir/implib.lib" "" \
215 [concat "--defsym NO_GLOBAL=1" $hpux] \
216 {implib.s} \
217 {{ld empty-implib.out}} \
218 "implib" ] \
219 [list "Generate import library" \
220 "--out-implib=tmpdir/implib.lib" "" \
221 $hpux \
222 {implib.s} \
223 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
224 "implib" ] \
225 ] $xfail_implib
226
227 if { [istarget *-*-linux*]
228 || [istarget *-*-nacl*]
229 || [istarget *-*-gnu*] } {
230 run_ld_link_tests {
231 {"Weak symbols in dynamic objects 1 (support)"
232 "-shared" "" "" {weak-dyn-1a.s}
233 {}
234 "libweakdyn1a.so"}
235 {"Weak symbols in dynamic objects 1 (main test)"
236 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
237 {{readelf {--relocs --wide} weak-dyn-1.rd}}
238 "libweakdyn1b.so"}
239 }
240 }
241
242 #v850 gas complains about .tbss.var section attributes.
243 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
244 run_ld_link_tests {
245 {"--gc-sections on tls variable"
246 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
247 }
248 }
249
250 if { [istarget *-*-*linux*]
251 || [istarget *-*-nacl*]
252 || [istarget *-*-gnu*] } {
253 run_ld_link_tests {
254 {"stack exec" "-z execstack" "" "" {stack.s}
255 {{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"}
256 {"stack size" "-z stack-size=0x123400" "" "" {stack.s}
257 {{readelf {-Wl} stack-size.rd}} "stack-size.exe"}
258 }
259 }
260
261 set LDFLAGS $old_ldflags
262 set ASFLAGS $old_asflags
263
264 # Check to see if the C compiler works
265 if { [which $CC] == 0 } {
266 return
267 }
268
269 if [check_gc_sections_available] {
270 run_cc_link_tests {
271 {"PR ld/13195" "-Wl,--gc-sections" ""
272 {pr13195.c} {} "pr13195"}
273 }
274 }
275
276 set array_tests {
277 {"preinit array" "" ""
278 {preinit.c} "preinit" "preinit.out"}
279 {"init array" "" ""
280 {init.c} "init" "init.out"}
281 {"fini array" "" ""
282 {fini.c} "fini" "fini.out"}
283 {"init array mixed" "" ""
284 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
285 }
286 set array_tests_pie {
287 {"PIE preinit array" "-pie" ""
288 {preinit.c} "preinit" "preinit.out" "-fPIE"}
289 {"PIE init array" "-pie" ""
290 {init.c} "init" "init.out" "-fPIE"}
291 {"PIE fini array" "-pie" ""
292 {fini.c} "fini" "fini.out" "-fPIE"}
293 {"PIE init array mixed" "-pie" ""
294 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
295 {"PIE PR ld/14525" "-pie" ""
296 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
297 }
298 set array_tests_static {
299 {"static preinit array" "-static" ""
300 {preinit.c} "preinit" "preinit.out"}
301 {"static init array" "-static" ""
302 {init.c} "init" "init.out"}
303 {"static fini array" "-static" ""
304 {fini.c} "fini" "fini.out"}
305 {"static init array mixed" "-static" ""
306 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
307 }
308
309 # NetBSD ELF systems do not currently support the .*_array sections.
310 set xfails "*-*-netbsdelf*"
311 run_ld_link_exec_tests $array_tests $xfails
312
313 if { [istarget *-*-linux*]
314 || [istarget *-*-nacl*]
315 || [istarget *-*-gnu*] } {
316 run_ld_link_exec_tests $array_tests_pie $xfails
317
318 run_ld_link_exec_tests [list \
319 [list \
320 "Run mbind2a" \
321 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
322 "" \
323 { mbind2a.s mbind2b.c } \
324 "mbind2a" \
325 "pass.out" \
326 "-O2 -I../bfd" \
327 ] \
328 [list \
329 "Run mbind2b" \
330 "-static -Wl,-z,common-page-size=0x4000" \
331 "" \
332 { mbind2a.s mbind2b.c } \
333 "mbind2b" \
334 "pass.out" \
335 "-O2 -I../bfd" \
336 ] \
337 ]
338 }
339
340 # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
341 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
342 switch -regexp $target_triplet {
343 ^\[^-\]*-\[^-\]*-gnu.*$ {
344 set xfails "*-*-*"
345 }
346 }
347 run_ld_link_exec_tests $array_tests_static $xfails
348
349 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status
This page took 0.039808 seconds and 5 git commands to generate.