ld: Add --export-dynamic-symbol and --export-dynamic-symbol-list
[deliverable/binutils-gdb.git] / ld / testsuite / config / default.exp
1 # Basic expect script for LD Regression Tests
2 # Copyright (C) 1993-2020 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This file 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 # Written by Jeffrey Wheat (cassidy@cygnus.com)
22 #
23
24 if ![info exists ld] then {
25 set ld [findfile $base_dir/ld-new $base_dir/ld-new [transform ld]]
26 }
27
28 if ![info exists as] then {
29 set as [findfile $base_dir/../gas/as-new $base_dir/../gas/as-new [transform as]]
30 }
31
32 if ![info exists nm] then {
33 set nm [findfile $base_dir/../binutils/nm-new $base_dir/../binutils/nm-new [transform nm]]
34 }
35
36 if ![info exists objdump] then {
37 set objdump [findfile $base_dir/../binutils/objdump]
38 }
39
40 if ![info exists objcopy] then {
41 set objcopy [findfile $base_dir/../binutils/objcopy]
42 }
43
44 if ![info exists ar] then {
45 set ar [findfile $base_dir/../binutils/ar]
46 }
47
48 if ![info exists strip] then {
49 set strip [findfile $base_dir/../binutils/strip-new $base_dir/../binutils/strip-new [transform strip]]
50 }
51
52 if ![info exists size] then {
53 set size [findfile $base_dir/../binutils/size]
54 }
55
56 remote_exec host "mkdir -p tmpdir"
57
58 # Make symlinks from tmpdir/ld to the linker and assembler in the
59 # build tree, so that we can use a -B option to gcc to force it to use
60 # the newly built linker and assembler.
61 if {![file isdirectory tmpdir/ld]} then {
62 catch "exec mkdir tmpdir/ld" status
63 catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
64 catch "exec ln -s ld tmpdir/ld/collect-ld" status
65 catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
66 }
67 set gcc_B_opt "-B[pwd]/tmpdir/ld/"
68
69 # load the linker path
70 set ld_L_opt ""
71 if {[file exists tmpdir/libpath.exp]} {
72 load_lib tmpdir/libpath.exp
73
74 foreach dir $libpath {
75 append ld_L_opt " -L$dir"
76 }
77 }
78
79 # Many ELF testcases expect that "-z relro" is off.
80 set ld_elf_shared_opt "-z norelro"
81
82 # The "make check" target in the Makefile passes in
83 # "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
84 # (as when testing an installed linker), these flags may not be set.
85 if {![info exists CC]} {
86 set CC [find_gcc]
87 }
88 if {![info exists CFLAGS]} {
89 set CFLAGS "-g -O2"
90 }
91 if {![info exists CXX]} {
92 set CXX [find_g++]
93 }
94 if {![info exists CXXFLAGS]} {
95 set CXXFLAGS ""
96 }
97
98 # This allows us to run the linker testsuite with clang as the compilation
99 # driver instead of gcc. The syntax of the overrides are as follows, one
100 # per line:
101 #
102 # '#': Silence information about the changes to the command line arguments.
103 #
104 # '^': Add FOO as a new argument at the beginning of the command line.
105 #
106 # '+': Add FOO as a new argument at the end of the command line.
107 #
108 # 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
109 # line.
110 #
111 # 'xOPTION': Removes all instances of the literal argument OPTION.
112 #
113 # 'XOPTION': Removes all instances of the literal argument OPTION,
114 # and the following argument.
115 #
116 # 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
117 # at the end of the command line.
118 #
119 # \param OS - The stream to write edit information to.
120 # \param Args - The vector of command line arguments.
121 # \param Edit - The override command to perform.
122 # \param SavedStrings - Set to use for storing string representations.
123
124 global env
125 # Only set up the environment variable if the user has not already provided one.
126 if {! [info exists env(CCC_OVERRIDE_OPTIONS)]} {
127 set env(CCC_OVERRIDE_OPTIONS) "#\
128 +-Wno-unused-command-line-argument \
129 +-Wno-unknown-attributes \
130 +-Wno-tautological-compare \
131 +-Wno-ignored-optimization-argument \
132 +-Wno-deprecated \
133 +-fuse-ld=$ld \
134 x-Wa,--elf-stt-common=yes \
135 x-Wa,-mx86-used-note=no \
136 x-Wa,-mx86-used-note=yes \
137 x-Wa,-madd-bnd-prefix \
138 x-fno-early-inlining \
139 x-fno-toplevel-reorder \
140 x-flto-partition=none \
141 x-feliminate-dwarf2-dups \
142 s/-Wa,-mrelax-relocations=yes,-mx86-used-note=yes/-Wa,-mrelax-relocations=yes/ \
143 s/-Wa,--compress-debug-sections=zlib/-Wa,-compress-debug-sections=zlib/ \
144 s/-Wa,--compress-debug-sections=zlib-gabi/-Wa,-compress-debug-sections=zlib-gabi/ \
145 "
146 }
147
148 # The mips64-*-linux-gnu compiler defaults to the N32 ABI after
149 # installed, but to the O32 ABI in the build tree, because of some
150 # specs-file hacks. Make sure we use an ABI that is compatible with
151 # the one we expect.
152 if {[istarget mips64*-*-linux*] &&
153 (![board_info [target_info name] exists multilib_flags] ||
154 ![string match "*-mabi" [board_info [target_info name] multilib_flags]])
155 } {
156 append gcc_B_opt " -mabi=n32"
157 }
158
159 if { [istarget rx-*-*] } {
160 global ASFLAGS
161 set ASFLAGS "-muse-conventional-section-names"
162 }
163
164 # load the utility procedures
165 load_lib ld-lib.exp
166
167 proc get_target_emul {} {
168 global target_triplet
169 global srcdir
170 set status [catch "exec sh -c \"targ='$target_triplet' && . $srcdir/../configure.tgt && echo \\\$targ_emul\"" result]
171 if $status { error "Error getting emulation name: $result" }
172 return $result
173 }
174
175 if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" }
176
177 #
178 # ld_version -- extract and print the version number of ld compiler (GCC)
179 #
180 proc ld_version {} {
181 global ld
182 default_ld_version $ld
183 }
184
185 #
186 # ld_exit -- just a stub for ld
187 #
188 proc ld_exit {} {
189 }
190
191 #
192 # ld_start
193 # relink the linker
194 #
195 proc ld_start { ld target } {
196 #
197 }
198
199 #
200 # ld_relocate
201 # link an object using relocation
202 #
203 proc ld_relocate { ld target objects } {
204 default_ld_relocate $ld $target $objects
205 }
206
207 #
208 # ld_link
209 # link a program using ld
210 #
211 proc ld_link { ld target objects } {
212 default_ld_link $ld $target $objects
213 }
214
215 #
216 # ld_compile
217 # compile an object using $cc
218 #
219 proc ld_compile { cc source object } {
220 default_ld_compile $cc $source $object
221 }
222
223 #
224 # ld_assemble
225 # assemble a file
226 #
227 proc ld_assemble { as source object } {
228 default_ld_assemble $as "" $source $object
229 }
230
231 #
232 # ld_assemble_flags
233 # assemble a file with extra flags
234 #
235 proc ld_assemble_flags { as flags source object } {
236 default_ld_assemble $as $flags $source $object
237 }
238
239 #
240 # ld_nm
241 # run nm on a file
242 #
243 proc ld_nm { nm nmflags object } {
244 default_ld_nm $nm $nmflags $object
245 }
246
247 #
248 # ld_exec
249 # execute ithe target
250 #
251 proc ld_exec { target output } {
252 default_ld_exec $target $output
253 }
254
255 # From gas-defs.exp, to support run_dump_test.
256 if ![info exists AS] then {
257 set AS $as
258 }
259
260 if ![info exists ASFLAGS] then {
261 set ASFLAGS ""
262 }
263
264 if ![info exists OBJDUMP] then {
265 set OBJDUMP $objdump
266 }
267
268 if ![info exists OBJDUMPFLAGS] then {
269 set OBJDUMPFLAGS {}
270 }
271
272 if ![info exists NM] then {
273 set NM $nm
274 }
275
276 if ![info exists NMFLAGS] then {
277 set NMFLAGS {}
278 }
279
280 if ![info exists OBJCOPY] then {
281 set OBJCOPY $objcopy
282 }
283
284 if ![info exists OBJCOPYFLAGS] then {
285 set OBJCOPYFLAGS {}
286 }
287
288 if ![info exists READELF] then {
289 set READELF [findfile $base_dir/../binutils/readelf]
290 }
291
292 if ![info exists READELFFLAGS] then {
293 set READELFFLAGS {}
294 }
295
296 if ![info exists ELFEDIT] then {
297 set ELFEDIT [findfile $base_dir/../binutils/elfedit]
298 }
299
300 if ![info exists LD] then {
301 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
302 }
303
304 if ![info exists LDFLAGS] then {
305 set LDFLAGS {}
306 }
307
308 # Set LD_CLASS to "64bit" for a 64-bit *host* linker.
309 if { ![info exists LD_CLASS] } then {
310 set REAL_LD [findfile $base_dir/.libs/ld-new .libs/ld-new $LD [transform ld]]
311 set readelf_output [run_host_cmd "$READELF" "-h $REAL_LD"]
312 if { [regexp {[ \t]+Class:[ \t]+ELF64} $readelf_output] } then {
313 set LD_CLASS "64bit"
314 } else {
315 set LD_CLASS "32bit"
316 }
317 }
318
319 # Set PLT_CFLAGS to "-fplt" if target compiler supports it.
320
321 if { ![info exists PLT_CFLAGS] } then {
322 if { [check_compiler_available] } {
323 # Check if gcc supports -fplt
324 set flags ""
325 if [board_info [target_info name] exists cflags] {
326 append flags " [board_info [target_info name] cflags]"
327 }
328 if [board_info [target_info name] exists ldflags] {
329 append flags " [board_info [target_info name] ldflags]"
330 }
331
332 set basename "tmpdir/plt[pid]"
333 set src ${basename}.c
334 set output ${basename}.o
335 set f [open $src "w"]
336 puts $f ""
337 close $f
338 if [is_remote host] {
339 set src [remote_download host $src]
340 }
341 set plt_available [run_host_cmd_yesno "$CC" "$flags -c -fplt $src -o $output"]
342 remote_file host delete $src
343 remote_file host delete $output
344 file delete $src
345
346 if { $plt_available == 1 } then {
347 set PLT_CFLAGS "-fplt"
348 } else {
349 set PLT_CFLAGS ""
350 }
351 } else {
352 set PLT_CFLAGS ""
353 }
354 }
355
356 # Set NOPIE_CFLAGS to "-fno-PIE" and NOPIE_LDFLAGS to "-no-pie" if
357 # target compiler supports them.
358
359 if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
360 if { [check_compiler_available] } {
361 # Check if gcc supports -fno-PIE -no-pie.
362 set flags ""
363 if [board_info [target_info name] exists cflags] {
364 append flags " [board_info [target_info name] cflags]"
365 }
366 if [board_info [target_info name] exists ldflags] {
367 append flags " [board_info [target_info name] ldflags]"
368 }
369
370 set basename "tmpdir/nopie[pid]"
371 set src ${basename}.c
372 set output ${basename}
373 set f [open $src "w"]
374 puts $f "int main (void) { return 0; }"
375 close $f
376 if [is_remote host] {
377 set src [remote_download host $src]
378 }
379 set nopie_available [run_host_cmd_yesno "$CC" "$flags -fno-PIE -no-pie $src -o $output"]
380 remote_file host delete $src
381 remote_file host delete $output
382 file delete $src
383
384 if { $nopie_available == 1 } then {
385 set NOPIE_CFLAGS "-fno-PIE"
386 set NOPIE_LDFLAGS "-no-pie"
387 } else {
388 set NOPIE_CFLAGS ""
389 set NOPIE_LDFLAGS ""
390 }
391 } else {
392 set NOPIE_CFLAGS ""
393 set NOPIE_LDFLAGS ""
394 }
395 }
396
397 # Set NOCF_PROTECTION_CFLAGS to "-fcf-protection=none" if target compiler
398 # supports it.
399
400 if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
401 if { [check_compiler_available] } {
402 # Check if gcc supports -fcf-protection=none.
403 set flags ""
404 if [board_info [target_info name] exists cflags] {
405 append flags " [board_info [target_info name] cflags]"
406 }
407 if [board_info [target_info name] exists ldflags] {
408 append flags " [board_info [target_info name] ldflags]"
409 }
410
411 set basename "tmpdir/available[pid]"
412 set src ${basename}.c
413 set output ${basename}
414 set f [open $src "w"]
415 puts $f "int main (void) { return 0; }"
416 close $f
417 if [is_remote host] {
418 set src [remote_download host $src]
419 }
420 set available [run_host_cmd_yesno "$CC" "$flags -fcf-protection=none $src -o $output"]
421 remote_file host delete $src
422 remote_file host delete $output
423 file delete $src
424
425 if { $available == 1 } then {
426 set NOCF_PROTECTION_CFLAGS "-fcf-protection=none"
427 } else {
428 set NOCF_PROTECTION_CFLAGS ""
429 }
430 } else {
431 set NOCF_PROTECTION_CFLAGS ""
432 }
433 }
434
435 # Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
436
437 if { ![info exists GNU2_CFLAGS] } then {
438 if { [check_compiler_available] } {
439 # Check if gcc supports -mtls-dialect=gnu2
440 set flags ""
441 if [board_info [target_info name] exists cflags] {
442 append flags " [board_info [target_info name] cflags]"
443 }
444 if [board_info [target_info name] exists ldflags] {
445 append flags " [board_info [target_info name] ldflags]"
446 }
447
448 set basename "tmpdir/gnu2[pid]"
449 set src ${basename}.c
450 set output ${basename}.o
451 set f [open $src "w"]
452 puts $f "__thread int yyy = 100;"
453 close $f
454 if [is_remote host] {
455 set src [remote_download host $src]
456 }
457 set gnu2_available [run_host_cmd_yesno "$CC" "$flags -c -mtls-dialect=gnu2 $src -o $output"]
458 remote_file host delete $src
459 remote_file host delete $output
460 file delete $src
461
462 if { $gnu2_available == 1 } then {
463 set GNU2_CFLAGS "-mtls-dialect=gnu2"
464 } else {
465 set GNU2_CFLAGS ""
466 }
467 } else {
468 set GNU2_CFLAGS ""
469 }
470 }
471
472 # Set INT128_CFLAGS to "-DHAS_INT128" if target compiler supports __int128.
473
474 if { ![info exists INT128_CFLAGS] } then {
475 if { [check_compiler_available] } {
476 # Check if gcc supports __int128.
477 set flags ""
478 if [board_info [target_info name] exists cflags] {
479 append flags " [board_info [target_info name] cflags]"
480 }
481 if [board_info [target_info name] exists ldflags] {
482 append flags " [board_info [target_info name] ldflags]"
483 }
484
485 set basename "tmpdir/int128[pid]"
486 set src ${basename}.c
487 set output ${basename}.o
488 set f [open $src "w"]
489 puts $f "__int128 a = 42;"
490 close $f
491 if [is_remote host] {
492 set src [remote_download host $src]
493 }
494 set int128_available [run_host_cmd_yesno "$CC" "$flags -c $src -o $output"]
495 remote_file host delete $src
496 remote_file host delete $output
497 file delete $src
498
499 if { $int128_available == 1 } then {
500 set INT128_CFLAGS "-DHAS_INT128"
501 } else {
502 set INT128_CFLAGS ""
503 }
504 } else {
505 set INT128_CFLAGS ""
506 }
507 }
508
509 # Set STATIC_LDFLAGS to "-static" if target compiler supports it.
510
511 if { ![info exists STATIC_LDFLAGS] } then {
512 if { [check_compiler_available] } {
513 # Check if gcc supports -static.
514 set flags ""
515 if [board_info [target_info name] exists cflags] {
516 append flags " [board_info [target_info name] cflags]"
517 }
518 if [board_info [target_info name] exists ldflags] {
519 append flags " [board_info [target_info name] ldflags]"
520 }
521
522 set basename "tmpdir/static[pid]"
523 set src ${basename}.c
524 set output ${basename}
525 set f [open $src "w"]
526 puts $f "int main (void) { return 0; }"
527 close $f
528 if [is_remote host] {
529 set src [remote_download host $src]
530 }
531 set static_available [run_host_cmd_yesno "$CC" "-static $flags $src -o $output"]
532 remote_file host delete $src
533 remote_file host delete $output
534 file delete $src
535
536 if { $static_available == 1 } then {
537 set STATIC_LDFLAGS "-static"
538 } else {
539 set STATIC_LDFLAGS ""
540 }
541 } else {
542 set STATIC_LDFLAGS ""
543 }
544 }
545
546 # Set STATIC_PIE_LDFLAGS to "-static-pie" if target compiler supports it.
547
548 if { ![info exists STATIC_PIE_LDFLAGS] } then {
549 if { [check_compiler_available] } {
550 # Check if gcc supports -static-pie.
551 set flags ""
552 if [board_info [target_info name] exists cflags] {
553 append flags " [board_info [target_info name] cflags]"
554 }
555 if [board_info [target_info name] exists ldflags] {
556 append flags " [board_info [target_info name] ldflags]"
557 }
558
559 set basename "tmpdir/static[pid]"
560 set src ${basename}.c
561 set output ${basename}
562 set f [open $src "w"]
563 puts $f "int main (void) { return 0; }"
564 close $f
565 if [is_remote host] {
566 set src [remote_download host $src]
567 }
568 set static_available [run_host_cmd_yesno "$CC" "-static-pie $flags $src -o $output"]
569 remote_file host delete $src
570 remote_file host delete $output
571 file delete $src
572
573 if { $static_available == 1 } then {
574 set STATIC_PIE_LDFLAGS "-static-pie"
575 } else {
576 set STATIC_PIE_LDFLAGS ""
577 }
578 } else {
579 set STATIC_PIE_LDFLAGS ""
580 }
581 }
This page took 0.042503 seconds and 5 git commands to generate.