ld: Add --export-dynamic-symbol and --export-dynamic-symbol-list
[deliverable/binutils-gdb.git] / ld / testsuite / config / default.exp
CommitLineData
252b5132 1# Basic expect script for LD Regression Tests
b3adc24a 2# Copyright (C) 1993-2020 Free Software Foundation, Inc.
252b5132 3#
f96b4a7b
NC
4# This file is part of the GNU Binutils.
5#
252b5132
RH
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
f96b4a7b 8# the Free Software Foundation; either version 3 of the License, or
252b5132
RH
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.
252b5132
RH
20#
21# Written by Jeffrey Wheat (cassidy@cygnus.com)
22#
23
24if ![info exists ld] then {
25 set ld [findfile $base_dir/ld-new $base_dir/ld-new [transform ld]]
26}
27
28if ![info exists as] then {
29 set as [findfile $base_dir/../gas/as-new $base_dir/../gas/as-new [transform as]]
30}
31
32if ![info exists nm] then {
33 set nm [findfile $base_dir/../binutils/nm-new $base_dir/../binutils/nm-new [transform nm]]
34}
35
36if ![info exists objdump] then {
37 set objdump [findfile $base_dir/../binutils/objdump]
38}
39
40if ![info exists objcopy] then {
41 set objcopy [findfile $base_dir/../binutils/objcopy]
42}
43
44if ![info exists ar] then {
45 set ar [findfile $base_dir/../binutils/ar]
46}
47
48if ![info exists strip] then {
49 set strip [findfile $base_dir/../binutils/strip-new $base_dir/../binutils/strip-new [transform strip]]
50}
51
7b19bec2
AM
52if ![info exists size] then {
53 set size [findfile $base_dir/../binutils/size]
54}
55
7f6a71ff 56remote_exec host "mkdir -p tmpdir"
252b5132 57
f1d7f4a6
AM
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.
b765d4e3
L
61if {![file isdirectory tmpdir/ld]} then {
62 catch "exec mkdir tmpdir/ld" status
63 catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
3499cebd 64 catch "exec ln -s ld tmpdir/ld/collect-ld" status
f1d7f4a6 65 catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
b765d4e3 66}
f1d7f4a6 67set gcc_B_opt "-B[pwd]/tmpdir/ld/"
b765d4e3 68
cdaeef2e 69# load the linker path
f1d7f4a6 70set ld_L_opt ""
99c05fe4
MM
71if {[file exists tmpdir/libpath.exp]} {
72 load_lib tmpdir/libpath.exp
cdaeef2e 73
99c05fe4 74 foreach dir $libpath {
f1d7f4a6 75 append ld_L_opt " -L$dir"
99c05fe4
MM
76 }
77}
78
647e4d46
L
79# Many ELF testcases expect that "-z relro" is off.
80set ld_elf_shared_opt "-z norelro"
81
99c05fe4
MM
82# The "make check" target in the Makefile passes in
83# "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
dae043d2 84# (as when testing an installed linker), these flags may not be set.
99c05fe4 85if {![info exists CC]} {
dae043d2
MM
86 set CC [find_gcc]
87}
88if {![info exists CFLAGS]} {
89 set CFLAGS "-g -O2"
90}
91if {![info exists CXX]} {
92 set CXX [find_g++]
93}
94if {![info exists CXXFLAGS]} {
95 set CXXFLAGS ""
cdaeef2e
L
96}
97
49c16254
NC
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
124global env
125# Only set up the environment variable if the user has not already provided one.
126if {! [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
697380b3
AO
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.
152if {[istarget mips64*-*-linux*] &&
153 (![board_info [target_info name] exists multilib_flags] ||
154 ![string match "*-mabi" [board_info [target_info name] multilib_flags]])
155 } {
f1d7f4a6 156 append gcc_B_opt " -mabi=n32"
697380b3
AO
157}
158
e5719043
NC
159if { [istarget rx-*-*] } {
160 global ASFLAGS
161 set ASFLAGS "-muse-conventional-section-names"
162}
163
252b5132
RH
164# load the utility procedures
165load_lib ld-lib.exp
166
252b5132
RH
167proc 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
252b5132
RH
175if ![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#
180proc ld_version {} {
181 global ld
182 default_ld_version $ld
183}
184
185#
186# ld_exit -- just a stub for ld
187#
188proc ld_exit {} {
189}
190
191#
192# ld_start
193# relink the linker
194#
195proc ld_start { ld target } {
196 #
197}
198
199#
200# ld_relocate
201# link an object using relocation
202#
203proc 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#
211proc ld_link { ld target objects } {
212 default_ld_link $ld $target $objects
213}
214
252b5132
RH
215#
216# ld_compile
217# compile an object using $cc
218#
219proc ld_compile { cc source object } {
220 default_ld_compile $cc $source $object
221}
222
223#
224# ld_assemble
225# assemble a file
226#
227proc ld_assemble { as source object } {
de1491f0
BS
228 default_ld_assemble $as "" $source $object
229}
230
231#
232# ld_assemble_flags
233# assemble a file with extra flags
234#
235proc ld_assemble_flags { as flags source object } {
236 default_ld_assemble $as $flags $source $object
252b5132
RH
237}
238
239#
240# ld_nm
241# run nm on a file
242#
992c450d
AM
243proc ld_nm { nm nmflags object } {
244 default_ld_nm $nm $nmflags $object
252b5132
RH
245}
246
247#
248# ld_exec
249# execute ithe target
250#
251proc ld_exec { target output } {
252 default_ld_exec $target $output
253}
254
261def70
HPN
255# From gas-defs.exp, to support run_dump_test.
256if ![info exists AS] then {
257 set AS $as
258}
259
261def70
HPN
260if ![info exists ASFLAGS] then {
261 set ASFLAGS ""
262}
263
264if ![info exists OBJDUMP] then {
265 set OBJDUMP $objdump
266}
267
268if ![info exists OBJDUMPFLAGS] then {
269 set OBJDUMPFLAGS {}
270}
271
272if ![info exists NM] then {
273 set NM $nm
274}
275
276if ![info exists NMFLAGS] then {
277 set NMFLAGS {}
278}
279
280if ![info exists OBJCOPY] then {
281 set OBJCOPY $objcopy
282}
283
284if ![info exists OBJCOPYFLAGS] then {
285 set OBJCOPYFLAGS {}
286}
287
288if ![info exists READELF] then {
289 set READELF [findfile $base_dir/../binutils/readelf]
290}
291
292if ![info exists READELFFLAGS] then {
293 set READELFFLAGS {}
294}
295
8a6b075b
L
296if ![info exists ELFEDIT] then {
297 set ELFEDIT [findfile $base_dir/../binutils/elfedit]
298}
299
261def70
HPN
300if ![info exists LD] then {
301 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
302}
303
304if ![info exists LDFLAGS] then {
305 set LDFLAGS {}
306}
e10461ae 307
b77db948 308# Set LD_CLASS to "64bit" for a 64-bit *host* linker.
978c0540 309if { ![info exists LD_CLASS] } then {
7ed1dab9
L
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"]
978c0540
L
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
e10461ae
L
319# Set PLT_CFLAGS to "-fplt" if target compiler supports it.
320
321if { ![info exists PLT_CFLAGS] } then {
44ed8092 322 if { [check_compiler_available] } {
e10461ae
L
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
010f98a5
L
338 if [is_remote host] {
339 set src [remote_download host $src]
340 }
e10461ae
L
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}
6f8ea6c4
L
355
356# Set NOPIE_CFLAGS to "-fno-PIE" and NOPIE_LDFLAGS to "-no-pie" if
357# target compiler supports them.
358
359if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
44ed8092 360 if { [check_compiler_available] } {
6f8ea6c4
L
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
010f98a5
L
376 if [is_remote host] {
377 set src [remote_download host $src]
378 }
6f8ea6c4
L
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}
1670f9c1 396
8be5def6
L
397# Set NOCF_PROTECTION_CFLAGS to "-fcf-protection=none" if target compiler
398# supports it.
399
400if { ![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
aa350065 411 set basename "tmpdir/available[pid]"
8be5def6
L
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 }
aa350065 420 set available [run_host_cmd_yesno "$CC" "$flags -fcf-protection=none $src -o $output"]
8be5def6
L
421 remote_file host delete $src
422 remote_file host delete $output
423 file delete $src
424
aa350065 425 if { $available == 1 } then {
8be5def6
L
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
1670f9c1
L
435# Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
436
437if { ![info exists GNU2_CFLAGS] } then {
44ed8092 438 if { [check_compiler_available] } {
1670f9c1
L
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}
fef75122
L
471
472# Set INT128_CFLAGS to "-DHAS_INT128" if target compiler supports __int128.
473
474if { ![info exists INT128_CFLAGS] } then {
44ed8092 475 if { [check_compiler_available] } {
fef75122
L
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}
98d72909
L
508
509# Set STATIC_LDFLAGS to "-static" if target compiler supports it.
510
511if { ![info exists STATIC_LDFLAGS] } then {
44ed8092 512 if { [check_compiler_available] } {
98d72909
L
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}
b3d7a867
L
545
546# Set STATIC_PIE_LDFLAGS to "-static-pie" if target compiler supports it.
547
548if { ![info exists STATIC_PIE_LDFLAGS] } then {
44ed8092 549 if { [check_compiler_available] } {
b3d7a867
L
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.96518 seconds and 4 git commands to generate.