ld: Add --export-dynamic-symbol and --export-dynamic-symbol-list
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
CommitLineData
782c0ebf 1# Expect script for various ELF tests.
b3adc24a 2# Copyright (C) 2002-2020 Free Software Foundation, Inc.
b7b0b729 3#
f96b4a7b
NC
4# This file is part of the GNU Binutils.
5#
6# This program is free software; you can redistribute it and/or modify
b7b0b729 7# it under the terms of the GNU General Public License as published by
f96b4a7b 8# the Free Software Foundation; either version 3 of the License, or
b7b0b729
HPN
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
f96b4a7b
NC
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
b7b0b729 20#
b7b0b729
HPN
21
22# Exclude non-ELF targets.
23
43f9d75b 24if ![is_elf_format] {
b7b0b729
HPN
25 return
26}
27
e4970690 28set old_ldflags $LDFLAGS
9f264ea9
AM
29if { [istarget spu*-*-*] } {
30 set LDFLAGS "$LDFLAGS --local-store 0:0"
31}
dd803a24
AM
32
33# hpux .comm differs from everyone else
34set hpux ""
35set old_asflags $ASFLAGS
36if [istarget "*-*-hpux*"] {
37 set hpux "--defsym HPUX=1"
38 set ASFLAGS "$ASFLAGS --defsym HPUX=1"
39}
40
991cda6c
RH
41if { [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"
54975ae9 46 set ASFLAGS "$ASFLAGS --defsym NO_SET=1"
991cda6c 47}
9f264ea9 48
7cf492ee
RM
49if { [istarget "*-*-nacl*"] } {
50 # The eh[1-4] cases are written to expect ELFCLASS64 layout on x86-64.
51 # But the target default is ELFCLASS32. So the cases explicitly use
52 # -melf_x86_64 to select that, but NaCl needs a different emulation name.
53 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_nacl}
54}
55
5cc51864
L
56if { [istarget "*-*-solaris*"] } {
57 # Same for Solaris
58 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
59}
60
7f6a71ff
JM
61if { [is_remote host] } then {
62 remote_download host merge.ld
63}
64
b77db948
NC
65# Note - the output file from the second test (symbol3w.a) is
66# used in the proc is_elf64 test below...
dd803a24
AM
67run_ld_link_tests [list \
68 [list "Build symbol3.a" \
69 "" "" $hpux \
70 {symbol3.s} {} "symbol3.a" ] \
71 [list "Build symbol3w.a" \
72 "" "" "" \
73 {symbol3w.s} {} "symbol3w.a" ] \
74]
75
b77db948 76
b77db948
NC
77if [is_elf64 tmpdir/symbol3w.a] {
78 set ASFLAGS "$ASFLAGS --defsym ALIGN=3"
0a59decb 79 set pr23900_1_exp "pr23900-1-64.rd"
b7d07216
L
80 set pr25490_2_exp "pr25490-2-64.rd"
81 set pr25490_3_exp "pr25490-3-64.rd"
82 set pr25490_4_exp "pr25490-4-64.rd"
83 set pr25490_5_exp "pr25490-5-64.rd"
84 set pr25490_6_exp "pr25490-6-64.rd"
b77db948
NC
85} else {
86 set ASFLAGS "$ASFLAGS --defsym ALIGN=2"
0a59decb 87 set pr23900_1_exp "pr23900-1-32.rd"
b7d07216
L
88 if { [istarget avr-*-*]
89 || [istarget h8300-*-*]
90 || [istarget ip2k-*-*]
91 || [istarget m68hc11-*]
92 || [istarget "xc16x-*"]
93 || [istarget "z80-*-*"] } {
94 set pr25490_2_exp "pr25490-2-16.rd"
95 set pr25490_3_exp "pr25490-3-16.rd"
96 set pr25490_4_exp "pr25490-4-16.rd"
97 set pr25490_5_exp "pr25490-5-16.rd"
98 set pr25490_6_exp "pr25490-6-16.rd"
99 } else {
100 set pr25490_2_exp "pr25490-2-32.rd"
101 set pr25490_3_exp "pr25490-3-32.rd"
102 set pr25490_4_exp "pr25490-4-32.rd"
103 set pr25490_5_exp "pr25490-5-32.rd"
104 set pr25490_6_exp "pr25490-6-32.rd"
105 }
b77db948
NC
106}
107
108
109
46b06a98 110# Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
506981af
RL
111run_ld_link_tests {
112 {"PR ld/21703"
93f4de39 113 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
506981af 114 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
506981af 115 {"PR ld/21703 -r"
93f4de39 116 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
506981af 117 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
1336939d 118} \[is_generic\]
93f4de39 119
bdd32e03
AM
120if [is_underscore_target] {
121 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
122}
123
e9d644e8
L
124global ASFLAGS
125set saved_ASFLAGS "$ASFLAGS"
126if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
127 set ASFLAGS "$ASFLAGS -mx86-used-note=no"
128}
129
782c0ebf
AM
130set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
131foreach t $test_list {
132 # We need to strip the ".d", but can leave the dirname.
133 verbose [file rootname $t]
134 run_dump_test [file rootname $t]
135}
24edc24d 136
e9d644e8
L
137set ASFLAGS "$saved_ASFLAGS"
138
76359541 139# Check that the --out-implib option work correctly.
075a2b89 140# Targets that don't use elf.em won't support this.
dd803a24
AM
141run_ld_link_tests [list \
142 [list "Generate empty import library" \
143 "--out-implib=tmpdir/implib.lib" "" \
144 [concat "--defsym NO_GLOBAL=1" $hpux] \
145 {implib.s} \
146 {{ld empty-implib.out}} \
147 "implib" ] \
148 [list "Generate import library" \
149 "--out-implib=tmpdir/implib.lib" "" \
150 $hpux \
151 {implib.s} \
152 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
153 "implib" ] \
1336939d 154] \[uses_genelf\]
76359541 155
78336cd6
AM
156#v850 gas complains about .tbss.var section attributes.
157if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
430a16a5
NC
158 run_ld_link_tests {
159 {"--gc-sections on tls variable"
897aea50 160 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
430a16a5
NC
161 }
162}
163
6b00ac5a 164if { [istarget *-*-*linux*]
b3adb10f 165 || [istarget *-*-nacl*]
9cc420b6 166 || [istarget *-*-gnu*] } {
0a59decb
L
167 run_ld_link_tests [list \
168 [list "stack exec" \
169 "-z execstack" \
170 "" \
171 "" \
172 {stack.s} \
173 {{readelf {-Wl} stack-exec.rd}} \
174 "stack-exec.exe"] \
175 [list "stack noexec" \
176 "-z noexecstack" \
177 "" \
178 "" \
179 {stack.s} \
180 {{readelf {-Wl} stack-noexec.rd}} \
181 "stack-noexec.exe"] \
182 [list "stack size" \
183 "-z stack-size=0x123400" \
184 "" \
185 "" \
186 {stack.s} \
187 {{readelf {-Wl} stack-size.rd}} \
188 "stack-size.exe"] \
189 [list "PT_GNU_PROPERTY alignment" \
190 "" \
191 "" \
192 "" \
193 {pr23900-1.s} \
194 [list [list "readelf" {-Wl} $pr23900_1_exp]] \
195 "pr23900-1.exe"] \
196 ]
04c3a755
NS
197}
198
b7d07216
L
199if [check_gc_sections_available] {
200 run_ld_link_tests [list \
201 [list "__patchable_function_entries section 2" \
202 "--gc-sections -e _start" \
203 "" \
204 "" \
205 {pr25490-2.s} \
206 [list [list "readelf" {-SW} $pr25490_2_exp]] \
207 "pr25490-2.exe"] \
208 [list "__patchable_function_entries section 3" \
209 "--gc-sections -e _start" \
210 "" \
211 "" \
212 {pr25490-3.s} \
213 [list [list "readelf" {-SW} $pr25490_3_exp]] \
214 "pr25490-3.exe"] \
215 [list "__patchable_function_entries section 4" \
216 "--gc-sections -e _start" \
217 "" \
218 "" \
219 {pr25490-4.s} \
220 [list [list "readelf" {-SW} $pr25490_4_exp]] \
221 "pr25490-4.exe"] \
222 [list "__patchable_function_entries section 5" \
223 "--gc-sections -e _start" \
224 "" \
225 "" \
226 {pr25490-5.s} \
227 [list [list "readelf" {-SW} $pr25490_5_exp]] \
228 "pr25490-5.exe"] \
229 [list "__patchable_function_entries section 6" \
230 "--gc-sections -e _start" \
231 "" \
232 "" \
233 {pr25490-6.s} \
234 [list [list "readelf" {-SW} $pr25490_6_exp]] \
235 "pr25490-6.exe"] \
236 ]
237}
238
e4970690 239set LDFLAGS $old_ldflags
dd803a24 240set ASFLAGS $old_asflags
e4970690 241
4ce6ca2c 242# Check to see if the C compiler works
44ed8092 243if { ![check_compiler_available] } {
4ce6ca2c
AM
244 return
245}
246
a130722b
L
247if [check_gc_sections_available] {
248 run_cc_link_tests {
249 {"PR ld/13195" "-Wl,--gc-sections" ""
250 {pr13195.c} {} "pr13195"}
251 }
54e8959c
L
252}
253
24edc24d 254set array_tests {
d9816402
AM
255 {"preinit array" "" ""
256 {preinit.c} "preinit" "preinit.out"}
257 {"init array" "" ""
258 {init.c} "init" "init.out"}
259 {"fini array" "" ""
260 {fini.c} "fini" "fini.out"}
261 {"init array mixed" "" ""
262 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
310fd250
L
263}
264set array_tests_pie {
d9816402
AM
265 {"PIE preinit array" "-pie" ""
266 {preinit.c} "preinit" "preinit.out" "-fPIE"}
267 {"PIE init array" "-pie" ""
268 {init.c} "init" "init.out" "-fPIE"}
269 {"PIE fini array" "-pie" ""
270 {fini.c} "fini" "fini.out" "-fPIE"}
271 {"PIE init array mixed" "-pie" ""
272 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
273 {"PIE PR ld/14525" "-pie" ""
274 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
5940a93c
TS
275}
276set array_tests_static {
d9816402
AM
277 {"static preinit array" "-static" ""
278 {preinit.c} "preinit" "preinit.out"}
279 {"static init array" "-static" ""
280 {init.c} "init" "init.out"}
281 {"static fini array" "-static" ""
282 {fini.c} "fini" "fini.out"}
283 {"static init array mixed" "-static" ""
284 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
24edc24d
L
285}
286
c8c140d9 287# NetBSD ELF systems do not currently support the .*_array sections.
982c6f26
AM
288set xfails "*-*-netbsdelf*"
289run_ld_link_exec_tests $array_tests $xfails
310fd250 290
3fee20ef 291if { [istarget *-*-linux*]
5a68afcf 292 || [istarget *-*-nacl*]
3fee20ef 293 || [istarget *-*-gnu*] } {
982c6f26 294 run_ld_link_exec_tests $array_tests_pie $xfails
a91e1603 295
b3d7a867
L
296 if { $STATIC_PIE_LDFLAGS != "" } then {
297 run_ld_link_exec_tests [list \
298 [list \
299 "Static PIE preinit array" \
300 "$STATIC_PIE_LDFLAGS" \
301 "" \
302 {preinit.c} \
303 "preinit-static-pie" \
304 "preinit.out" \
305 "-fPIE" \
306 ] \
307 [list \
308 "Static PIE init array" \
309 "$STATIC_PIE_LDFLAGS" \
310 "" \
311 {init.c} \
312 "init-static-pie" \
313 "init.out" \
314 "-fPIE" \
315 ] \
316 [list \
317 "Static PIE fini array" \
318 "$STATIC_PIE_LDFLAGS" \
319 "" \
320 {fini.c} \
321 "fini-static-pie" \
322 "fini.out" \
323 "-fPIE" \
324 ] \
325 [list \
326 "Static PIE init array mixed" \
327 "$STATIC_PIE_LDFLAGS" \
328 "" \
329 {init-mixed.c} \
330 "init-mixed-static-pie" \
331 "init-mixed.out" \
332 "-I. -fPIE" \
333 ] \
334 [list \
335 "Static PIE PR ld/14525" \
336 "$STATIC_PIE_LDFLAGS" \
337 "" \
338 {pr14525.c} \
339 "pr14525-static-pie" \
340 "pr14525.out" \
341 "-fPIE" \
342 ] \
343 ]
344 }
345
a91e1603
L
346 run_ld_link_exec_tests [list \
347 [list \
348 "Run mbind2a" \
349 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
350 "" \
351 { mbind2a.s mbind2b.c } \
352 "mbind2a" \
353 "pass.out" \
354 "-O2 -I../bfd" \
355 ] \
356 [list \
357 "Run mbind2b" \
358 "-static -Wl,-z,common-page-size=0x4000" \
359 "" \
360 { mbind2a.s mbind2b.c } \
361 "mbind2b" \
362 "pass.out" \
363 "-O2 -I../bfd" \
364 ] \
365 ]
310fd250
L
366}
367
982c6f26 368run_ld_link_exec_tests $array_tests_static $xfails
9ab80182 369
02ecc8e9 370catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status
This page took 0.841402 seconds and 4 git commands to generate.