1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
|
# Basic expect script for LD Regression Tests
# Copyright (C) 1993-2020 Free Software Foundation, Inc.
#
# This file is part of the GNU Binutils.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# Written by Jeffrey Wheat (cassidy@cygnus.com)
#
if ![info exists ld] then {
set ld [findfile $base_dir/ld-new $base_dir/ld-new [transform ld]]
}
if ![info exists as] then {
set as [findfile $base_dir/../gas/as-new $base_dir/../gas/as-new [transform as]]
}
if ![info exists nm] then {
set nm [findfile $base_dir/../binutils/nm-new $base_dir/../binutils/nm-new [transform nm]]
}
if ![info exists objdump] then {
set objdump [findfile $base_dir/../binutils/objdump]
}
if ![info exists objcopy] then {
set objcopy [findfile $base_dir/../binutils/objcopy]
}
if ![info exists ar] then {
set ar [findfile $base_dir/../binutils/ar]
}
if ![info exists strip] then {
set strip [findfile $base_dir/../binutils/strip-new $base_dir/../binutils/strip-new [transform strip]]
}
if ![info exists size] then {
set size [findfile $base_dir/../binutils/size]
}
remote_exec host "mkdir -p tmpdir"
# Make symlinks from tmpdir/ld to the linker and assembler in the
# build tree, so that we can use a -B option to gcc to force it to use
# the newly built linker and assembler.
if {![file isdirectory tmpdir/ld]} then {
catch "exec mkdir tmpdir/ld" status
catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
catch "exec ln -s ld tmpdir/ld/collect-ld" status
catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
}
set gcc_B_opt "-B[pwd]/tmpdir/ld/"
# load the linker path
set ld_L_opt ""
if {[file exists tmpdir/libpath.exp]} {
load_lib tmpdir/libpath.exp
foreach dir $libpath {
append ld_L_opt " -L$dir"
}
}
# Many ELF testcases expect that "-z relro" is off.
set ld_elf_shared_opt "-z norelro"
# The "make check" target in the Makefile passes in
# "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
# (as when testing an installed linker), these flags may not be set.
if {![info exists CC]} {
set CC [find_gcc]
}
if {![info exists CFLAGS]} {
set CFLAGS "-g -O2"
}
if {![info exists CXX]} {
set CXX [find_g++]
}
if {![info exists CXXFLAGS]} {
set CXXFLAGS ""
}
# This allows us to run the linker testsuite with clang as the compilation
# driver instead of gcc. The syntax of the overrides are as follows, one
# per line:
#
# '#': Silence information about the changes to the command line arguments.
#
# '^': Add FOO as a new argument at the beginning of the command line.
#
# '+': Add FOO as a new argument at the end of the command line.
#
# 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
# line.
#
# 'xOPTION': Removes all instances of the literal argument OPTION.
#
# 'XOPTION': Removes all instances of the literal argument OPTION,
# and the following argument.
#
# 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
# at the end of the command line.
#
# \param OS - The stream to write edit information to.
# \param Args - The vector of command line arguments.
# \param Edit - The override command to perform.
# \param SavedStrings - Set to use for storing string representations.
global env
# Only set up the environment variable if the user has not already provided one.
if {! [info exists env(CCC_OVERRIDE_OPTIONS)]} {
set env(CCC_OVERRIDE_OPTIONS) "#\
+-Wno-unused-command-line-argument \
+-Wno-unknown-attributes \
+-Wno-tautological-compare \
+-Wno-ignored-optimization-argument \
+-Wno-deprecated \
+-fuse-ld=$ld \
x-Wa,--elf-stt-common=yes \
x-Wa,-mx86-used-note=no \
x-Wa,-mx86-used-note=yes \
x-Wa,-madd-bnd-prefix \
x-fno-early-inlining \
x-fno-toplevel-reorder \
x-flto-partition=none \
x-feliminate-dwarf2-dups \
s/-Wa,-mrelax-relocations=yes,-mx86-used-note=yes/-Wa,-mrelax-relocations=yes/ \
s/-Wa,--compress-debug-sections=zlib/-Wa,-compress-debug-sections=zlib/ \
s/-Wa,--compress-debug-sections=zlib-gabi/-Wa,-compress-debug-sections=zlib-gabi/ \
"
}
# The mips64-*-linux-gnu compiler defaults to the N32 ABI after
# installed, but to the O32 ABI in the build tree, because of some
# specs-file hacks. Make sure we use an ABI that is compatible with
# the one we expect.
if {[istarget mips64*-*-linux*] &&
(![board_info [target_info name] exists multilib_flags] ||
![string match "*-mabi" [board_info [target_info name] multilib_flags]])
} {
append gcc_B_opt " -mabi=n32"
}
if { [istarget rx-*-*] } {
global ASFLAGS
set ASFLAGS "-muse-conventional-section-names"
}
# load the utility procedures
load_lib ld-lib.exp
proc get_target_emul {} {
global target_triplet
global srcdir
set status [catch "exec sh -c \"targ='$target_triplet' && . $srcdir/../configure.tgt && echo \\\$targ_emul\"" result]
if $status { error "Error getting emulation name: $result" }
return $result
}
if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" }
#
# ld_version -- extract and print the version number of ld compiler (GCC)
#
proc ld_version {} {
global ld
default_ld_version $ld
}
#
# ld_exit -- just a stub for ld
#
proc ld_exit {} {
}
#
# ld_start
# relink the linker
#
proc ld_start { ld target } {
#
}
#
# ld_relocate
# link an object using relocation
#
proc ld_relocate { ld target objects } {
default_ld_relocate $ld $target $objects
}
#
# ld_link
# link a program using ld
#
proc ld_link { ld target objects } {
default_ld_link $ld $target $objects
}
#
# ld_compile
# compile an object using $cc
#
proc ld_compile { cc source object } {
default_ld_compile $cc $source $object
}
#
# ld_assemble
# assemble a file
#
proc ld_assemble { as source object } {
default_ld_assemble $as "" $source $object
}
#
# ld_assemble_flags
# assemble a file with extra flags
#
proc ld_assemble_flags { as flags source object } {
default_ld_assemble $as $flags $source $object
}
#
# ld_nm
# run nm on a file
#
proc ld_nm { nm nmflags object } {
default_ld_nm $nm $nmflags $object
}
#
# ld_exec
# execute ithe target
#
proc ld_exec { target output } {
default_ld_exec $target $output
}
# From gas-defs.exp, to support run_dump_test.
if ![info exists AS] then {
set AS $as
}
if ![info exists ASFLAGS] then {
set ASFLAGS ""
}
if ![info exists OBJDUMP] then {
set OBJDUMP $objdump
}
if ![info exists OBJDUMPFLAGS] then {
set OBJDUMPFLAGS {}
}
if ![info exists NM] then {
set NM $nm
}
if ![info exists NMFLAGS] then {
set NMFLAGS {}
}
if ![info exists OBJCOPY] then {
set OBJCOPY $objcopy
}
if ![info exists OBJCOPYFLAGS] then {
set OBJCOPYFLAGS {}
}
if ![info exists READELF] then {
set READELF [findfile $base_dir/../binutils/readelf]
}
if ![info exists READELFFLAGS] then {
set READELFFLAGS {}
}
if ![info exists ELFEDIT] then {
set ELFEDIT [findfile $base_dir/../binutils/elfedit]
}
if ![info exists LD] then {
set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
}
if ![info exists LDFLAGS] then {
set LDFLAGS {}
}
# Set LD_CLASS to "64bit" for a 64-bit *host* linker.
if { ![info exists LD_CLASS] } then {
set REAL_LD [findfile $base_dir/.libs/ld-new .libs/ld-new $LD [transform ld]]
set readelf_output [run_host_cmd "$READELF" "-h $REAL_LD"]
if { [regexp {[ \t]+Class:[ \t]+ELF64} $readelf_output] } then {
set LD_CLASS "64bit"
} else {
set LD_CLASS "32bit"
}
}
# Set PLT_CFLAGS to "-fplt" if target compiler supports it.
if { ![info exists PLT_CFLAGS] } then {
if { [check_compiler_available] } {
# Check if gcc supports -fplt
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set basename "tmpdir/plt[pid]"
set src ${basename}.c
set output ${basename}.o
set f [open $src "w"]
puts $f ""
close $f
if [is_remote host] {
set src [remote_download host $src]
}
set plt_available [run_host_cmd_yesno "$CC" "$flags -c -fplt $src -o $output"]
remote_file host delete $src
remote_file host delete $output
file delete $src
if { $plt_available == 1 } then {
set PLT_CFLAGS "-fplt"
} else {
set PLT_CFLAGS ""
}
} else {
set PLT_CFLAGS ""
}
}
# Set NOPIE_CFLAGS to "-fno-PIE" and NOPIE_LDFLAGS to "-no-pie" if
# target compiler supports them.
if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
if { [check_compiler_available] } {
# Check if gcc supports -fno-PIE -no-pie.
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set basename "tmpdir/nopie[pid]"
set src ${basename}.c
set output ${basename}
set f [open $src "w"]
puts $f "int main (void) { return 0; }"
close $f
if [is_remote host] {
set src [remote_download host $src]
}
set nopie_available [run_host_cmd_yesno "$CC" "$flags -fno-PIE -no-pie $src -o $output"]
remote_file host delete $src
remote_file host delete $output
file delete $src
if { $nopie_available == 1 } then {
set NOPIE_CFLAGS "-fno-PIE"
set NOPIE_LDFLAGS "-no-pie"
} else {
set NOPIE_CFLAGS ""
set NOPIE_LDFLAGS ""
}
} else {
set NOPIE_CFLAGS ""
set NOPIE_LDFLAGS ""
}
}
# Set NOCF_PROTECTION_CFLAGS to "-fcf-protection=none" if target compiler
# supports it.
if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
if { [check_compiler_available] } {
# Check if gcc supports -fcf-protection=none.
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set basename "tmpdir/available[pid]"
set src ${basename}.c
set output ${basename}
set f [open $src "w"]
puts $f "int main (void) { return 0; }"
close $f
if [is_remote host] {
set src [remote_download host $src]
}
set available [run_host_cmd_yesno "$CC" "$flags -fcf-protection=none $src -o $output"]
remote_file host delete $src
remote_file host delete $output
file delete $src
if { $available == 1 } then {
set NOCF_PROTECTION_CFLAGS "-fcf-protection=none"
} else {
set NOCF_PROTECTION_CFLAGS ""
}
} else {
set NOCF_PROTECTION_CFLAGS ""
}
}
# Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
if { ![info exists GNU2_CFLAGS] } then {
if { [check_compiler_available] } {
# Check if gcc supports -mtls-dialect=gnu2
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set basename "tmpdir/gnu2[pid]"
set src ${basename}.c
set output ${basename}.o
set f [open $src "w"]
puts $f "__thread int yyy = 100;"
close $f
if [is_remote host] {
set src [remote_download host $src]
}
set gnu2_available [run_host_cmd_yesno "$CC" "$flags -c -mtls-dialect=gnu2 $src -o $output"]
remote_file host delete $src
remote_file host delete $output
file delete $src
if { $gnu2_available == 1 } then {
set GNU2_CFLAGS "-mtls-dialect=gnu2"
} else {
set GNU2_CFLAGS ""
}
} else {
set GNU2_CFLAGS ""
}
}
# Set INT128_CFLAGS to "-DHAS_INT128" if target compiler supports __int128.
if { ![info exists INT128_CFLAGS] } then {
if { [check_compiler_available] } {
# Check if gcc supports __int128.
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set basename "tmpdir/int128[pid]"
set src ${basename}.c
set output ${basename}.o
set f [open $src "w"]
puts $f "__int128 a = 42;"
close $f
if [is_remote host] {
set src [remote_download host $src]
}
set int128_available [run_host_cmd_yesno "$CC" "$flags -c $src -o $output"]
remote_file host delete $src
remote_file host delete $output
file delete $src
if { $int128_available == 1 } then {
set INT128_CFLAGS "-DHAS_INT128"
} else {
set INT128_CFLAGS ""
}
} else {
set INT128_CFLAGS ""
}
}
# Set STATIC_LDFLAGS to "-static" if target compiler supports it.
if { ![info exists STATIC_LDFLAGS] } then {
if { [check_compiler_available] } {
# Check if gcc supports -static.
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set basename "tmpdir/static[pid]"
set src ${basename}.c
set output ${basename}
set f [open $src "w"]
puts $f "int main (void) { return 0; }"
close $f
if [is_remote host] {
set src [remote_download host $src]
}
set static_available [run_host_cmd_yesno "$CC" "-static $flags $src -o $output"]
remote_file host delete $src
remote_file host delete $output
file delete $src
if { $static_available == 1 } then {
set STATIC_LDFLAGS "-static"
} else {
set STATIC_LDFLAGS ""
}
} else {
set STATIC_LDFLAGS ""
}
}
# Set STATIC_PIE_LDFLAGS to "-static-pie" if target compiler supports it.
if { ![info exists STATIC_PIE_LDFLAGS] } then {
if { [check_compiler_available] } {
# Check if gcc supports -static-pie.
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set basename "tmpdir/static[pid]"
set src ${basename}.c
set output ${basename}
set f [open $src "w"]
puts $f "int main (void) { return 0; }"
close $f
if [is_remote host] {
set src [remote_download host $src]
}
set static_available [run_host_cmd_yesno "$CC" "-static-pie $flags $src -o $output"]
remote_file host delete $src
remote_file host delete $output
file delete $src
if { $static_available == 1 } then {
set STATIC_PIE_LDFLAGS "-static-pie"
} else {
set STATIC_PIE_LDFLAGS ""
}
} else {
set STATIC_PIE_LDFLAGS ""
}
}
# Set NOSANTIZE_CFLAGS to "-fno-sanitize=all" if target compiler
# supports it.
if { ![info exists NOSANTIZE_CFLAGS] } then {
if { [check_compiler_available] } {
# Check if gcc supports -fno-sanitize=all.
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set basename "tmpdir/available[pid]"
set src ${basename}.c
set output ${basename}
set f [open $src "w"]
puts $f "int main (void) { return 0; }"
close $f
if [is_remote host] {
set src [remote_download host $src]
}
set available [run_host_cmd_yesno "$CC" "$flags -fno-sanitize=all $src -o $output"]
remote_file host delete $src
remote_file host delete $output
file delete $src
if { $available == 1 } then {
set NOSANTIZE_CFLAGS "-fno-sanitize=all"
} else {
set NOSANTIZE_CFLAGS ""
}
} else {
set NOSANTIZE_CFLAGS ""
}
}
|