Automatic date update in version.in
[binutils-gdb.git] / ld / testsuite / config / default.exp
blob9ffcc58779f2e2d3feb5c367b943072302efaaa4
1 # Basic expect script for LD Regression Tests
2 # Copyright (C) 1993-2024 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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.
21 # Written by Jeffrey Wheat (cassidy@cygnus.com)
24 if [info exists env(LD_UNDER_TEST)] {
25 # LD_UNDER_TEST must be an absolute full path.
26 if {[file pathtype $env(LD_UNDER_TEST)] ne "absolute"} {
27 perror "**************************************************"
28 perror "Environment variable LD_UNDER_TEST ($env(LD_UNDER_TEST)) isn't an absolute full path."
29 perror "**************************************************"
30 exit 1
31 } elseif {![file exists $env(LD_UNDER_TEST)]} {
32 perror "**************************************************"
33 perror "Environment variable LD_UNDER_TEST ($env(LD_UNDER_TEST)) doesn't exist."
34 perror "**************************************************"
35 exit 1
37 set ld "$env(LD_UNDER_TEST)"
38 set LD "$ld"
41 if ![info exists ld] then {
42 set ld [findfile $base_dir/ld-new $base_dir/ld-new [transform ld]]
45 if ![info exists as] then {
46 set as [findfile $base_dir/../gas/as-new $base_dir/../gas/as-new [transform as]]
49 if ![info exists nm] then {
50 set nm [findfile $base_dir/../binutils/nm-new $base_dir/../binutils/nm-new [transform nm]]
53 if ![info exists objdump] then {
54 set objdump [findfile $base_dir/../binutils/objdump]
57 if ![info exists objcopy] then {
58 set objcopy [findfile $base_dir/../binutils/objcopy]
61 if ![info exists ar] then {
62 set ar [findfile $base_dir/../binutils/ar]
65 if ![info exists strip] then {
66 set strip [findfile $base_dir/../binutils/strip-new $base_dir/../binutils/strip-new [transform strip]]
69 if ![info exists size] then {
70 set size [findfile $base_dir/../binutils/size]
73 remote_exec host "mkdir -p tmpdir"
75 # Make symlinks from tmpdir/ld to the linker and assembler in the
76 # build tree, so that we can use a -B option to gcc to force it to use
77 # the newly built linker and assembler.
78 # The variable ld_testsuite_bindir allows to provide another directory
79 # for -B option. This can be useful when launching the testsuite outside
80 # the build tree as the symlinks will be wrong in this case.
81 if {[info exists ld_testsuite_bindir]} {
82 set gcc_B_opt "-B$ld_testsuite_bindir/"
83 } else {
84 # Delete tmpdir/ld first to remove tmpdir/ld/ld created by the
85 # previous LD_UNDER_TEST runs.
86 file delete -force tmpdir/ld
87 catch "exec mkdir tmpdir/ld" status
88 if [info exists env(LD_UNDER_TEST)] {
89 catch "exec ln -s $env(LD_UNDER_TEST) tmpdir/ld/ld" status
90 } else {
91 catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
93 catch "exec ln -s ld tmpdir/ld/collect-ld" status
94 catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
95 set gcc_B_opt "-B[pwd]/tmpdir/ld/"
98 # load the linker path
99 set ld_L_opt ""
100 if {[file exists tmpdir/libpath.exp]} {
101 load_lib tmpdir/libpath.exp
103 foreach dir $libpath {
104 append ld_L_opt " -L$dir"
108 if {![info exists CC]} {
109 set CC gcc
111 if {![info exists CFLAGS]} {
112 set CFLAGS "-g -O2"
114 if {![info exists CC_FOR_TARGET]} {
115 set CC_FOR_TARGET [find_gcc]
117 if {![info exists CFLAGS_FOR_TARGET]} {
118 set CFLAGS_FOR_TARGET "-g -O2"
120 if {![info exists CXX_FOR_TARGET]} {
121 set CXX_FOR_TARGET [find_g++]
123 if {![info exists CXXFLAGS_FOR_TARGET]} {
124 set CXXFLAGS_FOR_TARGET ""
127 # This allows us to run the linker testsuite with clang as the compilation
128 # driver instead of gcc. The syntax of the overrides are as follows, one
129 # per line:
131 # '#': Silence information about the changes to the command line arguments.
133 # '^': Add FOO as a new argument at the beginning of the command line.
135 # '+': Add FOO as a new argument at the end of the command line.
137 # 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
138 # line.
140 # 'xOPTION': Removes all instances of the literal argument OPTION.
142 # 'XOPTION': Removes all instances of the literal argument OPTION,
143 # and the following argument.
145 # 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
146 # at the end of the command line.
148 # \param OS - The stream to write edit information to.
149 # \param Args - The vector of command line arguments.
150 # \param Edit - The override command to perform.
151 # \param SavedStrings - Set to use for storing string representations.
153 # Only set up the environment variable if the user has not already provided one.
154 if {! [info exists env(CCC_OVERRIDE_OPTIONS)]} {
155 set env(CCC_OVERRIDE_OPTIONS) "#\
156 +-Wno-unused-command-line-argument \
157 +-Wno-unknown-attributes \
158 +-Wno-tautological-compare \
159 +-Wno-ignored-optimization-argument \
160 +-Wno-deprecated \
161 +-fuse-ld=$ld \
162 x-Wa,--elf-stt-common=yes \
163 x-Wa,-mx86-used-note=no \
164 x-Wa,-mx86-used-note=yes \
165 x-Wa,-madd-bnd-prefix \
166 x-fno-early-inlining \
167 x-fno-toplevel-reorder \
168 x-flto-partition=none \
169 x-feliminate-dwarf2-dups \
170 s/-Wa,-mrelax-relocations=yes,-mx86-used-note=yes/-Wa,-mrelax-relocations=yes/ \
171 s/-Wa,--compress-debug-sections=zlib/-Wa,-compress-debug-sections=zlib/ \
172 s/-Wa,--compress-debug-sections=zlib-gabi/-Wa,-compress-debug-sections=zlib-gabi/ \
176 # The mips64-*-linux-gnu compiler defaults to the N32 ABI after
177 # installed, but to the O32 ABI in the build tree, because of some
178 # specs-file hacks. Make sure we use an ABI that is compatible with
179 # the one we expect.
180 if {[istarget mips64*-*-linux*] &&
181 (![board_info [target_info name] exists multilib_flags] ||
182 ![string match "*-mabi" [board_info [target_info name] multilib_flags]])
184 append gcc_B_opt " -mabi=n32"
187 if { [istarget rx-*-*] } {
188 global ASFLAGS
189 set ASFLAGS "-muse-conventional-section-names"
192 # Blackfin ELF targets require selection of an explicit CPU. Use the sim.
193 if {[istarget bfin*-elf*]} {
194 append gcc_B_opt " -msim"
197 # load the utility procedures
198 load_lib ld-lib.exp
200 proc get_target_emul {} {
201 global target_triplet
202 global srcdir
203 set status [catch "exec sh -c \"targ='$target_triplet' && . $srcdir/../configure.tgt && echo \\\$targ_emul\"" result]
204 if $status { error "Error getting emulation name: $result" }
205 return $result
208 if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" }
211 # ld_version -- extract and print the version number of ld compiler (GCC)
213 proc ld_version {} {
214 global ld
215 default_ld_version $ld
219 # ld_exit -- just a stub for ld
221 proc ld_exit {} {
225 # ld_start
226 # relink the linker
228 proc ld_start { ld target } {
233 # ld_relocate
234 # link an object using relocation
236 proc ld_relocate { ld target objects } {
237 default_ld_relocate $ld $target $objects
241 # ld_link
242 # link a program using ld
244 proc ld_link { ld target objects } {
245 default_ld_link $ld $target $objects
249 # ld_compile
250 # compile an object using $cc
252 proc ld_compile { cc source object } {
253 default_ld_compile $cc $source $object
257 # ld_assemble
258 # assemble a file
260 proc ld_assemble { as source object } {
261 default_ld_assemble $as "" $source $object
265 # ld_assemble_flags
266 # assemble a file with extra flags
268 proc ld_assemble_flags { as flags source object } {
269 default_ld_assemble $as $flags $source $object
273 # ld_nm
274 # run nm on a file
276 proc ld_nm { nm nmflags object } {
277 default_ld_nm $nm $nmflags $object
281 # ld_exec
282 # execute ithe target
284 proc ld_exec { target output } {
285 default_ld_exec $target $output
288 # From gas-defs.exp, to support run_dump_test.
289 if ![info exists AS] then {
290 set AS $as
293 if ![info exists ASFLAGS] then {
294 set ASFLAGS ""
297 if ![info exists OBJDUMP] then {
298 set OBJDUMP $objdump
301 if ![info exists OBJDUMPFLAGS] then {
302 set OBJDUMPFLAGS {}
305 if ![info exists NM] then {
306 set NM $nm
309 if ![info exists NMFLAGS] then {
310 set NMFLAGS {}
313 if ![info exists OBJCOPY] then {
314 set OBJCOPY $objcopy
317 if ![info exists OBJCOPYFLAGS] then {
318 set OBJCOPYFLAGS {}
321 if ![info exists RANLIB] then {
322 set RANLIB [findfile $base_dir/../binutils/ranlib]
325 if ![info exists READELF] then {
326 set READELF [findfile $base_dir/../binutils/readelf]
329 if ![info exists READELFFLAGS] then {
330 set READELFFLAGS {}
333 if ![info exists SIZE] then {
334 set SIZE [findfile $base_dir/../binutils/size]
337 if ![info exists SIZEFLAGS] then {
338 set SIZEFLAGS ""
341 if ![info exists ELFEDIT] then {
342 set ELFEDIT [findfile $base_dir/../binutils/elfedit]
345 if ![info exists LD] then {
346 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
349 if ![info exists LDFLAGS] then {
350 set LDFLAGS {}
353 if { ![info exists DT_RELR_LDFLAGS] } then {
354 if { [supports_dt_relr] } then {
355 set DT_RELR_LDFLAGS "-z pack-relative-relocs"
356 } else {
357 set DT_RELR_LDFLAGS {}
361 if { ![info exists DT_RELR_CC_LDFLAGS] } then {
362 if { [supports_dt_relr] } then {
363 set DT_RELR_CC_LDFLAGS "-Wl,-z,pack-relative-relocs"
364 } else {
365 set DT_RELR_CC_LDFLAGS {}
369 if { ![info exists NO_DT_RELR_LDFLAGS] } then {
370 if { [supports_dt_relr] } then {
371 set NO_DT_RELR_LDFLAGS "-z nopack-relative-relocs"
372 } else {
373 set NO_DT_RELR_LDFLAGS {}
377 if { ![info exists NO_DT_RELR_CC_LDFLAGS] } then {
378 if { [supports_dt_relr] } then {
379 set NO_DT_RELR_CC_LDFLAGS "-Wl,-z,nopack-relative-relocs"
380 } else {
381 set NO_DT_RELR_CC_LDFLAGS {}
385 # Set LD_CLASS to "64bit" for a 64-bit *host* linker.
386 if { ![info exists LD_CLASS] } then {
387 set REAL_LD [findfile $base_dir/.libs/ld-new .libs/ld-new $LD [transform ld]]
388 set readelf_output [run_host_cmd "$READELF" "-h $REAL_LD"]
389 if { [regexp {[ \t]+Class:[ \t]+ELF64} $readelf_output] } then {
390 set LD_CLASS "64bit"
391 } else {
392 set LD_CLASS "32bit"
396 # Compiler tests
397 proc compiler_supports { flag args } {
398 if { [check_compiler_available] } {
399 global CC_FOR_TARGET
400 set flags ""
401 if [board_info [target_info name] exists cflags] {
402 append flags " [board_info [target_info name] cflags]"
404 if [board_info [target_info name] exists ldflags] {
405 append flags " [board_info [target_info name] ldflags]"
407 set fn "cs[pid].c"
408 set rfno "cs[pid].exe"
409 set f [open $fn "w"]
410 if { [llength $args] > 0 } {
411 puts $f [lindex $args 0]
412 } else {
413 puts $f "int main (void) { return 0; }"
415 close $f
416 set rfn [remote_download host $fn]
417 set avail [run_host_cmd_yesno "$CC_FOR_TARGET" "$flags $flag $rfn -o $rfno"]
418 remote_file host delete $rfno
419 remote_file host delete $rfn
420 file delete $fn
421 return $avail
423 return 0
426 if { ![info exists PLT_CFLAGS] } then {
427 set PLT_CFLAGS ""
428 if [compiler_supports "-c -fplt"] {
429 set PLT_CFLAGS "-fplt"
433 if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
434 set NOPIE_CFLAGS ""
435 set NOPIE_LDFLAGS ""
436 if [compiler_supports "-fno-PIE -no-pie"] {
437 set NOPIE_CFLAGS "-fno-PIE"
438 set NOPIE_LDFLAGS "-no-pie"
442 if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
443 set NOCF_PROTECTION_CFLAGS ""
444 if [compiler_supports "-fcf-protection=none"] {
445 set NOCF_PROTECTION_CFLAGS "-fcf-protection=none"
449 if { ![info exists GNU2_CFLAGS] } then {
450 set GNU2_CFLAGS ""
451 if [compiler_supports "-c -mtls-dialect=gnu2" "__thread int y = 1;"] {
452 set GNU2_CFLAGS "-mtls-dialect=gnu2"
456 if { ![info exists INT128_CFLAGS] } then {
457 set INT128_CFLAGS ""
458 if [compiler_supports "-c" "__int128 a = 42;"] {
459 set INT128_CFLAGS "-DHAS_INT128"
463 if { ![info exists STATIC_LDFLAGS] } then {
464 set STATIC_LDFLAGS ""
465 if [compiler_supports "-static"] {
466 set STATIC_LDFLAGS "-static"
470 if { ![info exists STATIC_PIE_LDFLAGS] } then {
471 set STATIC_PIE_LDFLAGS ""
472 if [compiler_supports "-static-pie"] {
473 set STATIC_PIE_LDFLAGS "-static-pie"
477 if { ![info exists NOSANITIZE_CFLAGS] } then {
478 set NOSANITIZE_CFLAGS ""
479 if [compiler_supports "-fno-sanitize=all"] {
480 set NOSANITIZE_CFLAGS "-fno-sanitize=all"
484 append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS"
485 append CXXFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS"
487 if { ![info exists NOLTO_CFLAGS] } then {
488 set NOLTO_CFLAGS ""
489 if [compiler_supports "-fno-lto"] {
490 set NOLTO_CFLAGS "-fno-lto"
494 # Provide dummy libraries that alpha-vms-ld always loads
495 if { [istarget alpha*-*-*vms*] } {
496 set src tmpdir/empty.s
497 set f [open $src "w"]
498 close $f
499 if { [ld_assemble $as $src tmpdir/empty.o]
500 && ![ld_link $LD tmpdir/empty tmpdir/empty.o]
501 && [regsub -all {[^\n]*: cannot find -l([^\n :]*)[^\n]*} $exec_output {tmpdir/lib\1.a } missing_libs] } {
502 regsub -all {\$} $missing_libs {\\\$} missing_libs
503 for { set i 0 } { $i < [llength $missing_libs] } { incr i } {
504 set f [lindex $missing_libs $i]
505 verbose -log "creating dummy $f"
506 ar_simple_create $ar {} $f tmpdir/empty.o
508 append LDFLAGS " -Ltmpdir"
509 unset i missing_libs
511 unset f src
514 set plug_opt ""
515 if { [check_compiler_available] } {
516 set plugin_names {
517 liblto_plugin.so
518 liblto_plugin-0.dll
519 cyglto_plugin-0.dll
521 foreach plug $plugin_names {
522 set plug_so [string trim [run_host_cmd $CC_FOR_TARGET "--print-prog-name $plug"]]
523 if { $plug_so eq $plug } then {
524 set plug_so [string trim [run_host_cmd $CC_FOR_TARGET "--print-file-name $plug"]]
526 if { $plug_so ne $plug } then {
527 set plug_opt "--plugin $plug_so"
528 break
533 if {[file exists .libs/libdep.so]} {
534 set dep_plug_opt "--plugin .libs/libdep.so"
535 } elseif {[file exists .libs/libdep.dll]} {
536 set dep_plug_opt "--plugin .libs/libdep.dll"
537 } else {
538 set dep_plug_opt ""