]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/config/default.exp
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / testsuite / config / default.exp
1 # Basic expect script for LD Regression Tests
2 # Copyright (C) 1993-2021 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 # 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]} {
83 set CC [find_gcc]
84 }
85 if {![info exists CFLAGS]} {
86 set CFLAGS "-g -O2"
87 }
88 if {![info exists CXX]} {
89 set CXX [find_g++]
90 }
91 if {![info exists CXXFLAGS]} {
92 set CXXFLAGS ""
93 }
94
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
97 # per line:
98 #
99 # '#': Silence information about the changes to the command line arguments.
100 #
101 # '^': Add FOO as a new argument at the beginning of the command line.
102 #
103 # '+': Add FOO as a new argument at the end of the command line.
104 #
105 # 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
106 # line.
107 #
108 # 'xOPTION': Removes all instances of the literal argument OPTION.
109 #
110 # 'XOPTION': Removes all instances of the literal argument OPTION,
111 # and the following argument.
112 #
113 # 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
114 # at the end of the command line.
115 #
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.
120
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 \
128 +-Wno-deprecated \
129 +-fuse-ld=$ld \
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/ \
141 "
142 }
143
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
147 # the one we expect.
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]])
151 } {
152 append gcc_B_opt " -mabi=n32"
153 }
154
155 if { [istarget rx-*-*] } {
156 global ASFLAGS
157 set ASFLAGS "-muse-conventional-section-names"
158 }
159
160 # load the utility procedures
161 load_lib ld-lib.exp
162
163 proc get_target_emul {} {
164 global target_triplet
165 global srcdir
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" }
168 return $result
169 }
170
171 if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" }
172
173 #
174 # ld_version -- extract and print the version number of ld compiler (GCC)
175 #
176 proc ld_version {} {
177 global ld
178 default_ld_version $ld
179 }
180
181 #
182 # ld_exit -- just a stub for ld
183 #
184 proc ld_exit {} {
185 }
186
187 #
188 # ld_start
189 # relink the linker
190 #
191 proc ld_start { ld target } {
192 #
193 }
194
195 #
196 # ld_relocate
197 # link an object using relocation
198 #
199 proc ld_relocate { ld target objects } {
200 default_ld_relocate $ld $target $objects
201 }
202
203 #
204 # ld_link
205 # link a program using ld
206 #
207 proc ld_link { ld target objects } {
208 default_ld_link $ld $target $objects
209 }
210
211 #
212 # ld_compile
213 # compile an object using $cc
214 #
215 proc ld_compile { cc source object } {
216 default_ld_compile $cc $source $object
217 }
218
219 #
220 # ld_assemble
221 # assemble a file
222 #
223 proc ld_assemble { as source object } {
224 default_ld_assemble $as "" $source $object
225 }
226
227 #
228 # ld_assemble_flags
229 # assemble a file with extra flags
230 #
231 proc ld_assemble_flags { as flags source object } {
232 default_ld_assemble $as $flags $source $object
233 }
234
235 #
236 # ld_nm
237 # run nm on a file
238 #
239 proc ld_nm { nm nmflags object } {
240 default_ld_nm $nm $nmflags $object
241 }
242
243 #
244 # ld_exec
245 # execute ithe target
246 #
247 proc ld_exec { target output } {
248 default_ld_exec $target $output
249 }
250
251 # From gas-defs.exp, to support run_dump_test.
252 if ![info exists AS] then {
253 set AS $as
254 }
255
256 if ![info exists ASFLAGS] then {
257 set ASFLAGS ""
258 }
259
260 if ![info exists OBJDUMP] then {
261 set OBJDUMP $objdump
262 }
263
264 if ![info exists OBJDUMPFLAGS] then {
265 set OBJDUMPFLAGS {}
266 }
267
268 if ![info exists NM] then {
269 set NM $nm
270 }
271
272 if ![info exists NMFLAGS] then {
273 set NMFLAGS {}
274 }
275
276 if ![info exists OBJCOPY] then {
277 set OBJCOPY $objcopy
278 }
279
280 if ![info exists OBJCOPYFLAGS] then {
281 set OBJCOPYFLAGS {}
282 }
283
284 if ![info exists READELF] then {
285 set READELF [findfile $base_dir/../binutils/readelf]
286 }
287
288 if ![info exists READELFFLAGS] then {
289 set READELFFLAGS {}
290 }
291
292 if ![info exists ELFEDIT] then {
293 set ELFEDIT [findfile $base_dir/../binutils/elfedit]
294 }
295
296 if ![info exists LD] then {
297 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
298 }
299
300 if ![info exists LDFLAGS] then {
301 set LDFLAGS {}
302 }
303
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 {
309 set LD_CLASS "64bit"
310 } else {
311 set LD_CLASS "32bit"
312 }
313 }
314
315 # Compiler tests
316 proc compiler_supports { flag args } {
317 if { [check_compiler_available] } {
318 global CC
319 set flags ""
320 if [board_info [target_info name] exists cflags] {
321 append flags " [board_info [target_info name] cflags]"
322 }
323 if [board_info [target_info name] exists ldflags] {
324 append flags " [board_info [target_info name] ldflags]"
325 }
326 set fn "cs[pid].c"
327 set f [open $fn "w"]
328 if { [llength $args] > 0 } {
329 puts $f [lindex $args 0]
330 } else {
331 puts $f "int main (void) { return 0; }"
332 }
333 close $f
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
337 file delete $fn
338 return $avail
339 }
340 return 0
341 }
342
343 if { ![info exists PLT_CFLAGS] } then {
344 set PLT_CFLAGS ""
345 if [compiler_supports "-c -fplt"] {
346 set PLT_CFLAGS "-fplt"
347 }
348 }
349
350 if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
351 set NOPIE_CFLAGS ""
352 set NOPIE_LDFLAGS ""
353 if [compiler_supports "-fno-PIE -no-pie"] {
354 set NOPIE_CFLAGS "-fno-PIE"
355 set NOPIE_LDFLAGS "-no-pie"
356 }
357 }
358
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"
363 }
364 }
365
366 if { ![info exists GNU2_CFLAGS] } then {
367 set GNU2_CFLAGS ""
368 if [compiler_supports "-c -mtls-dialect=gnu2" "__thread int y = 1;"] {
369 set GNU2_CFLAGS "-mtls-dialect=gnu2"
370 }
371 }
372
373 if { ![info exists INT128_CFLAGS] } then {
374 set INT128_CFLAGS ""
375 if [compiler_supports "-c" "__int128 a = 42;"] {
376 set INT128_CFLAGS "-DHAS_INT128"
377 }
378 }
379
380 if { ![info exists STATIC_LDFLAGS] } then {
381 set STATIC_LDFLAGS ""
382 if [compiler_supports "-static"] {
383 set STATIC_LDFLAGS "-static"
384 }
385 }
386
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"
391 }
392 }
393
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"
398 }
399 }
400
401 if { ![info exists NOLTO_CFLAGS] } then {
402 set NOLTO_CFLAGS ""
403 if [compiler_supports "-fno-lto"] {
404 set NOLTO_CFLAGS "-fno-lto"
405 }
406 }
407
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"]
412 close $f
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
421 }
422 append LDFLAGS " -Ltmpdir"
423 unset i missing_libs
424 }
425 unset f src
426 }
427
428 set plug_opt ""
429 if { [check_compiler_available] } {
430 set plugin_names {
431 liblto_plugin.so
432 liblto_plugin-0.dll
433 cyglto_plugin-0.dll
434 }
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"]
439 }
440 if { $plug_so ne $plug } then {
441 set plug_opt "--plugin $plug_so"
442 break
443 }
444 }
445 }
446
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"
451 } else {
452 set dep_plug_opt ""
453 }