PR28751 mbind2a / mbind2b regressions on powerpc*-linux
[binutils-gdb.git] / ld / testsuite / config / default.exp
1 # Basic expect script for LD Regression Tests
2 # Copyright (C) 1993-2022 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 if {![info exists CC]} {
80 set CC gcc
81 }
82 if {![info exists CFLAGS]} {
83 set CFLAGS "-g -O2"
84 }
85 if {![info exists CC_FOR_TARGET]} {
86 set CC_FOR_TARGET [find_gcc]
87 }
88 if {![info exists CFLAGS_FOR_TARGET]} {
89 set CFLAGS_FOR_TARGET "-g -O2"
90 }
91 if {![info exists CXX_FOR_TARGET]} {
92 set CXX_FOR_TARGET [find_g++]
93 }
94 if {![info exists CXXFLAGS_FOR_TARGET]} {
95 set CXXFLAGS_FOR_TARGET ""
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 # 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 \
131 +-Wno-deprecated \
132 +-fuse-ld=$ld \
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/ \
144 "
145 }
146
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
150 # the one we expect.
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]])
154 } {
155 append gcc_B_opt " -mabi=n32"
156 }
157
158 if { [istarget rx-*-*] } {
159 global ASFLAGS
160 set ASFLAGS "-muse-conventional-section-names"
161 }
162
163 # Blackfin ELF targets require selection of an explicit CPU. Use the sim.
164 if {[istarget bfin*-elf*]} {
165 append gcc_B_opt " -msim"
166 }
167
168 # load the utility procedures
169 load_lib ld-lib.exp
170
171 proc get_target_emul {} {
172 global target_triplet
173 global srcdir
174 set status [catch "exec sh -c \"targ='$target_triplet' && . $srcdir/../configure.tgt && echo \\\$targ_emul\"" result]
175 if $status { error "Error getting emulation name: $result" }
176 return $result
177 }
178
179 if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" }
180
181 #
182 # ld_version -- extract and print the version number of ld compiler (GCC)
183 #
184 proc ld_version {} {
185 global ld
186 default_ld_version $ld
187 }
188
189 #
190 # ld_exit -- just a stub for ld
191 #
192 proc ld_exit {} {
193 }
194
195 #
196 # ld_start
197 # relink the linker
198 #
199 proc ld_start { ld target } {
200 #
201 }
202
203 #
204 # ld_relocate
205 # link an object using relocation
206 #
207 proc ld_relocate { ld target objects } {
208 default_ld_relocate $ld $target $objects
209 }
210
211 #
212 # ld_link
213 # link a program using ld
214 #
215 proc ld_link { ld target objects } {
216 default_ld_link $ld $target $objects
217 }
218
219 #
220 # ld_compile
221 # compile an object using $cc
222 #
223 proc ld_compile { cc source object } {
224 default_ld_compile $cc $source $object
225 }
226
227 #
228 # ld_assemble
229 # assemble a file
230 #
231 proc ld_assemble { as source object } {
232 default_ld_assemble $as "" $source $object
233 }
234
235 #
236 # ld_assemble_flags
237 # assemble a file with extra flags
238 #
239 proc ld_assemble_flags { as flags source object } {
240 default_ld_assemble $as $flags $source $object
241 }
242
243 #
244 # ld_nm
245 # run nm on a file
246 #
247 proc ld_nm { nm nmflags object } {
248 default_ld_nm $nm $nmflags $object
249 }
250
251 #
252 # ld_exec
253 # execute ithe target
254 #
255 proc ld_exec { target output } {
256 default_ld_exec $target $output
257 }
258
259 # From gas-defs.exp, to support run_dump_test.
260 if ![info exists AS] then {
261 set AS $as
262 }
263
264 if ![info exists ASFLAGS] then {
265 set ASFLAGS ""
266 }
267
268 if ![info exists OBJDUMP] then {
269 set OBJDUMP $objdump
270 }
271
272 if ![info exists OBJDUMPFLAGS] then {
273 set OBJDUMPFLAGS {}
274 }
275
276 if ![info exists NM] then {
277 set NM $nm
278 }
279
280 if ![info exists NMFLAGS] then {
281 set NMFLAGS {}
282 }
283
284 if ![info exists OBJCOPY] then {
285 set OBJCOPY $objcopy
286 }
287
288 if ![info exists OBJCOPYFLAGS] then {
289 set OBJCOPYFLAGS {}
290 }
291
292 if ![info exists RANLIB] then {
293 set RANLIB [findfile $base_dir/../binutils/ranlib]
294 }
295
296 if ![info exists READELF] then {
297 set READELF [findfile $base_dir/../binutils/readelf]
298 }
299
300 if ![info exists READELFFLAGS] then {
301 set READELFFLAGS {}
302 }
303
304 if ![info exists ELFEDIT] then {
305 set ELFEDIT [findfile $base_dir/../binutils/elfedit]
306 }
307
308 if ![info exists LD] then {
309 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
310 }
311
312 if ![info exists LDFLAGS] then {
313 set LDFLAGS {}
314 }
315
316 if { ![info exists DT_RELR_LDFLAGS] } then {
317 if { [supports_dt_relr] } then {
318 set DT_RELR_LDFLAGS "-z pack-relative-relocs"
319 } else {
320 set DT_RELR_LDFLAGS {}
321 }
322 }
323
324 if { ![info exists DT_RELR_CC_LDFLAGS] } then {
325 if { [supports_dt_relr] } then {
326 set DT_RELR_CC_LDFLAGS "-Wl,-z,pack-relative-relocs"
327 } else {
328 set DT_RELR_CC_LDFLAGS {}
329 }
330 }
331
332 if { ![info exists NO_DT_RELR_LDFLAGS] } then {
333 if { [supports_dt_relr] } then {
334 set NO_DT_RELR_LDFLAGS "-z nopack-relative-relocs"
335 } else {
336 set NO_DT_RELR_LDFLAGS {}
337 }
338 }
339
340 if { ![info exists NO_DT_RELR_CC_LDFLAGS] } then {
341 if { [supports_dt_relr] } then {
342 set NO_DT_RELR_CC_LDFLAGS "-Wl,-z,nopack-relative-relocs"
343 } else {
344 set NO_DT_RELR_CC_LDFLAGS {}
345 }
346 }
347
348 # Set LD_CLASS to "64bit" for a 64-bit *host* linker.
349 if { ![info exists LD_CLASS] } then {
350 set REAL_LD [findfile $base_dir/.libs/ld-new .libs/ld-new $LD [transform ld]]
351 set readelf_output [run_host_cmd "$READELF" "-h $REAL_LD"]
352 if { [regexp {[ \t]+Class:[ \t]+ELF64} $readelf_output] } then {
353 set LD_CLASS "64bit"
354 } else {
355 set LD_CLASS "32bit"
356 }
357 }
358
359 # Compiler tests
360 proc compiler_supports { flag args } {
361 if { [check_compiler_available] } {
362 global CC_FOR_TARGET
363 set flags ""
364 if [board_info [target_info name] exists cflags] {
365 append flags " [board_info [target_info name] cflags]"
366 }
367 if [board_info [target_info name] exists ldflags] {
368 append flags " [board_info [target_info name] ldflags]"
369 }
370 set fn "cs[pid].c"
371 set f [open $fn "w"]
372 if { [llength $args] > 0 } {
373 puts $f [lindex $args 0]
374 } else {
375 puts $f "int main (void) { return 0; }"
376 }
377 close $f
378 set rfn [remote_download host $fn]
379 set avail [run_host_cmd_yesno "$CC_FOR_TARGET" "$flags $flag $rfn -o /dev/null"]
380 remote_file host delete $rfn
381 file delete $fn
382 return $avail
383 }
384 return 0
385 }
386
387 if { ![info exists PLT_CFLAGS] } then {
388 set PLT_CFLAGS ""
389 if [compiler_supports "-c -fplt"] {
390 set PLT_CFLAGS "-fplt"
391 }
392 }
393
394 if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
395 set NOPIE_CFLAGS ""
396 set NOPIE_LDFLAGS ""
397 if [compiler_supports "-fno-PIE -no-pie"] {
398 set NOPIE_CFLAGS "-fno-PIE"
399 set NOPIE_LDFLAGS "-no-pie"
400 }
401 }
402
403 if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
404 set NOCF_PROTECTION_CFLAGS ""
405 if [compiler_supports "-fcf-protection=none"] {
406 set NOCF_PROTECTION_CFLAGS "-fcf-protection=none"
407 }
408 }
409
410 if { ![info exists GNU2_CFLAGS] } then {
411 set GNU2_CFLAGS ""
412 if [compiler_supports "-c -mtls-dialect=gnu2" "__thread int y = 1;"] {
413 set GNU2_CFLAGS "-mtls-dialect=gnu2"
414 }
415 }
416
417 if { ![info exists INT128_CFLAGS] } then {
418 set INT128_CFLAGS ""
419 if [compiler_supports "-c" "__int128 a = 42;"] {
420 set INT128_CFLAGS "-DHAS_INT128"
421 }
422 }
423
424 if { ![info exists STATIC_LDFLAGS] } then {
425 set STATIC_LDFLAGS ""
426 if [compiler_supports "-static"] {
427 set STATIC_LDFLAGS "-static"
428 }
429 }
430
431 if { ![info exists STATIC_PIE_LDFLAGS] } then {
432 set STATIC_PIE_LDFLAGS ""
433 if [compiler_supports "-static-pie"] {
434 set STATIC_PIE_LDFLAGS "-static-pie"
435 }
436 }
437
438 if { ![info exists NOSANITIZE_CFLAGS] } then {
439 set NOSANITIZE_CFLAGS ""
440 if [compiler_supports "-fno-sanitize=all"] {
441 set NOSANITIZE_CFLAGS "-fno-sanitize=all"
442 }
443 }
444
445 if { ![info exists NOLTO_CFLAGS] } then {
446 set NOLTO_CFLAGS ""
447 if [compiler_supports "-fno-lto"] {
448 set NOLTO_CFLAGS "-fno-lto"
449 }
450 }
451
452 # Provide dummy libraries that alpha-vms-ld always loads
453 if { [istarget alpha*-*-*vms*] } {
454 set src tmpdir/empty.s
455 set f [open $src "w"]
456 close $f
457 if { [ld_assemble $as $src tmpdir/empty.o]
458 && ![ld_link $LD tmpdir/empty tmpdir/empty.o]
459 && [regsub -all {[^\n]*: cannot find -l([^\n]*)} $exec_output {tmpdir/lib\1.a } missing_libs] } {
460 regsub -all {\$} $missing_libs {\\\$} missing_libs
461 for { set i 0 } { $i < [llength $missing_libs] } { incr i } {
462 set f [lindex $missing_libs $i]
463 verbose -log "creating dummy $f"
464 ar_simple_create $ar {} $f tmpdir/empty.o
465 }
466 append LDFLAGS " -Ltmpdir"
467 unset i missing_libs
468 }
469 unset f src
470 }
471
472 set plug_opt ""
473 if { [check_compiler_available] } {
474 set plugin_names {
475 liblto_plugin.so
476 liblto_plugin-0.dll
477 cyglto_plugin-0.dll
478 }
479 foreach plug $plugin_names {
480 set plug_so [run_host_cmd $CC_FOR_TARGET "--print-prog-name $plug"]
481 if { $plug_so eq $plug } then {
482 set plug_so [run_host_cmd $CC_FOR_TARGET "--print-file-name $plug"]
483 }
484 if { $plug_so ne $plug } then {
485 set plug_opt "--plugin $plug_so"
486 break
487 }
488 }
489 }
490
491 if {[file exists .libs/libdep.so]} {
492 set dep_plug_opt "--plugin .libs/libdep.so"
493 } elseif {[file exists .libs/libdep.dll]} {
494 set dep_plug_opt "--plugin .libs/libdep.dll"
495 } else {
496 set dep_plug_opt ""
497 }