1 # Basic expect script for LD Regression Tests
2 # Copyright (C) 1993-2020 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,
21 # Written by Jeffrey Wheat (cassidy@cygnus.com)
24 if ![info exists ld] then {
25 set ld [findfile $base_dir/ld-new $base_dir/ld-new [transform ld]]
28 if ![info exists as] then {
29 set as [findfile $base_dir/../gas/as-new $base_dir/../gas/as-new [transform as]]
32 if ![info exists nm] then {
33 set nm [findfile $base_dir/../binutils/nm-new $base_dir/../binutils/nm-new [transform nm]]
36 if ![info exists objdump] then {
37 set objdump [findfile $base_dir/../binutils/objdump]
40 if ![info exists objcopy] then {
41 set objcopy [findfile $base_dir/../binutils/objcopy]
44 if ![info exists ar] then {
45 set ar [findfile $base_dir/../binutils/ar]
48 if ![info exists strip] then {
49 set strip [findfile $base_dir/../binutils/strip-new $base_dir/../binutils/strip-new [transform strip]]
52 if ![info exists size] then {
53 set size [findfile $base_dir/../binutils/size]
56 remote_exec host "mkdir -p tmpdir"
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
67 set gcc_B_opt "-B[pwd]/tmpdir/ld/"
69 # load the linker path
71 if {[file exists tmpdir/libpath.exp]} {
72 load_lib tmpdir/libpath.exp
74 foreach dir $libpath {
75 append ld_L_opt " -L$dir"
79 # Many ELF testcases expect that "-z relro" is off.
80 set ld_elf_shared_opt "-z norelro"
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]} {
88 if {![info exists CFLAGS]} {
91 if {![info exists CXX]} {
94 if {![info exists CXXFLAGS]} {
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
102 # '#': Silence information about the changes to the command line arguments.
104 # '^': Add FOO as a new argument at the beginning of the command line.
106 # '+': Add FOO as a new argument at the end of the command line.
108 # 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
111 # 'xOPTION': Removes all instances of the literal argument OPTION.
113 # 'XOPTION': Removes all instances of the literal argument OPTION,
114 # and the following argument.
116 # 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
117 # at the end of the command line.
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.
124 # Only set up the environment variable if the user has not already provided one.
125 if {! [info exists env(CCC_OVERRIDE_OPTIONS)]} {
126 set env(CCC_OVERRIDE_OPTIONS) "#\
127 +-Wno-unused-command-line-argument \
128 +-Wno-unknown-attributes \
129 +-Wno-tautological-compare \
130 +-Wno-ignored-optimization-argument \
133 x-Wa,--elf-stt-common=yes \
134 x-Wa,-mx86-used-note=no \
135 x-Wa,-mx86-used-note=yes \
136 x-Wa,-madd-bnd-prefix \
137 x-fno-early-inlining \
138 x-fno-toplevel-reorder \
139 x-flto-partition=none \
140 x-feliminate-dwarf2-dups \
141 s/-Wa,-mrelax-relocations=yes,-mx86-used-note=yes/-Wa,-mrelax-relocations=yes/ \
142 s/-Wa,--compress-debug-sections=zlib/-Wa,-compress-debug-sections=zlib/ \
143 s/-Wa,--compress-debug-sections=zlib-gabi/-Wa,-compress-debug-sections=zlib-gabi/ \
147 # The mips64-*-linux-gnu compiler defaults to the N32 ABI after
148 # installed, but to the O32 ABI in the build tree, because of some
149 # specs-file hacks. Make sure we use an ABI that is compatible with
151 if {[istarget mips64*-*-linux*] &&
152 (![board_info [target_info name] exists multilib_flags] ||
153 ![string match "*-mabi" [board_info [target_info name] multilib_flags]])
155 append gcc_B_opt " -mabi=n32"
158 if { [istarget rx-*-*] } {
160 set ASFLAGS "-muse-conventional-section-names"
163 # load the utility procedures
166 proc get_target_emul {} {
167 global target_triplet
169 set status [catch "exec sh -c \"targ='$target_triplet' && . $srcdir/../configure.tgt && echo \\\$targ_emul\"" result]
170 if $status { error "Error getting emulation name: $result" }
174 if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" }
177 # ld_version -- extract and print the version number of ld compiler (GCC)
181 default_ld_version $ld
185 # ld_exit -- just a stub for ld
194 proc ld_start { ld target } {
200 # link an object using relocation
202 proc ld_relocate { ld target objects } {
203 default_ld_relocate $ld $target $objects
208 # link a program using ld
210 proc ld_link { ld target objects } {
211 default_ld_link $ld $target $objects
216 # compile an object using $cc
218 proc ld_compile { cc source object } {
219 default_ld_compile $cc $source $object
226 proc ld_assemble { as source object } {
227 default_ld_assemble $as "" $source $object
232 # assemble a file with extra flags
234 proc ld_assemble_flags { as flags source object } {
235 default_ld_assemble $as $flags $source $object
242 proc ld_nm { nm nmflags object } {
243 default_ld_nm $nm $nmflags $object
248 # execute ithe target
250 proc ld_exec { target output } {
251 default_ld_exec $target $output
254 # From gas-defs.exp, to support run_dump_test.
255 if ![info exists AS] then {
259 if ![info exists ASFLAGS] then {
263 if ![info exists OBJDUMP] then {
267 if ![info exists OBJDUMPFLAGS] then {
271 if ![info exists NM] then {
275 if ![info exists NMFLAGS] then {
279 if ![info exists OBJCOPY] then {
283 if ![info exists OBJCOPYFLAGS] then {
287 if ![info exists READELF] then {
288 set READELF [findfile $base_dir/../binutils/readelf]
291 if ![info exists READELFFLAGS] then {
295 if ![info exists ELFEDIT] then {
296 set ELFEDIT [findfile $base_dir/../binutils/elfedit]
299 if ![info exists LD] then {
300 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
303 if ![info exists LDFLAGS] then {
307 # Set LD_CLASS to "64bit" for a 64-bit *host* linker.
308 if { ![info exists LD_CLASS] } then {
309 set REAL_LD [findfile $base_dir/.libs/ld-new .libs/ld-new $LD [transform ld]]
310 set readelf_output [run_host_cmd "$READELF" "-h $REAL_LD"]
311 if { [regexp {[ \t]+Class:[ \t]+ELF64} $readelf_output] } then {
318 # Set PLT_CFLAGS to "-fplt" if target compiler supports it.
320 if { ![info exists PLT_CFLAGS] } then {
321 if { [check_compiler_available] } {
322 # Check if gcc supports -fplt
324 if [board_info [target_info name] exists cflags] {
325 append flags " [board_info [target_info name] cflags]"
327 if [board_info [target_info name] exists ldflags] {
328 append flags " [board_info [target_info name] ldflags]"
331 set basename "tmpdir/plt[pid]"
332 set src ${basename}.c
333 set output ${basename}.o
334 set f [open $src "w"]
337 if [is_remote host] {
338 set src [remote_download host $src]
340 set plt_available [run_host_cmd_yesno "$CC" "$flags -c -fplt $src -o $output"]
341 remote_file host delete $src
342 remote_file host delete $output
345 if { $plt_available == 1 } then {
346 set PLT_CFLAGS "-fplt"
355 # Set NOPIE_CFLAGS to "-fno-PIE" and NOPIE_LDFLAGS to "-no-pie" if
356 # target compiler supports them.
358 if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
359 if { [check_compiler_available] } {
360 # Check if gcc supports -fno-PIE -no-pie.
362 if [board_info [target_info name] exists cflags] {
363 append flags " [board_info [target_info name] cflags]"
365 if [board_info [target_info name] exists ldflags] {
366 append flags " [board_info [target_info name] ldflags]"
369 set basename "tmpdir/nopie[pid]"
370 set src ${basename}.c
371 set output ${basename}
372 set f [open $src "w"]
373 puts $f "int main (void) { return 0; }"
375 if [is_remote host] {
376 set src [remote_download host $src]
378 set nopie_available [run_host_cmd_yesno "$CC" "$flags -fno-PIE -no-pie $src -o $output"]
379 remote_file host delete $src
380 remote_file host delete $output
383 if { $nopie_available == 1 } then {
384 set NOPIE_CFLAGS "-fno-PIE"
385 set NOPIE_LDFLAGS "-no-pie"
396 # Set NOCF_PROTECTION_CFLAGS to "-fcf-protection=none" if target compiler
399 if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
400 if { [check_compiler_available] } {
401 # Check if gcc supports -fcf-protection=none.
403 if [board_info [target_info name] exists cflags] {
404 append flags " [board_info [target_info name] cflags]"
406 if [board_info [target_info name] exists ldflags] {
407 append flags " [board_info [target_info name] ldflags]"
410 set basename "tmpdir/available[pid]"
411 set src ${basename}.c
412 set output ${basename}
413 set f [open $src "w"]
414 puts $f "int main (void) { return 0; }"
416 if [is_remote host] {
417 set src [remote_download host $src]
419 set available [run_host_cmd_yesno "$CC" "$flags -fcf-protection=none $src -o $output"]
420 remote_file host delete $src
421 remote_file host delete $output
424 if { $available == 1 } then {
425 set NOCF_PROTECTION_CFLAGS "-fcf-protection=none"
427 set NOCF_PROTECTION_CFLAGS ""
430 set NOCF_PROTECTION_CFLAGS ""
434 # Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
436 if { ![info exists GNU2_CFLAGS] } then {
437 if { [check_compiler_available] } {
438 # Check if gcc supports -mtls-dialect=gnu2
440 if [board_info [target_info name] exists cflags] {
441 append flags " [board_info [target_info name] cflags]"
443 if [board_info [target_info name] exists ldflags] {
444 append flags " [board_info [target_info name] ldflags]"
447 set basename "tmpdir/gnu2[pid]"
448 set src ${basename}.c
449 set output ${basename}.o
450 set f [open $src "w"]
451 puts $f "__thread int yyy = 100;"
453 if [is_remote host] {
454 set src [remote_download host $src]
456 set gnu2_available [run_host_cmd_yesno "$CC" "$flags -c -mtls-dialect=gnu2 $src -o $output"]
457 remote_file host delete $src
458 remote_file host delete $output
461 if { $gnu2_available == 1 } then {
462 set GNU2_CFLAGS "-mtls-dialect=gnu2"
471 # Set INT128_CFLAGS to "-DHAS_INT128" if target compiler supports __int128.
473 if { ![info exists INT128_CFLAGS] } then {
474 if { [check_compiler_available] } {
475 # Check if gcc supports __int128.
477 if [board_info [target_info name] exists cflags] {
478 append flags " [board_info [target_info name] cflags]"
480 if [board_info [target_info name] exists ldflags] {
481 append flags " [board_info [target_info name] ldflags]"
484 set basename "tmpdir/int128[pid]"
485 set src ${basename}.c
486 set output ${basename}.o
487 set f [open $src "w"]
488 puts $f "__int128 a = 42;"
490 if [is_remote host] {
491 set src [remote_download host $src]
493 set int128_available [run_host_cmd_yesno "$CC" "$flags -c $src -o $output"]
494 remote_file host delete $src
495 remote_file host delete $output
498 if { $int128_available == 1 } then {
499 set INT128_CFLAGS "-DHAS_INT128"
508 # Set STATIC_LDFLAGS to "-static" if target compiler supports it.
510 if { ![info exists STATIC_LDFLAGS] } then {
511 if { [check_compiler_available] } {
512 # Check if gcc supports -static.
514 if [board_info [target_info name] exists cflags] {
515 append flags " [board_info [target_info name] cflags]"
517 if [board_info [target_info name] exists ldflags] {
518 append flags " [board_info [target_info name] ldflags]"
521 set basename "tmpdir/static[pid]"
522 set src ${basename}.c
523 set output ${basename}
524 set f [open $src "w"]
525 puts $f "int main (void) { return 0; }"
527 if [is_remote host] {
528 set src [remote_download host $src]
530 set static_available [run_host_cmd_yesno "$CC" "-static $flags $src -o $output"]
531 remote_file host delete $src
532 remote_file host delete $output
535 if { $static_available == 1 } then {
536 set STATIC_LDFLAGS "-static"
538 set STATIC_LDFLAGS ""
541 set STATIC_LDFLAGS ""
545 # Set STATIC_PIE_LDFLAGS to "-static-pie" if target compiler supports it.
547 if { ![info exists STATIC_PIE_LDFLAGS] } then {
548 if { [check_compiler_available] } {
549 # Check if gcc supports -static-pie.
551 if [board_info [target_info name] exists cflags] {
552 append flags " [board_info [target_info name] cflags]"
554 if [board_info [target_info name] exists ldflags] {
555 append flags " [board_info [target_info name] ldflags]"
558 set basename "tmpdir/static[pid]"
559 set src ${basename}.c
560 set output ${basename}
561 set f [open $src "w"]
562 puts $f "int main (void) { return 0; }"
564 if [is_remote host] {
565 set src [remote_download host $src]
567 set static_available [run_host_cmd_yesno "$CC" "-static-pie $flags $src -o $output"]
568 remote_file host delete $src
569 remote_file host delete $output
572 if { $static_available == 1 } then {
573 set STATIC_PIE_LDFLAGS "-static-pie"
575 set STATIC_PIE_LDFLAGS ""
578 set STATIC_PIE_LDFLAGS ""
582 # Set NOSANTIZE_CFLAGS to "-fno-sanitize=all" if target compiler
585 if { ![info exists NOSANTIZE_CFLAGS] } then {
586 if { [check_compiler_available] } {
587 # Check if gcc supports -fno-sanitize=all.
589 if [board_info [target_info name] exists cflags] {
590 append flags " [board_info [target_info name] cflags]"
592 if [board_info [target_info name] exists ldflags] {
593 append flags " [board_info [target_info name] ldflags]"
596 set basename "tmpdir/available[pid]"
597 set src ${basename}.c
598 set output ${basename}
599 set f [open $src "w"]
600 puts $f "int main (void) { return 0; }"
602 if [is_remote host] {
603 set src [remote_download host $src]
605 set available [run_host_cmd_yesno "$CC" "$flags -fno-sanitize=all $src -o $output"]
606 remote_file host delete $src
607 remote_file host delete $output
610 if { $available == 1 } then {
611 set NOSANTIZE_CFLAGS "-fno-sanitize=all"
613 set NOSANTIZE_CFLAGS ""
616 set NOSANTIZE_CFLAGS ""