]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-elf/elf.exp
elf: Add -z unique-symbol to avoid duplicated local symbol names
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2020 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 set ASFLAGS "$ASFLAGS --defsym NO_SET=1"
47 }
48
49 if { [istarget "*-*-solaris*"] } {
50 # Same for Solaris
51 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
52 }
53
54 if { [is_remote host] } then {
55 remote_download host merge.ld
56 }
57
58 # Note - the output file from the second test (symbol3w.a) is
59 # used in the proc is_elf64 test below...
60 run_ld_link_tests [list \
61 [list "Build symbol3.a" \
62 "" "" $hpux \
63 {symbol3.s} {} "symbol3.a" ] \
64 [list "Build symbol3w.a" \
65 "" "" "" \
66 {symbol3w.s} {} "symbol3w.a" ] \
67 ]
68
69
70 if [is_elf64 tmpdir/symbol3w.a] {
71 set ASFLAGS "$ASFLAGS --defsym ALIGN=3"
72 set pr23900_1_exp "pr23900-1-64.rd"
73 set pr25490_2_exp "pr25490-2-64.rd"
74 set pr25490_3_exp "pr25490-3-64.rd"
75 set pr25490_4_exp "pr25490-4-64.rd"
76 set pr25490_5_exp "pr25490-5-64.rd"
77 set pr25490_6_exp "pr25490-6-64.rd"
78 } else {
79 set ASFLAGS "$ASFLAGS --defsym ALIGN=2"
80 set pr23900_1_exp "pr23900-1-32.rd"
81 if { [istarget avr-*-*]
82 || [istarget h8300-*-*]
83 || [istarget ip2k-*-*]
84 || [istarget m68hc11-*]
85 || [istarget "xc16x-*"]
86 || [istarget "z80-*-*"] } {
87 set pr25490_2_exp "pr25490-2-16.rd"
88 set pr25490_3_exp "pr25490-3-16.rd"
89 set pr25490_4_exp "pr25490-4-16.rd"
90 set pr25490_5_exp "pr25490-5-16.rd"
91 set pr25490_6_exp "pr25490-6-16.rd"
92 } else {
93 set pr25490_2_exp "pr25490-2-32.rd"
94 set pr25490_3_exp "pr25490-3-32.rd"
95 set pr25490_4_exp "pr25490-4-32.rd"
96 set pr25490_5_exp "pr25490-5-32.rd"
97 set pr25490_6_exp "pr25490-6-32.rd"
98 }
99 }
100
101
102
103 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
104 run_ld_link_tests {
105 {"PR ld/21703"
106 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
107 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
108 {"PR ld/21703 -r"
109 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
110 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
111 } \[is_generic\]
112
113 if [is_underscore_target] {
114 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
115 }
116
117 set saved_ASFLAGS "$ASFLAGS"
118 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
119 set ASFLAGS "$ASFLAGS -mx86-used-note=no"
120 }
121
122 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
123 foreach t $test_list {
124 # We need to strip the ".d", but can leave the dirname.
125 verbose [file rootname $t]
126 run_dump_test [file rootname $t]
127 }
128
129 set ASFLAGS "$saved_ASFLAGS"
130
131 # Check that the --out-implib option work correctly.
132 # Targets that don't use elf.em won't support this.
133 run_ld_link_tests [list \
134 [list "Generate empty import library" \
135 "--out-implib=tmpdir/implib.lib" "" \
136 [concat "--defsym NO_GLOBAL=1" $hpux] \
137 {implib.s} \
138 {{ld empty-implib.out}} \
139 "implib" ] \
140 [list "Generate import library" \
141 "--out-implib=tmpdir/implib.lib" "" \
142 $hpux \
143 {implib.s} \
144 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
145 "implib" ] \
146 ] \[uses_genelf\]
147
148 #v850 gas complains about .tbss.var section attributes.
149 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
150 run_ld_link_tests {
151 {"--gc-sections on tls variable"
152 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
153 }
154 }
155
156 if { [istarget *-*-*linux*]
157 || [istarget *-*-nacl*]
158 || [istarget *-*-gnu*] } {
159 run_ld_link_tests [list \
160 [list "stack exec" \
161 "-z execstack" \
162 "" \
163 "" \
164 {stack.s} \
165 {{readelf {-Wl} stack-exec.rd}} \
166 "stack-exec.exe"] \
167 [list "stack noexec" \
168 "-z noexecstack" \
169 "" \
170 "" \
171 {stack.s} \
172 {{readelf {-Wl} stack-noexec.rd}} \
173 "stack-noexec.exe"] \
174 [list "stack size" \
175 "-z stack-size=0x123400" \
176 "" \
177 "" \
178 {stack.s} \
179 {{readelf {-Wl} stack-size.rd}} \
180 "stack-size.exe"] \
181 [list "PT_GNU_PROPERTY alignment" \
182 "" \
183 "" \
184 "" \
185 {pr23900-1.s} \
186 [list [list "readelf" {-Wl} $pr23900_1_exp]] \
187 "pr23900-1.exe"] \
188 ]
189 }
190
191 if [check_gc_sections_available] {
192 run_ld_link_tests [list \
193 [list "__patchable_function_entries section 2" \
194 "--gc-sections -e _start" \
195 "" \
196 "" \
197 {pr25490-2.s} \
198 [list [list "readelf" {-SW} $pr25490_2_exp]] \
199 "pr25490-2.exe"] \
200 [list "__patchable_function_entries section 3" \
201 "--gc-sections -e _start" \
202 "" \
203 "" \
204 {pr25490-3.s} \
205 [list [list "readelf" {-SW} $pr25490_3_exp]] \
206 "pr25490-3.exe"] \
207 [list "__patchable_function_entries section 4" \
208 "--gc-sections -e _start" \
209 "" \
210 "" \
211 {pr25490-4.s} \
212 [list [list "readelf" {-SW} $pr25490_4_exp]] \
213 "pr25490-4.exe"] \
214 [list "__patchable_function_entries section 5" \
215 "--gc-sections -e _start" \
216 "" \
217 "" \
218 {pr25490-5.s} \
219 [list [list "readelf" {-SW} $pr25490_5_exp]] \
220 "pr25490-5.exe"] \
221 [list "__patchable_function_entries section 6" \
222 "--gc-sections -e _start" \
223 "" \
224 "" \
225 {pr25490-6.s} \
226 [list [list "readelf" {-SW} $pr25490_6_exp]] \
227 "pr25490-6.exe"] \
228 ]
229 }
230
231 set LDFLAGS $old_ldflags
232 set ASFLAGS $old_asflags
233
234 # Check to see if the C compiler works
235 if { ![check_compiler_available] } {
236 return
237 }
238
239 if [check_gc_sections_available] {
240 run_cc_link_tests {
241 {"PR ld/13195" "-Wl,--gc-sections" ""
242 {pr13195.c} {} "pr13195"}
243 }
244 }
245
246 set array_tests {
247 {"preinit array" "" ""
248 {preinit.c} "preinit" "preinit.out"}
249 {"init array" "" ""
250 {init.c} "init" "init.out"}
251 {"fini array" "" ""
252 {fini.c} "fini" "fini.out"}
253 {"init array mixed" "" ""
254 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
255 }
256 set array_tests_pie {
257 {"PIE preinit array" "-pie" ""
258 {preinit.c} "preinit" "preinit.out" "-fPIE"}
259 {"PIE init array" "-pie" ""
260 {init.c} "init" "init.out" "-fPIE"}
261 {"PIE fini array" "-pie" ""
262 {fini.c} "fini" "fini.out" "-fPIE"}
263 {"PIE init array mixed" "-pie" ""
264 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
265 {"PIE PR ld/14525" "-pie" ""
266 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
267 }
268 set array_tests_static {
269 {"static preinit array" "-static" ""
270 {preinit.c} "preinit" "preinit.out"}
271 {"static init array" "-static" ""
272 {init.c} "init" "init.out"}
273 {"static fini array" "-static" ""
274 {fini.c} "fini" "fini.out"}
275 {"static init array mixed" "-static" ""
276 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
277 }
278
279 # NetBSD ELF systems do not currently support the .*_array sections.
280 set xfails "*-*-netbsdelf*"
281 run_ld_link_exec_tests $array_tests $xfails
282
283 if { [istarget *-*-linux*]
284 || [istarget *-*-nacl*]
285 || [istarget *-*-gnu*] } {
286 run_ld_link_exec_tests $array_tests_pie $xfails
287
288 if { $STATIC_PIE_LDFLAGS != "" } then {
289 run_ld_link_exec_tests [list \
290 [list \
291 "Static PIE preinit array" \
292 "$STATIC_PIE_LDFLAGS" \
293 "" \
294 {preinit.c} \
295 "preinit-static-pie" \
296 "preinit.out" \
297 "-fPIE" \
298 ] \
299 [list \
300 "Static PIE init array" \
301 "$STATIC_PIE_LDFLAGS" \
302 "" \
303 {init.c} \
304 "init-static-pie" \
305 "init.out" \
306 "-fPIE" \
307 ] \
308 [list \
309 "Static PIE fini array" \
310 "$STATIC_PIE_LDFLAGS" \
311 "" \
312 {fini.c} \
313 "fini-static-pie" \
314 "fini.out" \
315 "-fPIE" \
316 ] \
317 [list \
318 "Static PIE init array mixed" \
319 "$STATIC_PIE_LDFLAGS" \
320 "" \
321 {init-mixed.c} \
322 "init-mixed-static-pie" \
323 "init-mixed.out" \
324 "-I. -fPIE" \
325 ] \
326 [list \
327 "Static PIE PR ld/14525" \
328 "$STATIC_PIE_LDFLAGS" \
329 "" \
330 {pr14525.c} \
331 "pr14525-static-pie" \
332 "pr14525.out" \
333 "-fPIE" \
334 ] \
335 ]
336 }
337
338 run_ld_link_exec_tests [list \
339 [list \
340 "Run mbind2a" \
341 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
342 "" \
343 { mbind2a.s mbind2b.c } \
344 "mbind2a" \
345 "pass.out" \
346 "-O2 -I../bfd" \
347 ] \
348 [list \
349 "Run mbind2b" \
350 "-static -Wl,-z,common-page-size=0x4000" \
351 "" \
352 { mbind2a.s mbind2b.c } \
353 "mbind2b" \
354 "pass.out" \
355 "-O2 -I../bfd" \
356 ] \
357 ]
358 }
359
360 run_ld_link_exec_tests $array_tests_static $xfails
361
362 run_cc_link_tests [list \
363 [list \
364 "Build pr26391-1" \
365 "-Wl,-z,unique-symbol" \
366 "-fno-function-sections" \
367 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
368 {{nm "" pr26391.nd}} \
369 "pr26391-1" \
370 ] \
371 [list \
372 "Build pr26391-2" \
373 "-Wl,-z,unique-symbol" \
374 "-ffunction-sections" \
375 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
376 {{nm "" pr26391.nd}} \
377 "pr26391-2" \
378 ] \
379 [list \
380 "Build pr26391-3" \
381 "-Wl,-z,unique-symbol,--emit-relocs" \
382 "-fno-function-sections" \
383 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
384 {{nm "" pr26391.nd}} \
385 "pr26391-3" \
386 ] \
387 [list \
388 "Build pr26391-4" \
389 "-Wl,-z,unique-symbol,--emit-relocs" \
390 "-ffunction-sections" \
391 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
392 {{nm "" pr26391.nd}} \
393 "pr26391-4" \
394 ] \
395 ]
396
397 run_ld_link_tests [list \
398 [list \
399 "Build pr26391-5.o" \
400 "-z unique-symbol -r" \
401 "" \
402 "" \
403 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
404 {{nm "" pr26391.nd}} \
405 "pr26391-5.o" \
406 "-fno-function-sections" \
407 ] \
408 [list \
409 "Build pr26391-6.o" \
410 "-z unique-symbol -r" \
411 "" \
412 "" \
413 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
414 {{nm "" pr26391.nd}} \
415 "pr26391-6.o" \
416 "-ffunction-sections" \
417 ] \
418 ]
419
420 run_ld_link_exec_tests [list \
421 [list \
422 "Run pr26391-1" \
423 "-Wl,-z,unique-symbol" \
424 "" \
425 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
426 "pr26391-1" \
427 "pr26391.out" \
428 "-fno-function-sections" \
429 ] \
430 [list \
431 "Run pr26391-2" \
432 "-Wl,-z,unique-symbol" \
433 "" \
434 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
435 "pr26391-2" \
436 "pr26391.out" \
437 "-ffunction-sections" \
438 ] \
439 [list \
440 "Run pr26391-3" \
441 "-Wl,-z,unique-symbol,--emit-relocs" \
442 "" \
443 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
444 "pr26391-3" \
445 "pr26391.out" \
446 "-fno-function-sections" \
447 ] \
448 [list \
449 "Run pr26391-4" \
450 "-Wl,-z,unique-symbol,--emit-relocs" \
451 "" \
452 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
453 "pr26391-4" \
454 "pr26391.out" \
455 "-ffunction-sections" \
456 ] \
457 [list \
458 "Run pr26391-5" \
459 "-Wl,-z,unique-symbol" \
460 "" \
461 {dummy.c} \
462 "pr26391-5" \
463 "pr26391.out" \
464 "" \
465 "c" \
466 "" \
467 "tmpdir/pr26391-5.o" \
468 ] \
469 [list \
470 "Run pr26391-6" \
471 "-Wl,-z,unique-symbol" \
472 "" \
473 {dummy.c} \
474 "pr26391-6" \
475 "pr26391.out" \
476 "" \
477 "c" \
478 "" \
479 "tmpdir/pr26391-6.o" \
480 ] \
481 ]
482
483 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status