b2097ce7af25a02f29c3a791e3f263ba616982d3
[deliverable/binutils-gdb.git] / ld / testsuite / config / default.exp
1 # Basic expect script for LD Regression Tests
2 # Copyright (C) 1993-2020 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 # Many ELF testcases expect that "-z relro" is off.
80 set ld_elf_shared_opt "-z norelro"
81
82 # The "make check" target in the Makefile passes in
83 # "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
84 # (as when testing an installed linker), these flags may not be set.
85 if {![info exists CC]} {
86 set CC [find_gcc]
87 }
88 if {![info exists CFLAGS]} {
89 set CFLAGS "-g -O2"
90 }
91 if {![info exists CXX]} {
92 set CXX [find_g++]
93 }
94 if {![info exists CXXFLAGS]} {
95 set CXXFLAGS ""
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 # load the utility procedures
164 load_lib ld-lib.exp
165
166 proc 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
174 if ![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 #
179 proc ld_version {} {
180 global ld
181 default_ld_version $ld
182 }
183
184 #
185 # ld_exit -- just a stub for ld
186 #
187 proc ld_exit {} {
188 }
189
190 #
191 # ld_start
192 # relink the linker
193 #
194 proc ld_start { ld target } {
195 #
196 }
197
198 #
199 # ld_relocate
200 # link an object using relocation
201 #
202 proc 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 #
210 proc ld_link { ld target objects } {
211 default_ld_link $ld $target $objects
212 }
213
214 #
215 # ld_compile
216 # compile an object using $cc
217 #
218 proc ld_compile { cc source object } {
219 default_ld_compile $cc $source $object
220 }
221
222 #
223 # ld_assemble
224 # assemble a file
225 #
226 proc ld_assemble { as source object } {
227 default_ld_assemble $as "" $source $object
228 }
229
230 #
231 # ld_assemble_flags
232 # assemble a file with extra flags
233 #
234 proc ld_assemble_flags { as flags source object } {
235 default_ld_assemble $as $flags $source $object
236 }
237
238 #
239 # ld_nm
240 # run nm on a file
241 #
242 proc ld_nm { nm nmflags object } {
243 default_ld_nm $nm $nmflags $object
244 }
245
246 #
247 # ld_exec
248 # execute ithe target
249 #
250 proc ld_exec { target output } {
251 default_ld_exec $target $output
252 }
253
254 # From gas-defs.exp, to support run_dump_test.
255 if ![info exists AS] then {
256 set AS $as
257 }
258
259 if ![info exists ASFLAGS] then {
260 set ASFLAGS ""
261 }
262
263 if ![info exists OBJDUMP] then {
264 set OBJDUMP $objdump
265 }
266
267 if ![info exists OBJDUMPFLAGS] then {
268 set OBJDUMPFLAGS {}
269 }
270
271 if ![info exists NM] then {
272 set NM $nm
273 }
274
275 if ![info exists NMFLAGS] then {
276 set NMFLAGS {}
277 }
278
279 if ![info exists OBJCOPY] then {
280 set OBJCOPY $objcopy
281 }
282
283 if ![info exists OBJCOPYFLAGS] then {
284 set OBJCOPYFLAGS {}
285 }
286
287 if ![info exists READELF] then {
288 set READELF [findfile $base_dir/../binutils/readelf]
289 }
290
291 if ![info exists READELFFLAGS] then {
292 set READELFFLAGS {}
293 }
294
295 if ![info exists ELFEDIT] then {
296 set ELFEDIT [findfile $base_dir/../binutils/elfedit]
297 }
298
299 if ![info exists LD] then {
300 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
301 }
302
303 if ![info exists LDFLAGS] then {
304 set LDFLAGS {}
305 }
306
307 # Set LD_CLASS to "64bit" for a 64-bit *host* linker.
308 if { ![info exists LD_CLASS] } then {
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"]
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
318 # Set PLT_CFLAGS to "-fplt" if target compiler supports it.
319
320 if { ![info exists PLT_CFLAGS] } then {
321 if { [check_compiler_available] } {
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
337 if [is_remote host] {
338 set src [remote_download host $src]
339 }
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 }
354
355 # Set NOPIE_CFLAGS to "-fno-PIE" and NOPIE_LDFLAGS to "-no-pie" if
356 # target compiler supports them.
357
358 if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
359 if { [check_compiler_available] } {
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
375 if [is_remote host] {
376 set src [remote_download host $src]
377 }
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 }
395
396 # Set NOCF_PROTECTION_CFLAGS to "-fcf-protection=none" if target compiler
397 # supports it.
398
399 if { ![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
410 set basename "tmpdir/available[pid]"
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 }
419 set available [run_host_cmd_yesno "$CC" "$flags -fcf-protection=none $src -o $output"]
420 remote_file host delete $src
421 remote_file host delete $output
422 file delete $src
423
424 if { $available == 1 } then {
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
434 # Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
435
436 if { ![info exists GNU2_CFLAGS] } then {
437 if { [check_compiler_available] } {
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 }
470
471 # Set INT128_CFLAGS to "-DHAS_INT128" if target compiler supports __int128.
472
473 if { ![info exists INT128_CFLAGS] } then {
474 if { [check_compiler_available] } {
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 }
507
508 # Set STATIC_LDFLAGS to "-static" if target compiler supports it.
509
510 if { ![info exists STATIC_LDFLAGS] } then {
511 if { [check_compiler_available] } {
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 }
544
545 # Set STATIC_PIE_LDFLAGS to "-static-pie" if target compiler supports it.
546
547 if { ![info exists STATIC_PIE_LDFLAGS] } then {
548 if { [check_compiler_available] } {
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 }
581
582 # Set NOSANTIZE_CFLAGS to "-fno-sanitize=all" if target compiler
583 # supports it.
584
585 if { ![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.058579 seconds and 4 git commands to generate.