]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/testsuite/config/default.exp
Emit a warning when -z relro is unsupported
[thirdparty/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
79# The "make check" target in the Makefile passes in
80# "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
dae043d2 81# (as when testing an installed linker), these flags may not be set.
99c05fe4 82if {![info exists CC]} {
dae043d2
MM
83 set CC [find_gcc]
84}
85if {![info exists CFLAGS]} {
86 set CFLAGS "-g -O2"
87}
88if {![info exists CXX]} {
89 set CXX [find_g++]
90}
91if {![info exists CXXFLAGS]} {
92 set CXXFLAGS ""
cdaeef2e
L
93}
94
49c16254
NC
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
49c16254
NC
121# Only set up the environment variable if the user has not already provided one.
122if {! [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
697380b3
AO
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.
148if {[istarget mips64*-*-linux*] &&
149 (![board_info [target_info name] exists multilib_flags] ||
150 ![string match "*-mabi" [board_info [target_info name] multilib_flags]])
151 } {
f1d7f4a6 152 append gcc_B_opt " -mabi=n32"
697380b3
AO
153}
154
e5719043
NC
155if { [istarget rx-*-*] } {
156 global ASFLAGS
157 set ASFLAGS "-muse-conventional-section-names"
158}
159
252b5132
RH
160# load the utility procedures
161load_lib ld-lib.exp
162
252b5132
RH
163proc 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
252b5132
RH
171if ![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#
176proc ld_version {} {
177 global ld
178 default_ld_version $ld
179}
180
181#
182# ld_exit -- just a stub for ld
183#
184proc ld_exit {} {
185}
186
187#
188# ld_start
189# relink the linker
190#
191proc ld_start { ld target } {
192 #
193}
194
195#
196# ld_relocate
197# link an object using relocation
198#
199proc 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#
207proc ld_link { ld target objects } {
208 default_ld_link $ld $target $objects
209}
210
252b5132
RH
211#
212# ld_compile
213# compile an object using $cc
214#
215proc ld_compile { cc source object } {
216 default_ld_compile $cc $source $object
217}
218
219#
220# ld_assemble
221# assemble a file
222#
223proc ld_assemble { as source object } {
de1491f0
BS
224 default_ld_assemble $as "" $source $object
225}
226
227#
228# ld_assemble_flags
229# assemble a file with extra flags
230#
231proc ld_assemble_flags { as flags source object } {
232 default_ld_assemble $as $flags $source $object
252b5132
RH
233}
234
235#
236# ld_nm
237# run nm on a file
238#
992c450d
AM
239proc ld_nm { nm nmflags object } {
240 default_ld_nm $nm $nmflags $object
252b5132
RH
241}
242
243#
244# ld_exec
245# execute ithe target
246#
247proc ld_exec { target output } {
248 default_ld_exec $target $output
249}
250
261def70
HPN
251# From gas-defs.exp, to support run_dump_test.
252if ![info exists AS] then {
253 set AS $as
254}
255
261def70
HPN
256if ![info exists ASFLAGS] then {
257 set ASFLAGS ""
258}
259
260if ![info exists OBJDUMP] then {
261 set OBJDUMP $objdump
262}
263
264if ![info exists OBJDUMPFLAGS] then {
265 set OBJDUMPFLAGS {}
266}
267
268if ![info exists NM] then {
269 set NM $nm
270}
271
272if ![info exists NMFLAGS] then {
273 set NMFLAGS {}
274}
275
276if ![info exists OBJCOPY] then {
277 set OBJCOPY $objcopy
278}
279
280if ![info exists OBJCOPYFLAGS] then {
281 set OBJCOPYFLAGS {}
282}
283
284if ![info exists READELF] then {
285 set READELF [findfile $base_dir/../binutils/readelf]
286}
287
288if ![info exists READELFFLAGS] then {
289 set READELFFLAGS {}
290}
291
8a6b075b
L
292if ![info exists ELFEDIT] then {
293 set ELFEDIT [findfile $base_dir/../binutils/elfedit]
294}
295
261def70
HPN
296if ![info exists LD] then {
297 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
298}
299
300if ![info exists LDFLAGS] then {
301 set LDFLAGS {}
302}
e10461ae 303
b77db948 304# Set LD_CLASS to "64bit" for a 64-bit *host* linker.
978c0540 305if { ![info exists LD_CLASS] } then {
7ed1dab9
L
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"]
978c0540
L
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
e10461ae
L
315# Set PLT_CFLAGS to "-fplt" if target compiler supports it.
316
317if { ![info exists PLT_CFLAGS] } then {
44ed8092 318 if { [check_compiler_available] } {
e10461ae
L
319 # Check if gcc supports -fplt
320 set flags ""
321 if [board_info [target_info name] exists cflags] {
322 append flags " [board_info [target_info name] cflags]"
323 }
324 if [board_info [target_info name] exists ldflags] {
325 append flags " [board_info [target_info name] ldflags]"
326 }
327
328 set basename "tmpdir/plt[pid]"
329 set src ${basename}.c
330 set output ${basename}.o
331 set f [open $src "w"]
332 puts $f ""
333 close $f
010f98a5
L
334 if [is_remote host] {
335 set src [remote_download host $src]
336 }
e10461ae
L
337 set plt_available [run_host_cmd_yesno "$CC" "$flags -c -fplt $src -o $output"]
338 remote_file host delete $src
339 remote_file host delete $output
340 file delete $src
341
342 if { $plt_available == 1 } then {
343 set PLT_CFLAGS "-fplt"
344 } else {
345 set PLT_CFLAGS ""
346 }
347 } else {
348 set PLT_CFLAGS ""
349 }
350}
6f8ea6c4
L
351
352# Set NOPIE_CFLAGS to "-fno-PIE" and NOPIE_LDFLAGS to "-no-pie" if
353# target compiler supports them.
354
355if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
44ed8092 356 if { [check_compiler_available] } {
6f8ea6c4
L
357 # Check if gcc supports -fno-PIE -no-pie.
358 set flags ""
359 if [board_info [target_info name] exists cflags] {
360 append flags " [board_info [target_info name] cflags]"
361 }
362 if [board_info [target_info name] exists ldflags] {
363 append flags " [board_info [target_info name] ldflags]"
364 }
365
366 set basename "tmpdir/nopie[pid]"
367 set src ${basename}.c
368 set output ${basename}
369 set f [open $src "w"]
370 puts $f "int main (void) { return 0; }"
371 close $f
010f98a5
L
372 if [is_remote host] {
373 set src [remote_download host $src]
374 }
6f8ea6c4
L
375 set nopie_available [run_host_cmd_yesno "$CC" "$flags -fno-PIE -no-pie $src -o $output"]
376 remote_file host delete $src
377 remote_file host delete $output
378 file delete $src
379
380 if { $nopie_available == 1 } then {
381 set NOPIE_CFLAGS "-fno-PIE"
382 set NOPIE_LDFLAGS "-no-pie"
383 } else {
384 set NOPIE_CFLAGS ""
385 set NOPIE_LDFLAGS ""
386 }
387 } else {
388 set NOPIE_CFLAGS ""
389 set NOPIE_LDFLAGS ""
390 }
391}
1670f9c1 392
8be5def6
L
393# Set NOCF_PROTECTION_CFLAGS to "-fcf-protection=none" if target compiler
394# supports it.
395
396if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
397 if { [check_compiler_available] } {
398 # Check if gcc supports -fcf-protection=none.
399 set flags ""
400 if [board_info [target_info name] exists cflags] {
401 append flags " [board_info [target_info name] cflags]"
402 }
403 if [board_info [target_info name] exists ldflags] {
404 append flags " [board_info [target_info name] ldflags]"
405 }
406
aa350065 407 set basename "tmpdir/available[pid]"
8be5def6
L
408 set src ${basename}.c
409 set output ${basename}
410 set f [open $src "w"]
411 puts $f "int main (void) { return 0; }"
412 close $f
413 if [is_remote host] {
414 set src [remote_download host $src]
415 }
aa350065 416 set available [run_host_cmd_yesno "$CC" "$flags -fcf-protection=none $src -o $output"]
8be5def6
L
417 remote_file host delete $src
418 remote_file host delete $output
419 file delete $src
420
aa350065 421 if { $available == 1 } then {
8be5def6
L
422 set NOCF_PROTECTION_CFLAGS "-fcf-protection=none"
423 } else {
424 set NOCF_PROTECTION_CFLAGS ""
425 }
426 } else {
427 set NOCF_PROTECTION_CFLAGS ""
428 }
429}
430
1670f9c1
L
431# Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
432
433if { ![info exists GNU2_CFLAGS] } then {
44ed8092 434 if { [check_compiler_available] } {
1670f9c1
L
435 # Check if gcc supports -mtls-dialect=gnu2
436 set flags ""
437 if [board_info [target_info name] exists cflags] {
438 append flags " [board_info [target_info name] cflags]"
439 }
440 if [board_info [target_info name] exists ldflags] {
441 append flags " [board_info [target_info name] ldflags]"
442 }
443
444 set basename "tmpdir/gnu2[pid]"
445 set src ${basename}.c
446 set output ${basename}.o
447 set f [open $src "w"]
448 puts $f "__thread int yyy = 100;"
449 close $f
450 if [is_remote host] {
451 set src [remote_download host $src]
452 }
453 set gnu2_available [run_host_cmd_yesno "$CC" "$flags -c -mtls-dialect=gnu2 $src -o $output"]
454 remote_file host delete $src
455 remote_file host delete $output
456 file delete $src
457
458 if { $gnu2_available == 1 } then {
459 set GNU2_CFLAGS "-mtls-dialect=gnu2"
460 } else {
461 set GNU2_CFLAGS ""
462 }
463 } else {
464 set GNU2_CFLAGS ""
465 }
466}
fef75122
L
467
468# Set INT128_CFLAGS to "-DHAS_INT128" if target compiler supports __int128.
469
470if { ![info exists INT128_CFLAGS] } then {
44ed8092 471 if { [check_compiler_available] } {
fef75122
L
472 # Check if gcc supports __int128.
473 set flags ""
474 if [board_info [target_info name] exists cflags] {
475 append flags " [board_info [target_info name] cflags]"
476 }
477 if [board_info [target_info name] exists ldflags] {
478 append flags " [board_info [target_info name] ldflags]"
479 }
480
481 set basename "tmpdir/int128[pid]"
482 set src ${basename}.c
483 set output ${basename}.o
484 set f [open $src "w"]
485 puts $f "__int128 a = 42;"
486 close $f
487 if [is_remote host] {
488 set src [remote_download host $src]
489 }
490 set int128_available [run_host_cmd_yesno "$CC" "$flags -c $src -o $output"]
491 remote_file host delete $src
492 remote_file host delete $output
493 file delete $src
494
495 if { $int128_available == 1 } then {
496 set INT128_CFLAGS "-DHAS_INT128"
497 } else {
498 set INT128_CFLAGS ""
499 }
500 } else {
501 set INT128_CFLAGS ""
502 }
503}
98d72909
L
504
505# Set STATIC_LDFLAGS to "-static" if target compiler supports it.
506
507if { ![info exists STATIC_LDFLAGS] } then {
44ed8092 508 if { [check_compiler_available] } {
98d72909
L
509 # Check if gcc supports -static.
510 set flags ""
511 if [board_info [target_info name] exists cflags] {
512 append flags " [board_info [target_info name] cflags]"
513 }
514 if [board_info [target_info name] exists ldflags] {
515 append flags " [board_info [target_info name] ldflags]"
516 }
517
518 set basename "tmpdir/static[pid]"
519 set src ${basename}.c
520 set output ${basename}
521 set f [open $src "w"]
522 puts $f "int main (void) { return 0; }"
523 close $f
524 if [is_remote host] {
525 set src [remote_download host $src]
526 }
527 set static_available [run_host_cmd_yesno "$CC" "-static $flags $src -o $output"]
528 remote_file host delete $src
529 remote_file host delete $output
530 file delete $src
531
532 if { $static_available == 1 } then {
533 set STATIC_LDFLAGS "-static"
534 } else {
535 set STATIC_LDFLAGS ""
536 }
537 } else {
538 set STATIC_LDFLAGS ""
539 }
540}
b3d7a867
L
541
542# Set STATIC_PIE_LDFLAGS to "-static-pie" if target compiler supports it.
543
544if { ![info exists STATIC_PIE_LDFLAGS] } then {
44ed8092 545 if { [check_compiler_available] } {
b3d7a867
L
546 # Check if gcc supports -static-pie.
547 set flags ""
548 if [board_info [target_info name] exists cflags] {
549 append flags " [board_info [target_info name] cflags]"
550 }
551 if [board_info [target_info name] exists ldflags] {
552 append flags " [board_info [target_info name] ldflags]"
553 }
554
555 set basename "tmpdir/static[pid]"
556 set src ${basename}.c
557 set output ${basename}
558 set f [open $src "w"]
559 puts $f "int main (void) { return 0; }"
560 close $f
561 if [is_remote host] {
562 set src [remote_download host $src]
563 }
564 set static_available [run_host_cmd_yesno "$CC" "-static-pie $flags $src -o $output"]
565 remote_file host delete $src
566 remote_file host delete $output
567 file delete $src
568
569 if { $static_available == 1 } then {
570 set STATIC_PIE_LDFLAGS "-static-pie"
571 } else {
572 set STATIC_PIE_LDFLAGS ""
573 }
574 } else {
575 set STATIC_PIE_LDFLAGS ""
576 }
577}
1949ad04
L
578
579# Set NOSANTIZE_CFLAGS to "-fno-sanitize=all" if target compiler
580# supports it.
581
582if { ![info exists NOSANTIZE_CFLAGS] } then {
583 if { [check_compiler_available] } {
584 # Check if gcc supports -fno-sanitize=all.
585 set flags ""
586 if [board_info [target_info name] exists cflags] {
587 append flags " [board_info [target_info name] cflags]"
588 }
589 if [board_info [target_info name] exists ldflags] {
590 append flags " [board_info [target_info name] ldflags]"
591 }
592
593 set basename "tmpdir/available[pid]"
594 set src ${basename}.c
595 set output ${basename}
596 set f [open $src "w"]
597 puts $f "int main (void) { return 0; }"
598 close $f
599 if [is_remote host] {
600 set src [remote_download host $src]
601 }
602 set available [run_host_cmd_yesno "$CC" "$flags -fno-sanitize=all $src -o $output"]
603 remote_file host delete $src
604 remote_file host delete $output
605 file delete $src
606
607 if { $available == 1 } then {
608 set NOSANTIZE_CFLAGS "-fno-sanitize=all"
609 } else {
610 set NOSANTIZE_CFLAGS ""
611 }
612 } else {
613 set NOSANTIZE_CFLAGS ""
614 }
615}