tcl global directive outside proc body does nothing (ld)
[deliverable/binutils-gdb.git] / ld / testsuite / config / default.exp
CommitLineData
252b5132 1# Basic expect script for LD Regression Tests
b3adc24a 2# Copyright (C) 1993-2020 Free Software Foundation, Inc.
252b5132 3#
f96b4a7b
NC
4# This file is part of the GNU Binutils.
5#
252b5132
RH
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
f96b4a7b 8# the Free Software Foundation; either version 3 of the License, or
252b5132
RH
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
f96b4a7b
NC
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
252b5132
RH
20#
21# Written by Jeffrey Wheat (cassidy@cygnus.com)
22#
23
24if ![info exists ld] then {
25 set ld [findfile $base_dir/ld-new $base_dir/ld-new [transform ld]]
26}
27
28if ![info exists as] then {
29 set as [findfile $base_dir/../gas/as-new $base_dir/../gas/as-new [transform as]]
30}
31
32if ![info exists nm] then {
33 set nm [findfile $base_dir/../binutils/nm-new $base_dir/../binutils/nm-new [transform nm]]
34}
35
36if ![info exists objdump] then {
37 set objdump [findfile $base_dir/../binutils/objdump]
38}
39
40if ![info exists objcopy] then {
41 set objcopy [findfile $base_dir/../binutils/objcopy]
42}
43
44if ![info exists ar] then {
45 set ar [findfile $base_dir/../binutils/ar]
46}
47
48if ![info exists strip] then {
49 set strip [findfile $base_dir/../binutils/strip-new $base_dir/../binutils/strip-new [transform strip]]
50}
51
7b19bec2
AM
52if ![info exists size] then {
53 set size [findfile $base_dir/../binutils/size]
54}
55
7f6a71ff 56remote_exec host "mkdir -p tmpdir"
252b5132 57
f1d7f4a6
AM
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.
b765d4e3
L
61if {![file isdirectory tmpdir/ld]} then {
62 catch "exec mkdir tmpdir/ld" status
63 catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
3499cebd 64 catch "exec ln -s ld tmpdir/ld/collect-ld" status
f1d7f4a6 65 catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
b765d4e3 66}
f1d7f4a6 67set gcc_B_opt "-B[pwd]/tmpdir/ld/"
b765d4e3 68
cdaeef2e 69# load the linker path
f1d7f4a6 70set ld_L_opt ""
99c05fe4
MM
71if {[file exists tmpdir/libpath.exp]} {
72 load_lib tmpdir/libpath.exp
cdaeef2e 73
99c05fe4 74 foreach dir $libpath {
f1d7f4a6 75 append ld_L_opt " -L$dir"
99c05fe4
MM
76 }
77}
78
647e4d46
L
79# Many ELF testcases expect that "-z relro" is off.
80set ld_elf_shared_opt "-z norelro"
81
99c05fe4
MM
82# The "make check" target in the Makefile passes in
83# "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
dae043d2 84# (as when testing an installed linker), these flags may not be set.
99c05fe4 85if {![info exists CC]} {
dae043d2
MM
86 set CC [find_gcc]
87}
88if {![info exists CFLAGS]} {
89 set CFLAGS "-g -O2"
90}
91if {![info exists CXX]} {
92 set CXX [find_g++]
93}
94if {![info exists CXXFLAGS]} {
95 set CXXFLAGS ""
cdaeef2e
L
96}
97
49c16254
NC
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
49c16254
NC
124# Only set up the environment variable if the user has not already provided one.
125if {! [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
697380b3
AO
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.
151if {[istarget mips64*-*-linux*] &&
152 (![board_info [target_info name] exists multilib_flags] ||
153 ![string match "*-mabi" [board_info [target_info name] multilib_flags]])
154 } {
f1d7f4a6 155 append gcc_B_opt " -mabi=n32"
697380b3
AO
156}
157
e5719043
NC
158if { [istarget rx-*-*] } {
159 global ASFLAGS
160 set ASFLAGS "-muse-conventional-section-names"
161}
162
252b5132
RH
163# load the utility procedures
164load_lib ld-lib.exp
165
252b5132
RH
166proc get_target_emul {} {
167 global target_triplet
168 global srcdir
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" }
171 return $result
172}
173
252b5132
RH
174if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" }
175
176#
177# ld_version -- extract and print the version number of ld compiler (GCC)
178#
179proc ld_version {} {
180 global ld
181 default_ld_version $ld
182}
183
184#
185# ld_exit -- just a stub for ld
186#
187proc ld_exit {} {
188}
189
190#
191# ld_start
192# relink the linker
193#
194proc ld_start { ld target } {
195 #
196}
197
198#
199# ld_relocate
200# link an object using relocation
201#
202proc ld_relocate { ld target objects } {
203 default_ld_relocate $ld $target $objects
204}
205
206#
207# ld_link
208# link a program using ld
209#
210proc ld_link { ld target objects } {
211 default_ld_link $ld $target $objects
212}
213
252b5132
RH
214#
215# ld_compile
216# compile an object using $cc
217#
218proc ld_compile { cc source object } {
219 default_ld_compile $cc $source $object
220}
221
222#
223# ld_assemble
224# assemble a file
225#
226proc ld_assemble { as source object } {
de1491f0
BS
227 default_ld_assemble $as "" $source $object
228}
229
230#
231# ld_assemble_flags
232# assemble a file with extra flags
233#
234proc ld_assemble_flags { as flags source object } {
235 default_ld_assemble $as $flags $source $object
252b5132
RH
236}
237
238#
239# ld_nm
240# run nm on a file
241#
992c450d
AM
242proc ld_nm { nm nmflags object } {
243 default_ld_nm $nm $nmflags $object
252b5132
RH
244}
245
246#
247# ld_exec
248# execute ithe target
249#
250proc ld_exec { target output } {
251 default_ld_exec $target $output
252}
253
261def70
HPN
254# From gas-defs.exp, to support run_dump_test.
255if ![info exists AS] then {
256 set AS $as
257}
258
261def70
HPN
259if ![info exists ASFLAGS] then {
260 set ASFLAGS ""
261}
262
263if ![info exists OBJDUMP] then {
264 set OBJDUMP $objdump
265}
266
267if ![info exists OBJDUMPFLAGS] then {
268 set OBJDUMPFLAGS {}
269}
270
271if ![info exists NM] then {
272 set NM $nm
273}
274
275if ![info exists NMFLAGS] then {
276 set NMFLAGS {}
277}
278
279if ![info exists OBJCOPY] then {
280 set OBJCOPY $objcopy
281}
282
283if ![info exists OBJCOPYFLAGS] then {
284 set OBJCOPYFLAGS {}
285}
286
287if ![info exists READELF] then {
288 set READELF [findfile $base_dir/../binutils/readelf]
289}
290
291if ![info exists READELFFLAGS] then {
292 set READELFFLAGS {}
293}
294
8a6b075b
L
295if ![info exists ELFEDIT] then {
296 set ELFEDIT [findfile $base_dir/../binutils/elfedit]
297}
298
261def70
HPN
299if ![info exists LD] then {
300 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
301}
302
303if ![info exists LDFLAGS] then {
304 set LDFLAGS {}
305}
e10461ae 306
b77db948 307# Set LD_CLASS to "64bit" for a 64-bit *host* linker.
978c0540 308if { ![info exists LD_CLASS] } then {
7ed1dab9
L
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"]
978c0540
L
311 if { [regexp {[ \t]+Class:[ \t]+ELF64} $readelf_output] } then {
312 set LD_CLASS "64bit"
313 } else {
314 set LD_CLASS "32bit"
315 }
316}
317
e10461ae
L
318# Set PLT_CFLAGS to "-fplt" if target compiler supports it.
319
320if { ![info exists PLT_CFLAGS] } then {
44ed8092 321 if { [check_compiler_available] } {
e10461ae
L
322 # Check if gcc supports -fplt
323 set flags ""
324 if [board_info [target_info name] exists cflags] {
325 append flags " [board_info [target_info name] cflags]"
326 }
327 if [board_info [target_info name] exists ldflags] {
328 append flags " [board_info [target_info name] ldflags]"
329 }
330
331 set basename "tmpdir/plt[pid]"
332 set src ${basename}.c
333 set output ${basename}.o
334 set f [open $src "w"]
335 puts $f ""
336 close $f
010f98a5
L
337 if [is_remote host] {
338 set src [remote_download host $src]
339 }
e10461ae
L
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
343 file delete $src
344
345 if { $plt_available == 1 } then {
346 set PLT_CFLAGS "-fplt"
347 } else {
348 set PLT_CFLAGS ""
349 }
350 } else {
351 set PLT_CFLAGS ""
352 }
353}
6f8ea6c4
L
354
355# Set NOPIE_CFLAGS to "-fno-PIE" and NOPIE_LDFLAGS to "-no-pie" if
356# target compiler supports them.
357
358if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
44ed8092 359 if { [check_compiler_available] } {
6f8ea6c4
L
360 # Check if gcc supports -fno-PIE -no-pie.
361 set flags ""
362 if [board_info [target_info name] exists cflags] {
363 append flags " [board_info [target_info name] cflags]"
364 }
365 if [board_info [target_info name] exists ldflags] {
366 append flags " [board_info [target_info name] ldflags]"
367 }
368
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; }"
374 close $f
010f98a5
L
375 if [is_remote host] {
376 set src [remote_download host $src]
377 }
6f8ea6c4
L
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
381 file delete $src
382
383 if { $nopie_available == 1 } then {
384 set NOPIE_CFLAGS "-fno-PIE"
385 set NOPIE_LDFLAGS "-no-pie"
386 } else {
387 set NOPIE_CFLAGS ""
388 set NOPIE_LDFLAGS ""
389 }
390 } else {
391 set NOPIE_CFLAGS ""
392 set NOPIE_LDFLAGS ""
393 }
394}
1670f9c1 395
8be5def6
L
396# Set NOCF_PROTECTION_CFLAGS to "-fcf-protection=none" if target compiler
397# supports it.
398
399if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
400 if { [check_compiler_available] } {
401 # Check if gcc supports -fcf-protection=none.
402 set flags ""
403 if [board_info [target_info name] exists cflags] {
404 append flags " [board_info [target_info name] cflags]"
405 }
406 if [board_info [target_info name] exists ldflags] {
407 append flags " [board_info [target_info name] ldflags]"
408 }
409
aa350065 410 set basename "tmpdir/available[pid]"
8be5def6
L
411 set src ${basename}.c
412 set output ${basename}
413 set f [open $src "w"]
414 puts $f "int main (void) { return 0; }"
415 close $f
416 if [is_remote host] {
417 set src [remote_download host $src]
418 }
aa350065 419 set available [run_host_cmd_yesno "$CC" "$flags -fcf-protection=none $src -o $output"]
8be5def6
L
420 remote_file host delete $src
421 remote_file host delete $output
422 file delete $src
423
aa350065 424 if { $available == 1 } then {
8be5def6
L
425 set NOCF_PROTECTION_CFLAGS "-fcf-protection=none"
426 } else {
427 set NOCF_PROTECTION_CFLAGS ""
428 }
429 } else {
430 set NOCF_PROTECTION_CFLAGS ""
431 }
432}
433
1670f9c1
L
434# Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
435
436if { ![info exists GNU2_CFLAGS] } then {
44ed8092 437 if { [check_compiler_available] } {
1670f9c1
L
438 # Check if gcc supports -mtls-dialect=gnu2
439 set flags ""
440 if [board_info [target_info name] exists cflags] {
441 append flags " [board_info [target_info name] cflags]"
442 }
443 if [board_info [target_info name] exists ldflags] {
444 append flags " [board_info [target_info name] ldflags]"
445 }
446
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;"
452 close $f
453 if [is_remote host] {
454 set src [remote_download host $src]
455 }
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
459 file delete $src
460
461 if { $gnu2_available == 1 } then {
462 set GNU2_CFLAGS "-mtls-dialect=gnu2"
463 } else {
464 set GNU2_CFLAGS ""
465 }
466 } else {
467 set GNU2_CFLAGS ""
468 }
469}
fef75122
L
470
471# Set INT128_CFLAGS to "-DHAS_INT128" if target compiler supports __int128.
472
473if { ![info exists INT128_CFLAGS] } then {
44ed8092 474 if { [check_compiler_available] } {
fef75122
L
475 # Check if gcc supports __int128.
476 set flags ""
477 if [board_info [target_info name] exists cflags] {
478 append flags " [board_info [target_info name] cflags]"
479 }
480 if [board_info [target_info name] exists ldflags] {
481 append flags " [board_info [target_info name] ldflags]"
482 }
483
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;"
489 close $f
490 if [is_remote host] {
491 set src [remote_download host $src]
492 }
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
496 file delete $src
497
498 if { $int128_available == 1 } then {
499 set INT128_CFLAGS "-DHAS_INT128"
500 } else {
501 set INT128_CFLAGS ""
502 }
503 } else {
504 set INT128_CFLAGS ""
505 }
506}
98d72909
L
507
508# Set STATIC_LDFLAGS to "-static" if target compiler supports it.
509
510if { ![info exists STATIC_LDFLAGS] } then {
44ed8092 511 if { [check_compiler_available] } {
98d72909
L
512 # Check if gcc supports -static.
513 set flags ""
514 if [board_info [target_info name] exists cflags] {
515 append flags " [board_info [target_info name] cflags]"
516 }
517 if [board_info [target_info name] exists ldflags] {
518 append flags " [board_info [target_info name] ldflags]"
519 }
520
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; }"
526 close $f
527 if [is_remote host] {
528 set src [remote_download host $src]
529 }
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
533 file delete $src
534
535 if { $static_available == 1 } then {
536 set STATIC_LDFLAGS "-static"
537 } else {
538 set STATIC_LDFLAGS ""
539 }
540 } else {
541 set STATIC_LDFLAGS ""
542 }
543}
b3d7a867
L
544
545# Set STATIC_PIE_LDFLAGS to "-static-pie" if target compiler supports it.
546
547if { ![info exists STATIC_PIE_LDFLAGS] } then {
44ed8092 548 if { [check_compiler_available] } {
b3d7a867
L
549 # Check if gcc supports -static-pie.
550 set flags ""
551 if [board_info [target_info name] exists cflags] {
552 append flags " [board_info [target_info name] cflags]"
553 }
554 if [board_info [target_info name] exists ldflags] {
555 append flags " [board_info [target_info name] ldflags]"
556 }
557
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; }"
563 close $f
564 if [is_remote host] {
565 set src [remote_download host $src]
566 }
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
570 file delete $src
571
572 if { $static_available == 1 } then {
573 set STATIC_PIE_LDFLAGS "-static-pie"
574 } else {
575 set STATIC_PIE_LDFLAGS ""
576 }
577 } else {
578 set STATIC_PIE_LDFLAGS ""
579 }
580}
1949ad04
L
581
582# Set NOSANTIZE_CFLAGS to "-fno-sanitize=all" if target compiler
583# supports it.
584
585if { ![info exists NOSANTIZE_CFLAGS] } then {
586 if { [check_compiler_available] } {
587 # Check if gcc supports -fno-sanitize=all.
588 set flags ""
589 if [board_info [target_info name] exists cflags] {
590 append flags " [board_info [target_info name] cflags]"
591 }
592 if [board_info [target_info name] exists ldflags] {
593 append flags " [board_info [target_info name] ldflags]"
594 }
595
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; }"
601 close $f
602 if [is_remote host] {
603 set src [remote_download host $src]
604 }
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
608 file delete $src
609
610 if { $available == 1 } then {
611 set NOSANTIZE_CFLAGS "-fno-sanitize=all"
612 } else {
613 set NOSANTIZE_CFLAGS ""
614 }
615 } else {
616 set NOSANTIZE_CFLAGS ""
617 }
618}
This page took 0.9152 seconds and 4 git commands to generate.