1 # Basic expect script for LD Regression Tests
2 # Copyright (C) 1993-2021 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 # The "make check" target in the Makefile passes in
80 # "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
81 # (as when testing an installed linker), these flags may not be set.
82 if {![info exists CC]} {
85 if {![info exists CFLAGS]} {
88 if {![info exists CXX]} {
91 if {![info exists CXXFLAGS]} {
95 # This allows us to run the linker testsuite with clang as the compilation
96 # driver instead of gcc. The syntax of the overrides are as follows, one
99 # '#': Silence information about the changes to the command line arguments.
101 # '^': Add FOO as a new argument at the beginning of the command line.
103 # '+': Add FOO as a new argument at the end of the command line.
105 # 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
108 # 'xOPTION': Removes all instances of the literal argument OPTION.
110 # 'XOPTION': Removes all instances of the literal argument OPTION,
111 # and the following argument.
113 # 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
114 # at the end of the command line.
116 # \param OS - The stream to write edit information to.
117 # \param Args - The vector of command line arguments.
118 # \param Edit - The override command to perform.
119 # \param SavedStrings - Set to use for storing string representations.
121 # Only set up the environment variable if the user has not already provided one.
122 if {! [info exists env(CCC_OVERRIDE_OPTIONS)]} {
123 set env(CCC_OVERRIDE_OPTIONS) "#\
124 +-Wno-unused-command-line-argument \
125 +-Wno-unknown-attributes \
126 +-Wno-tautological-compare \
127 +-Wno-ignored-optimization-argument \
130 x-Wa,--elf-stt-common=yes \
131 x-Wa,-mx86-used-note=no \
132 x-Wa,-mx86-used-note=yes \
133 x-Wa,-madd-bnd-prefix \
134 x-fno-early-inlining \
135 x-fno-toplevel-reorder \
136 x-flto-partition=none \
137 x-feliminate-dwarf2-dups \
138 s/-Wa,-mrelax-relocations=yes,-mx86-used-note=yes/-Wa,-mrelax-relocations=yes/ \
139 s/-Wa,--compress-debug-sections=zlib/-Wa,-compress-debug-sections=zlib/ \
140 s/-Wa,--compress-debug-sections=zlib-gabi/-Wa,-compress-debug-sections=zlib-gabi/ \
144 # The mips64-*-linux-gnu compiler defaults to the N32 ABI after
145 # installed, but to the O32 ABI in the build tree, because of some
146 # specs-file hacks. Make sure we use an ABI that is compatible with
148 if {[istarget mips64*-*-linux*] &&
149 (![board_info [target_info name] exists multilib_flags] ||
150 ![string match "*-mabi" [board_info [target_info name] multilib_flags]])
152 append gcc_B_opt " -mabi=n32"
155 if { [istarget rx-*-*] } {
157 set ASFLAGS "-muse-conventional-section-names"
160 # load the utility procedures
163 proc get_target_emul {} {
164 global target_triplet
166 set status [catch "exec sh -c \"targ='$target_triplet' && . $srcdir/../configure.tgt && echo \\\$targ_emul\"" result]
167 if $status { error "Error getting emulation name: $result" }
171 if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" }
174 # ld_version -- extract and print the version number of ld compiler (GCC)
178 default_ld_version $ld
182 # ld_exit -- just a stub for ld
191 proc ld_start { ld target } {
197 # link an object using relocation
199 proc ld_relocate { ld target objects } {
200 default_ld_relocate $ld $target $objects
205 # link a program using ld
207 proc ld_link { ld target objects } {
208 default_ld_link $ld $target $objects
213 # compile an object using $cc
215 proc ld_compile { cc source object } {
216 default_ld_compile $cc $source $object
223 proc ld_assemble { as source object } {
224 default_ld_assemble $as "" $source $object
229 # assemble a file with extra flags
231 proc ld_assemble_flags { as flags source object } {
232 default_ld_assemble $as $flags $source $object
239 proc ld_nm { nm nmflags object } {
240 default_ld_nm $nm $nmflags $object
245 # execute ithe target
247 proc ld_exec { target output } {
248 default_ld_exec $target $output
251 # From gas-defs.exp, to support run_dump_test.
252 if ![info exists AS] then {
256 if ![info exists ASFLAGS] then {
260 if ![info exists OBJDUMP] then {
264 if ![info exists OBJDUMPFLAGS] then {
268 if ![info exists NM] then {
272 if ![info exists NMFLAGS] then {
276 if ![info exists OBJCOPY] then {
280 if ![info exists OBJCOPYFLAGS] then {
284 if ![info exists READELF] then {
285 set READELF [findfile $base_dir/../binutils/readelf]
288 if ![info exists READELFFLAGS] then {
292 if ![info exists ELFEDIT] then {
293 set ELFEDIT [findfile $base_dir/../binutils/elfedit]
296 if ![info exists LD] then {
297 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
300 if ![info exists LDFLAGS] then {
304 # Set LD_CLASS to "64bit" for a 64-bit *host* linker.
305 if { ![info exists LD_CLASS] } then {
306 set REAL_LD [findfile $base_dir/.libs/ld-new .libs/ld-new $LD [transform ld]]
307 set readelf_output [run_host_cmd "$READELF" "-h $REAL_LD"]
308 if { [regexp {[ \t]+Class:[ \t]+ELF64} $readelf_output] } then {
316 proc compiler_supports { flag args } {
317 if { [check_compiler_available] } {
320 if [board_info [target_info name] exists cflags] {
321 append flags " [board_info [target_info name] cflags]"
323 if [board_info [target_info name] exists ldflags] {
324 append flags " [board_info [target_info name] ldflags]"
328 if { [llength $args] > 0 } {
329 puts $f [lindex $args 0]
331 puts $f "int main (void) { return 0; }"
334 set rfn [remote_download host $fn]
335 set avail [run_host_cmd_yesno "$CC" "$flags $flag $rfn -o /dev/null"]
336 remote_file host delete $rfn
343 if { ![info exists PLT_CFLAGS] } then {
345 if [compiler_supports "-c -fplt"] {
346 set PLT_CFLAGS "-fplt"
350 if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
353 if [compiler_supports "-fno-PIE -no-pie"] {
354 set NOPIE_CFLAGS "-fno-PIE"
355 set NOPIE_LDFLAGS "-no-pie"
359 if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
360 set NOCF_PROTECTION_CFLAGS ""
361 if [compiler_supports "-fcf-protection=none"] {
362 set NOCF_PROTECTION_CFLAGS "-fcf-protection=none"
366 if { ![info exists GNU2_CFLAGS] } then {
368 if [compiler_supports "-c -mtls-dialect=gnu2" "__thread int y = 1;"] {
369 set GNU2_CFLAGS "-mtls-dialect=gnu2"
373 if { ![info exists INT128_CFLAGS] } then {
375 if [compiler_supports "-c" "__int128 a = 42;"] {
376 set INT128_CFLAGS "-DHAS_INT128"
380 if { ![info exists STATIC_LDFLAGS] } then {
381 set STATIC_LDFLAGS ""
382 if [compiler_supports "-static"] {
383 set STATIC_LDFLAGS "-static"
387 if { ![info exists STATIC_PIE_LDFLAGS] } then {
388 set STATIC_PIE_LDFLAGS ""
389 if [compiler_supports "-static-pie"] {
390 set STATIC_PIE_LDFLAGS "-static-pie"
394 if { ![info exists NOSANITIZE_CFLAGS] } then {
395 set NOSANITIZE_CFLAGS ""
396 if [compiler_supports "-fno-sanitize=all"] {
397 set NOSANITIZE_CFLAGS "-fno-sanitize=all"
401 if { ![info exists NOLTO_CFLAGS] } then {
403 if [compiler_supports "-fno-lto"] {
404 set NOLTO_CFLAGS "-fno-lto"
408 # Provide dummy libraries that alpha-vms-ld always loads
409 if { [istarget alpha*-*-*vms*] } {
410 set src tmpdir/empty.s
411 set f [open $src "w"]
413 if { [ld_assemble $as $src tmpdir/empty.o]
414 && ![ld_link $LD tmpdir/empty tmpdir/empty.o]
415 && [regsub -all {[^\n]*: cannot find -l([^\n]*)} $exec_output {tmpdir/lib\1.a } missing_libs] } {
416 regsub -all {\$} $missing_libs {\\\$} missing_libs
417 for { set i 0 } { $i < [llength $missing_libs] } { incr i } {
418 set f [lindex $missing_libs $i]
419 verbose -log "creating dummy $f"
420 ar_simple_create $ar {} $f tmpdir/empty.o
422 append LDFLAGS " -Ltmpdir"
429 if { [check_compiler_available] } {
435 foreach plug $plugin_names {
436 set plug_so [run_host_cmd $CC "--print-prog-name $plug"]
437 if { $plug_so eq $plug } then {
438 set plug_so [run_host_cmd $CC "--print-file-name $plug"]
440 if { $plug_so ne $plug } then {
441 set plug_opt "--plugin $plug_so"
447 if {[file exists .libs/libdep.so]} {
448 set dep_plug_opt "--plugin .libs/libdep.so"
449 } elseif {[file exists .libs/libdep.dll]} {
450 set dep_plug_opt "--plugin .libs/libdep.dll"