Commit | Line | Data |
---|---|---|
a2b64bed | 1 | # Support routines for LD testsuite. |
25629536 | 2 | # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
5a68afcf | 3 | # 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
8c5fc800 | 4 | # Free Software Foundation, Inc. |
a2b64bed | 5 | # |
f96b4a7b NC |
6 | # This file is part of the GNU Binutils. |
7 | # | |
a2b64bed NC |
8 | # This file is free software; you can redistribute it and/or modify |
9 | # it under the terms of the GNU General Public License as published by | |
f96b4a7b | 10 | # the Free Software Foundation; either version 3 of the License, or |
a2b64bed | 11 | # (at your option) any later version. |
3e8cba19 | 12 | # |
a2b64bed NC |
13 | # This program is distributed in the hope that it will be useful, |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
3e8cba19 | 17 | # |
a2b64bed NC |
18 | # You should have received a copy of the GNU General Public License |
19 | # along with this program; if not, write to the Free Software | |
f96b4a7b NC |
20 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
21 | # MA 02110-1301, USA. | |
3b6fe0cc | 22 | |
f3097f33 RS |
23 | proc load_common_lib { name } { |
24 | global srcdir | |
25 | load_file $srcdir/../../binutils/testsuite/lib/$name | |
26 | } | |
27 | ||
28 | load_common_lib binutils-common.exp | |
29 | ||
fb35d3d8 DD |
30 | # Returns 1 if the gcc for the target is at least version MAJOR.MINOR |
31 | # Returns 0 otherwise. | |
32 | # | |
33 | proc at_least_gcc_version { major minor } { | |
5a68afcf | 34 | |
fb35d3d8 DD |
35 | if {![info exists CC]} { |
36 | set CC [find_gcc] | |
37 | } | |
38 | if { $CC == "" } { | |
39 | return 0 | |
40 | } | |
41 | set state [remote_exec host $CC --version] | |
42 | set tmp "[lindex $state 1]\n" | |
43 | # Look for (eg) 4.6.1 in the version output. | |
8b5b2228 MR |
44 | set ver_re "\[^\\.0-9\]+(\[1-9\]\[0-9\]*)\\.(\[0-9\]+)(?:\\.\[0-9\]+)?" |
45 | regexp $ver_re $tmp fred maj min | |
fb35d3d8 | 46 | verbose "gcc version: $tmp" |
8b5b2228 MR |
47 | if { ![info exists maj] || ![info exists min] } then { |
48 | perror "can't decipher gcc version number, fix the framework!" | |
49 | return 0 | |
50 | } | |
fb35d3d8 DD |
51 | verbose "major gcc version is $maj, want at least $major" |
52 | if { $maj == $major } then { | |
53 | verbose "minor gcc version is $min, want at least $minor" | |
8b5b2228 | 54 | return [expr $min >= $minor] |
fb35d3d8 | 55 | } else { |
8b5b2228 | 56 | return [expr $maj > $major] |
fb35d3d8 DD |
57 | } |
58 | } | |
59 | ||
3b6fe0cc | 60 | # Extract and print the version number of ld. |
252b5132 RH |
61 | # |
62 | proc default_ld_version { ld } { | |
63 | global host_triplet | |
64 | ||
7f6a71ff | 65 | if { ![is_remote host] && [which $ld] == 0 } then { |
252b5132 RH |
66 | perror "$ld does not exist" |
67 | exit 1 | |
68 | } | |
3e8cba19 | 69 | |
7f6a71ff JM |
70 | remote_exec host "$ld --version" "" "/dev/null" "ld.version" |
71 | remote_upload host "ld.version" | |
72 | set tmp [prune_warnings [file_contents "ld.version"]] | |
73 | remote_file build delete "ld.version" | |
74 | remote_file host delete "ld.version" | |
75 | ||
252b5132 RH |
76 | regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" $tmp version cyg number |
77 | if [info exists number] then { | |
78 | clone_output "$ld $number\n" | |
79 | } | |
80 | } | |
81 | ||
7f6a71ff JM |
82 | proc run_host_cmd { prog command } { |
83 | global link_output | |
3e8cba19 | 84 | |
7f6a71ff JM |
85 | if { ![is_remote host] && [which "$prog"] == 0 } then { |
86 | perror "$prog does not exist" | |
252b5132 RH |
87 | return 0 |
88 | } | |
3e8cba19 | 89 | |
7f6a71ff JM |
90 | verbose -log "$prog $command" |
91 | set status [remote_exec host [concat sh -c [list "$prog $command 2>&1"]] "" "/dev/null" "ld.tmp"] | |
92 | remote_upload host "ld.tmp" | |
93 | set link_output [file_contents "ld.tmp"] | |
94 | regsub "\n$" $link_output "" link_output | |
95 | if { [lindex $status 0] != 0 && [string match "" $link_output] } then { | |
96 | append link_output "child process exited abnormally" | |
97 | } | |
98 | remote_file build delete ld.tmp | |
99 | remote_file host delete ld.tmp | |
fab4a87f | 100 | |
7f6a71ff JM |
101 | if [string match "" $link_output] then { |
102 | return "" | |
103 | } | |
3e8cba19 | 104 | |
7f6a71ff JM |
105 | verbose -log "$link_output" |
106 | return "$link_output" | |
107 | } | |
108 | ||
109 | proc run_host_cmd_yesno { prog command } { | |
110 | global exec_output | |
111 | ||
112 | set exec_output [prune_warnings [run_host_cmd "$prog" "$command"]] | |
252b5132 | 113 | if [string match "" $exec_output] then { |
7f6a71ff | 114 | return 1; |
252b5132 | 115 | } |
7f6a71ff JM |
116 | return 0; |
117 | } | |
118 | ||
119 | # Link an object using relocation. | |
120 | # | |
121 | proc default_ld_relocate { ld target objects } { | |
122 | global HOSTING_EMU | |
123 | ||
124 | remote_file host delete $target | |
125 | return [run_host_cmd_yesno "$ld" "$HOSTING_EMU -o $target -r $objects"] | |
252b5132 RH |
126 | } |
127 | ||
1688b748 | 128 | # Check to see if ld is being invoked with a non-endian output format |
3b6fe0cc | 129 | # |
1688b748 MH |
130 | proc is_endian_output_format { object_flags } { |
131 | ||
132 | if {[string match "*-oformat binary*" $object_flags] || \ | |
133 | [string match "*-oformat ieee*" $object_flags] || \ | |
134 | [string match "*-oformat ihex*" $object_flags] || \ | |
135 | [string match "*-oformat netbsd-core*" $object_flags] || \ | |
136 | [string match "*-oformat srec*" $object_flags] || \ | |
137 | [string match "*-oformat tekhex*" $object_flags] || \ | |
138 | [string match "*-oformat trad-core*" $object_flags] } then { | |
139 | return 0 | |
140 | } else { | |
141 | return 1 | |
142 | } | |
143 | } | |
144 | ||
38e31547 NC |
145 | # Look for big-endian or little-endian switches in the multlib |
146 | # options and translate these into a -EB or -EL switch. Note | |
147 | # we cannot rely upon proc process_multilib_options to do this | |
148 | # for us because for some targets the compiler does not support | |
149 | # -EB/-EL but it does support -mbig-endian/-mlittle-endian, and | |
150 | # the site.exp file will include the switch "-mbig-endian" | |
151 | # (rather than "big-endian") which is not detected by proc | |
152 | # process_multilib_options. | |
3b6fe0cc | 153 | # |
38e31547 | 154 | proc big_or_little_endian {} { |
3e8cba19 | 155 | |
38e31547 | 156 | if [board_info [target_info name] exists multilib_flags] { |
b24f926d | 157 | set tmp_flags " [board_info [target_info name] multilib_flags]" |
38e31547 NC |
158 | |
159 | foreach x $tmp_flags { | |
160 | case $x in { | |
906156c4 | 161 | {*big*endian eb EB -eb -EB -mb -meb} { |
38e31547 NC |
162 | set flags " -EB" |
163 | return $flags | |
164 | } | |
906156c4 | 165 | {*little*endian el EL -el -EL -ml -mel} { |
38e31547 NC |
166 | set flags " -EL" |
167 | return $flags | |
168 | } | |
169 | } | |
170 | } | |
171 | } | |
172 | ||
173 | set flags "" | |
174 | return $flags | |
175 | } | |
252b5132 | 176 | |
3b6fe0cc | 177 | # Link a program using ld. |
252b5132 RH |
178 | # |
179 | proc default_ld_link { ld target objects } { | |
180 | global HOSTING_EMU | |
181 | global HOSTING_CRT0 | |
182 | global HOSTING_LIBS | |
d1bcade6 | 183 | global LIBS |
252b5132 | 184 | global host_triplet |
6fc49d28 | 185 | global link_output |
fab4a87f | 186 | global exec_output |
3e8cba19 | 187 | |
252b5132 | 188 | set objs "$HOSTING_CRT0 $objects" |
d1bcade6 | 189 | set libs "$LIBS $HOSTING_LIBS" |
3e8cba19 | 190 | |
1688b748 MH |
191 | if [is_endian_output_format $objects] then { |
192 | set flags [big_or_little_endian] | |
193 | } else { | |
194 | set flags "" | |
195 | } | |
fab4a87f | 196 | |
7f6a71ff | 197 | remote_file host delete $target |
fab4a87f | 198 | |
7f6a71ff | 199 | return [run_host_cmd_yesno "$ld" "$HOSTING_EMU $flags -o $target $objs $libs"] |
252b5132 RH |
200 | } |
201 | ||
3b6fe0cc | 202 | # Link a program using ld, without including any libraries. |
252b5132 RH |
203 | # |
204 | proc default_ld_simple_link { ld target objects } { | |
205 | global host_triplet | |
b765d4e3 | 206 | global gcc_ld_flag |
fab4a87f | 207 | global exec_output |
7cda33a1 | 208 | |
1688b748 MH |
209 | if [is_endian_output_format $objects] then { |
210 | set flags [big_or_little_endian] | |
211 | } else { | |
212 | set flags "" | |
213 | } | |
3e8cba19 | 214 | |
b765d4e3 L |
215 | # If we are compiling with gcc, we want to add gcc_ld_flag to |
216 | # flags. Rather than determine this in some complex way, we guess | |
217 | # based on the name of the compiler. | |
b0fe1bf3 AM |
218 | set ldexe $ld |
219 | set ldparm [string first " " $ld] | |
cef3d14b | 220 | set ldflags "" |
b0fe1bf3 | 221 | if { $ldparm > 0 } then { |
cef3d14b | 222 | set ldflags [string range $ld $ldparm end] |
b0fe1bf3 | 223 | set ldexe [string range $ld 0 $ldparm] |
cef3d14b | 224 | set ld $ldexe |
b0fe1bf3 AM |
225 | } |
226 | set ldexe [string replace $ldexe 0 [string last "/" $ldexe] ""] | |
0f84fde1 | 227 | if {[string match "*gcc*" $ldexe] || [string match "*++*" $ldexe]} then { |
cef3d14b | 228 | set ldflags "$gcc_ld_flag $ldflags" |
b765d4e3 L |
229 | } |
230 | ||
7f6a71ff | 231 | remote_file host delete $target |
fab4a87f | 232 | |
cef3d14b | 233 | set exec_output [run_host_cmd "$ld" "$ldflags $flags -o $target $objects"] |
7f6a71ff | 234 | set exec_output [prune_warnings $exec_output] |
252b5132 RH |
235 | |
236 | # We don't care if we get a warning about a non-existent start | |
237 | # symbol, since the default linker script might use ENTRY. | |
238 | regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
239 | ||
240 | if [string match "" $exec_output] then { | |
241 | return 1 | |
242 | } else { | |
252b5132 RH |
243 | return 0 |
244 | } | |
245 | } | |
246 | ||
3b6fe0cc | 247 | # Compile an object using cc. |
252b5132 RH |
248 | # |
249 | proc default_ld_compile { cc source object } { | |
250 | global CFLAGS | |
58ffc3bd | 251 | global CXXFLAGS |
252b5132 RH |
252 | global srcdir |
253 | global subdir | |
254 | global host_triplet | |
255 | global gcc_gas_flag | |
256 | ||
257 | set cc_prog $cc | |
258 | if {[llength $cc_prog] > 1} then { | |
259 | set cc_prog [lindex $cc_prog 0] | |
260 | } | |
7f6a71ff | 261 | if {![is_remote host] && [which $cc_prog] == 0} then { |
252b5132 RH |
262 | perror "$cc_prog does not exist" |
263 | return 0 | |
264 | } | |
265 | ||
7f6a71ff JM |
266 | remote_file build delete "$object" |
267 | remote_file host delete "$object" | |
252b5132 | 268 | |
58ffc3bd | 269 | set flags "-I$srcdir/$subdir" |
252b5132 RH |
270 | |
271 | # If we are compiling with gcc, we want to add gcc_gas_flag to | |
272 | # flags. Rather than determine this in some complex way, we guess | |
273 | # based on the name of the compiler. | |
b0fe1bf3 AM |
274 | set ccexe $cc |
275 | set ccparm [string first " " $cc] | |
dec20c9e | 276 | set ccflags "" |
b0fe1bf3 | 277 | if { $ccparm > 0 } then { |
dec20c9e | 278 | set ccflags [string range $cc $ccparm end] |
b0fe1bf3 | 279 | set ccexe [string range $cc 0 $ccparm] |
dec20c9e | 280 | set cc $ccexe |
b0fe1bf3 AM |
281 | } |
282 | set ccexe [string replace $ccexe 0 [string last "/" $ccexe] ""] | |
0f84fde1 | 283 | if {[string match "*gcc*" $ccexe] || [string match "*++*" $ccexe]} then { |
252b5132 RH |
284 | set flags "$gcc_gas_flag $flags" |
285 | } | |
286 | ||
58ffc3bd MF |
287 | if {[string match "*++*" $ccexe]} { |
288 | set flags "$flags $CXXFLAGS" | |
289 | } else { | |
290 | set flags "$flags $CFLAGS" | |
291 | } | |
292 | ||
38e31547 | 293 | if [board_info [target_info name] exists multilib_flags] { |
b24f926d | 294 | append flags " [board_info [target_info name] multilib_flags]" |
38e31547 NC |
295 | } |
296 | ||
dec20c9e | 297 | verbose -log "$cc $flags $ccflags -c $source -o $object" |
252b5132 | 298 | |
7f6a71ff JM |
299 | set status [remote_exec host [concat sh -c [list "$cc $flags $ccflags -c $source -o $object 2>&1"]] "" "/dev/null" "ld.tmp"] |
300 | remote_upload host "ld.tmp" | |
301 | set exec_output [file_contents "ld.tmp"] | |
302 | remote_file build delete "ld.tmp" | |
303 | remote_file host delete "ld.tmp" | |
252b5132 RH |
304 | set exec_output [prune_warnings $exec_output] |
305 | if [string match "" $exec_output] then { | |
306 | if {![file exists $object]} then { | |
307 | regexp ".*/(\[^/\]*)$" $source all dobj | |
308 | regsub "\\.c" $dobj ".o" realobj | |
309 | verbose "looking for $realobj" | |
7f6a71ff | 310 | if {[remote_file host exists $realobj]} then { |
252b5132 | 311 | verbose -log "mv $realobj $object" |
7f6a71ff | 312 | remote_upload "$realobj" "$object" |
252b5132 RH |
313 | } else { |
314 | perror "$object not found after compilation" | |
315 | return 0 | |
316 | } | |
317 | } | |
318 | return 1 | |
319 | } else { | |
320 | verbose -log "$exec_output" | |
321 | perror "$source: compilation failed" | |
322 | return 0 | |
323 | } | |
324 | } | |
325 | ||
3b6fe0cc | 326 | # Assemble a file. |
252b5132 | 327 | # |
de1491f0 | 328 | proc default_ld_assemble { as in_flags source object } { |
252b5132 RH |
329 | global ASFLAGS |
330 | global host_triplet | |
3e8cba19 | 331 | |
252b5132 RH |
332 | if ![info exists ASFLAGS] { set ASFLAGS "" } |
333 | ||
38e31547 | 334 | set flags [big_or_little_endian] |
de1491f0 | 335 | set exec_output [run_host_cmd "$as" "$flags $in_flags $ASFLAGS -o $object $source"] |
252b5132 RH |
336 | set exec_output [prune_warnings $exec_output] |
337 | if [string match "" $exec_output] then { | |
338 | return 1 | |
339 | } else { | |
252b5132 RH |
340 | perror "$source: assembly failed" |
341 | return 0 | |
342 | } | |
343 | } | |
344 | ||
3b6fe0cc | 345 | # Run nm on a file, putting the result in the array nm_output. |
252b5132 | 346 | # |
992c450d | 347 | proc default_ld_nm { nm nmflags object } { |
252b5132 RH |
348 | global NMFLAGS |
349 | global nm_output | |
350 | global host_triplet | |
351 | ||
77e0b0ef ILT |
352 | if {[info exists nm_output]} { |
353 | unset nm_output | |
354 | } | |
355 | ||
252b5132 RH |
356 | if ![info exists NMFLAGS] { set NMFLAGS "" } |
357 | ||
3e8cba19 AM |
358 | # Ensure consistent sorting of symbols |
359 | if {[info exists env(LC_ALL)]} { | |
360 | set old_lc_all $env(LC_ALL) | |
361 | } | |
362 | set env(LC_ALL) "C" | |
7f6a71ff | 363 | |
992c450d | 364 | verbose -log "$nm $NMFLAGS $nmflags $object >tmpdir/nm.out" |
252b5132 | 365 | |
7f6a71ff | 366 | set status [remote_exec host [concat sh -c [list "$nm $NMFLAGS $nmflags $object 2>ld.stderr"]] "" "/dev/null" "tmpdir/nm.out"] |
3e8cba19 AM |
367 | if {[info exists old_lc_all]} { |
368 | set env(LC_ALL) $old_lc_all | |
369 | } else { | |
370 | unset env(LC_ALL) | |
371 | } | |
7f6a71ff JM |
372 | remote_upload host "ld.stderr" |
373 | remote_upload host "tmpdir/nm.out" "tmpdir/nm.out" | |
374 | set exec_output [prune_warnings [file_contents "ld.stderr"]] | |
375 | remote_file host delete "ld.stderr" | |
376 | remote_file build delete "ld.stderr" | |
252b5132 RH |
377 | if [string match "" $exec_output] then { |
378 | set file [open tmpdir/nm.out r] | |
379 | while { [gets $file line] != -1 } { | |
380 | verbose "$line" 2 | |
dbc37f89 | 381 | if [regexp "^(\[0-9a-fA-F\]+) \[a-zA-Z0-9\] \\.*(.+)$" $line whole value name] { |
252b5132 RH |
382 | set name [string trimleft $name "_"] |
383 | verbose "Setting nm_output($name) to 0x$value" 2 | |
384 | set nm_output($name) 0x$value | |
385 | } | |
386 | } | |
387 | close $file | |
388 | return 1 | |
389 | } else { | |
390 | verbose -log "$exec_output" | |
391 | perror "$object: nm failed" | |
392 | return 0 | |
393 | } | |
394 | } | |
395 | ||
1b662205 AM |
396 | # Define various symbols needed when not linking against all |
397 | # target libs. | |
398 | proc ld_simple_link_defsyms {} { | |
399 | ||
400 | set flags "--defsym __stack_chk_fail=0" | |
401 | ||
402 | # ARM targets call __gccmain | |
8c5fc800 | 403 | if {[istarget arm*-*-*]} { |
1b662205 AM |
404 | append flags " --defsym __gccmain=0" |
405 | } | |
406 | ||
36fe835f DK |
407 | # Windows targets need __main, prefixed with underscore. |
408 | if {[istarget *-*-cygwin* ] || [istarget *-*-mingw*]} { | |
409 | append flags " --defsym ___main=0" | |
410 | } | |
411 | ||
1b662205 AM |
412 | # PowerPC EABI code calls __eabi. |
413 | if {[istarget powerpc*-*-eabi*] || [istarget powerpc*-*-rtems*]} { | |
414 | append flags " --defsym __eabi=0" | |
415 | } | |
416 | ||
417 | # mn10200 code calls __truncsipsi2_d0_d2. | |
418 | if {[istarget mn10200*-*-*]} then { | |
419 | append flags " --defsym __truncsipsi2_d0_d2=0" | |
420 | } | |
421 | ||
422 | # m6811/m6812 code has references to soft registers. | |
32d79e68 | 423 | if {[istarget m6811-*-*] || [istarget m6812-*-*] || [istarget m68hc1*-*-*]} { |
1b662205 AM |
424 | append flags " --defsym _.frame=0 --defsym _.d1=0 --defsym _.d2=0" |
425 | append flags " --defsym _.d3=0 --defsym _.d4=0" | |
426 | append flags " --defsym _.tmp=0 --defsym _.xy=0 --defsym _.z=0" | |
427 | } | |
428 | ||
429 | # Some OpenBSD targets have ProPolice and reference __guard and | |
430 | # __stack_smash_handler. | |
431 | if [istarget *-*-openbsd*] { | |
432 | append flags " --defsym __guard=0" | |
433 | append flags " --defsym __stack_smash_handler=0" | |
434 | } | |
435 | ||
436 | return $flags | |
437 | } | |
438 | ||
ef2b5578 | 439 | # run_dump_test FILE (optional:) EXTRA_OPTIONS |
261def70 HPN |
440 | # Copied from gas testsuite, tweaked and further extended. |
441 | # | |
442 | # Assemble a .s file, then run some utility on it and check the output. | |
3e8cba19 | 443 | # |
261def70 HPN |
444 | # There should be an assembly language file named FILE.s in the test |
445 | # suite directory, and a pattern file called FILE.d. `run_dump_test' | |
446 | # will assemble FILE.s, run some tool like `objdump', `objcopy', or | |
447 | # `nm' on the .o file to produce textual output, and then analyze that | |
448 | # with regexps. The FILE.d file specifies what program to run, and | |
449 | # what to expect in its output. | |
450 | # | |
451 | # The FILE.d file begins with zero or more option lines, which specify | |
452 | # flags to pass to the assembler, the program to run to dump the | |
453 | # assembler's output, and the options it wants. The option lines have | |
454 | # the syntax: | |
3e8cba19 | 455 | # |
261def70 | 456 | # # OPTION: VALUE |
3e8cba19 | 457 | # |
261def70 HPN |
458 | # OPTION is the name of some option, like "name" or "objdump", and |
459 | # VALUE is OPTION's value. The valid options are described below. | |
460 | # Whitespace is ignored everywhere, except within VALUE. The option | |
461 | # list ends with the first line that doesn't match the above syntax | |
462 | # (hmm, not great for error detection). | |
463 | # | |
ef2b5578 MR |
464 | # The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of |
465 | # two-element lists. The first element of each is an option name, and | |
466 | # the second additional arguments to be added on to the end of the | |
467 | # option list as given in FILE.d. (If omitted, no additional options | |
468 | # are added.) | |
469 | # | |
261def70 | 470 | # The interesting options are: |
3e8cba19 | 471 | # |
261def70 HPN |
472 | # name: TEST-NAME |
473 | # The name of this test, passed to DejaGNU's `pass' and `fail' | |
474 | # commands. If omitted, this defaults to FILE, the root of the | |
475 | # .s and .d files' names. | |
3e8cba19 | 476 | # |
261def70 HPN |
477 | # as: FLAGS |
478 | # When assembling, pass FLAGS to the assembler. | |
479 | # If assembling several files, you can pass different assembler | |
480 | # options in the "source" directives. See below. | |
481 | # | |
482 | # ld: FLAGS | |
483 | # Link assembled files using FLAGS, in the order of the "source" | |
484 | # directives, when using multiple files. | |
485 | # | |
d6e0b160 HPN |
486 | # ld_after_inputfiles: FLAGS |
487 | # Similar to "ld", but put after all input files. | |
488 | # | |
cfe5266f HPN |
489 | # objcopy_linked_file: FLAGS |
490 | # Run objcopy on the linked file with the specified flags. | |
491 | # This lets you transform the linked file using objcopy, before the | |
492 | # result is analyzed by an analyzer program specified below (which | |
493 | # may in turn *also* be objcopy). | |
494 | # | |
261def70 HPN |
495 | # PROG: PROGRAM-NAME |
496 | # The name of the program to run to analyze the .o file produced | |
497 | # by the assembler or the linker output. This can be omitted; | |
498 | # run_dump_test will guess which program to run by seeing which of | |
499 | # the flags options below is present. | |
500 | # | |
501 | # objdump: FLAGS | |
502 | # nm: FLAGS | |
503 | # objcopy: FLAGS | |
504 | # Use the specified program to analyze the assembler or linker | |
505 | # output file, and pass it FLAGS, in addition to the output name. | |
3e8cba19 AM |
506 | # Note that they are run with LC_ALL=C in the environment to give |
507 | # consistent sorting of symbols. | |
261def70 HPN |
508 | # |
509 | # source: SOURCE [FLAGS] | |
510 | # Assemble the file SOURCE.s using the flags in the "as" directive | |
511 | # and the (optional) FLAGS. If omitted, the source defaults to | |
512 | # FILE.s. | |
513 | # This is useful if several .d files want to share a .s file. | |
514 | # More than one "source" directive can be given, which is useful | |
515 | # when testing linking. | |
516 | # | |
ef2b5578 MR |
517 | # dump: DUMP |
518 | # Match against DUMP.d. If omitted, this defaults to FILE.d. This | |
519 | # is useful if several .d files differ by options only. Options are | |
520 | # always read from FILE.d. | |
521 | # | |
261def70 HPN |
522 | # xfail: TARGET |
523 | # The test is expected to fail on TARGET. This may occur more than | |
524 | # once. | |
525 | # | |
526 | # target: TARGET | |
527 | # Only run the test for TARGET. This may occur more than once; the | |
33aa234e JK |
528 | # target being tested must match at least one. You may provide target |
529 | # name "cfi" for any target supporting the CFI statements. | |
261def70 HPN |
530 | # |
531 | # notarget: TARGET | |
532 | # Do not run the test for TARGET. This may occur more than once; | |
533 | # the target being tested must not match any of them. | |
534 | # | |
535 | # error: REGEX | |
536 | # An error with message matching REGEX must be emitted for the test | |
537 | # to pass. The PROG, objdump, nm and objcopy options have no | |
164de317 HPN |
538 | # meaning and need not supplied if this is present. Multiple "error" |
539 | # directives append to the expected linker error message. | |
261def70 | 540 | # |
bb00e284 HPN |
541 | # warning: REGEX |
542 | # Expect a linker warning matching REGEX. It is an error to issue | |
164de317 HPN |
543 | # both "error" and "warning". Multiple "warning" directives |
544 | # append to the expected linker warning message. | |
bb00e284 | 545 | # |
261def70 HPN |
546 | # Each option may occur at most once unless otherwise mentioned. |
547 | # | |
548 | # After the option lines come regexp lines. `run_dump_test' calls | |
549 | # `regexp_diff' to compare the output of the dumping tool against the | |
eb22018c RS |
550 | # regexps in FILE.d. `regexp_diff' is defined in binutils-common.exp; |
551 | # see further comments there. | |
3b6fe0cc | 552 | # |
ef2b5578 | 553 | proc run_dump_test { name {extra_options {}} } { |
261def70 HPN |
554 | global subdir srcdir |
555 | global OBJDUMP NM AS OBJCOPY READELF LD | |
556 | global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS LDFLAGS | |
557 | global host_triplet runtests | |
9a2ee7fc | 558 | global env verbose |
261def70 HPN |
559 | |
560 | if [string match "*/*" $name] { | |
561 | set file $name | |
562 | set name [file tail $name] | |
563 | } else { | |
564 | set file "$srcdir/$subdir/$name" | |
565 | } | |
566 | ||
567 | if ![runtest_file_p $runtests $name] then { | |
568 | return | |
569 | } | |
570 | ||
571 | set opt_array [slurp_options "${file}.d"] | |
572 | if { $opt_array == -1 } { | |
573 | perror "error reading options from $file.d" | |
574 | unresolved $subdir/$name | |
575 | return | |
576 | } | |
577 | set dumpfile tmpdir/dump.out | |
578 | set run_ld 0 | |
cfe5266f | 579 | set run_objcopy 0 |
261def70 HPN |
580 | set opts(as) {} |
581 | set opts(ld) {} | |
d6e0b160 | 582 | set opts(ld_after_inputfiles) {} |
261def70 HPN |
583 | set opts(xfail) {} |
584 | set opts(target) {} | |
585 | set opts(notarget) {} | |
586 | set opts(objdump) {} | |
587 | set opts(nm) {} | |
588 | set opts(objcopy) {} | |
589 | set opts(readelf) {} | |
590 | set opts(name) {} | |
591 | set opts(PROG) {} | |
592 | set opts(source) {} | |
ef2b5578 | 593 | set opts(dump) {} |
261def70 | 594 | set opts(error) {} |
bb00e284 | 595 | set opts(warning) {} |
cfe5266f | 596 | set opts(objcopy_linked_file) {} |
261def70 HPN |
597 | |
598 | foreach i $opt_array { | |
599 | set opt_name [lindex $i 0] | |
600 | set opt_val [lindex $i 1] | |
601 | if ![info exists opts($opt_name)] { | |
602 | perror "unknown option $opt_name in file $file.d" | |
603 | unresolved $subdir/$name | |
604 | return | |
605 | } | |
606 | ||
607 | switch -- $opt_name { | |
608 | xfail {} | |
609 | target {} | |
610 | notarget {} | |
164de317 HPN |
611 | warning {} |
612 | error {} | |
261def70 | 613 | source { |
df58fc94 | 614 | # Move any source-specific as-flags to a separate list to |
261def70 HPN |
615 | # simplify processing. |
616 | if { [llength $opt_val] > 1 } { | |
df58fc94 | 617 | lappend asflags [lrange $opt_val 1 end] |
261def70 HPN |
618 | set opt_val [lindex $opt_val 0] |
619 | } else { | |
df58fc94 | 620 | lappend asflags {} |
261def70 HPN |
621 | } |
622 | } | |
623 | default { | |
624 | if [string length $opts($opt_name)] { | |
625 | perror "option $opt_name multiply set in $file.d" | |
626 | unresolved $subdir/$name | |
627 | return | |
628 | } | |
629 | ||
630 | # A single "# ld:" with no options should do the right thing. | |
631 | if { $opt_name == "ld" } { | |
632 | set run_ld 1 | |
633 | } | |
cfe5266f HPN |
634 | # Likewise objcopy_linked_file. |
635 | if { $opt_name == "objcopy_linked_file" } { | |
636 | set run_objcopy 1 | |
637 | } | |
261def70 HPN |
638 | } |
639 | } | |
7f6a71ff JM |
640 | if { $opt_name == "as" || $opt_name == "ld" } { |
641 | set opt_val [subst $opt_val] | |
642 | } | |
134fa82e HPN |
643 | |
644 | # Append differently whether it's a message (without space) or | |
645 | # an option or list (with space). | |
646 | switch -- $opt_name { | |
647 | warning - | |
648 | error { | |
649 | append opts($opt_name) $opt_val | |
650 | } | |
651 | default { | |
652 | set opts($opt_name) [concat $opts($opt_name) $opt_val] | |
653 | } | |
654 | } | |
261def70 | 655 | } |
ef2b5578 MR |
656 | |
657 | foreach i $extra_options { | |
658 | set opt_name [lindex $i 0] | |
659 | set opt_val [lindex $i 1] | |
660 | if ![info exists opts($opt_name)] { | |
661 | perror "unknown option $opt_name given in extra_opts" | |
662 | unresolved $subdir/$name | |
663 | return | |
664 | } | |
665 | # Add extra option to end of existing option, adding space | |
666 | # if necessary. | |
667 | if { ![regexp "warning|error" $opt_name] | |
668 | && [string length $opts($opt_name)] } { | |
669 | append opts($opt_name) " " | |
670 | } | |
671 | append opts($opt_name) $opt_val | |
672 | } | |
673 | ||
3935e1af RS |
674 | foreach opt { as ld } { |
675 | regsub {\[big_or_little_endian\]} $opts($opt) \ | |
676 | [big_or_little_endian] opts($opt) | |
677 | } | |
261def70 HPN |
678 | |
679 | # Decide early whether we should run the test for this target. | |
680 | if { [llength $opts(target)] > 0 } { | |
681 | set targmatch 0 | |
682 | foreach targ $opts(target) { | |
683 | if [istarget $targ] { | |
684 | set targmatch 1 | |
685 | break | |
686 | } | |
687 | } | |
688 | if { $targmatch == 0 } { | |
689 | return | |
690 | } | |
691 | } | |
692 | foreach targ $opts(notarget) { | |
693 | if [istarget $targ] { | |
694 | return | |
695 | } | |
696 | } | |
697 | ||
f364d1ca AM |
698 | set program "" |
699 | # It's meaningless to require an output-testing method when we | |
700 | # expect an error. | |
701 | if { $opts(error) == "" } { | |
702 | if {$opts(PROG) != ""} { | |
703 | switch -- $opts(PROG) { | |
704 | objdump { set program objdump } | |
705 | nm { set program nm } | |
706 | objcopy { set program objcopy } | |
707 | readelf { set program readelf } | |
708 | default | |
261def70 HPN |
709 | { perror "unrecognized program option $opts(PROG) in $file.d" |
710 | unresolved $subdir/$name | |
711 | return } | |
f364d1ca AM |
712 | } |
713 | } else { | |
261def70 | 714 | # Guess which program to run, by seeing which option was specified. |
f364d1ca AM |
715 | foreach p {objdump objcopy nm readelf} { |
716 | if {$opts($p) != ""} { | |
717 | if {$program != ""} { | |
718 | perror "ambiguous dump program in $file.d" | |
719 | unresolved $subdir/$name | |
720 | return | |
721 | } else { | |
722 | set program $p | |
723 | } | |
261def70 HPN |
724 | } |
725 | } | |
726 | } | |
f364d1ca | 727 | if { $program == "" && $opts(warning) == "" } { |
261def70 HPN |
728 | perror "dump program unspecified in $file.d" |
729 | unresolved $subdir/$name | |
730 | return | |
731 | } | |
732 | } | |
733 | ||
261def70 HPN |
734 | if { $opts(name) == "" } { |
735 | set testname "$subdir/$name" | |
736 | } else { | |
737 | set testname $opts(name) | |
738 | } | |
739 | ||
740 | if { $opts(source) == "" } { | |
741 | set sourcefiles [list ${file}.s] | |
df58fc94 | 742 | set asflags [list ""] |
261def70 HPN |
743 | } else { |
744 | set sourcefiles {} | |
745 | foreach sf $opts(source) { | |
b7b0b729 HPN |
746 | if { [string match "/*" $sf] } { |
747 | lappend sourcefiles "$sf" | |
f364d1ca | 748 | } else { |
b7b0b729 HPN |
749 | lappend sourcefiles "$srcdir/$subdir/$sf" |
750 | } | |
261def70 HPN |
751 | } |
752 | } | |
753 | ||
ef2b5578 MR |
754 | if { $opts(dump) == "" } { |
755 | set dfile ${file}.d | |
756 | } else { | |
757 | set dfile $srcdir/$subdir/$opts(dump) | |
758 | } | |
759 | ||
65951855 RM |
760 | if { [string match "*--compress-debug-sections*" $opts(as)] \ |
761 | && ![is_zlib_supported] } { | |
762 | unsupported $testname | |
763 | return | |
764 | } | |
765 | ||
261def70 HPN |
766 | # Time to setup xfailures. |
767 | foreach targ $opts(xfail) { | |
768 | setup_xfail $targ | |
769 | } | |
770 | ||
771 | # Assemble each file. | |
772 | set objfiles {} | |
773 | for { set i 0 } { $i < [llength $sourcefiles] } { incr i } { | |
774 | set sourcefile [lindex $sourcefiles $i] | |
df58fc94 | 775 | set sourceasflags [lindex $asflags $i] |
261def70 HPN |
776 | |
777 | set objfile "tmpdir/dump$i.o" | |
30dabe8a | 778 | catch "exec rm -f $objfile" exec_output |
261def70 | 779 | lappend objfiles $objfile |
df58fc94 | 780 | set cmd "$AS $ASFLAGS $opts(as) $sourceasflags -o $objfile $sourcefile" |
261def70 HPN |
781 | |
782 | send_log "$cmd\n" | |
7f6a71ff JM |
783 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"] |
784 | remote_upload host "ld.tmp" | |
785 | set comp_output [prune_warnings [file_contents "ld.tmp"]] | |
786 | remote_file host delete "ld.tmp" | |
787 | remote_file build delete "ld.tmp" | |
261def70 | 788 | |
7f6a71ff | 789 | if { [lindex $cmdret 0] != 0 || ![string match "" $comp_output] } then { |
261def70 HPN |
790 | send_log "$comp_output\n" |
791 | verbose "$comp_output" 3 | |
f364d1ca AM |
792 | |
793 | set exitstat "succeeded" | |
794 | if { $cmdret != 0 } { set exitstat "failed" } | |
795 | verbose -log "$exitstat with: <$comp_output>" | |
261def70 HPN |
796 | fail $testname |
797 | return | |
798 | } | |
799 | } | |
800 | ||
f364d1ca AM |
801 | set expmsg $opts(error) |
802 | if { $opts(warning) != "" } { | |
803 | if { $expmsg != "" } { | |
804 | perror "$testname: mixing error and warning test-directives" | |
805 | return | |
806 | } | |
807 | set expmsg $opts(warning) | |
808 | } | |
809 | ||
261def70 HPN |
810 | # Perhaps link the file(s). |
811 | if { $run_ld } { | |
812 | set objfile "tmpdir/dump" | |
30dabe8a | 813 | catch "exec rm -f $objfile" exec_output |
3e3f011f RS |
814 | |
815 | # Add -L$srcdir/$subdir so that the linker command can use | |
816 | # linker scripts in the source directory. | |
817 | set cmd "$LD $LDFLAGS -L$srcdir/$subdir \ | |
d6e0b160 | 818 | $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)" |
261def70 HPN |
819 | |
820 | send_log "$cmd\n" | |
7f6a71ff JM |
821 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"] |
822 | remote_upload host "ld.tmp" | |
d3746675 | 823 | set comp_output [file_contents "ld.tmp"] |
7f6a71ff JM |
824 | remote_file host delete "ld.tmp" |
825 | remote_file build delete "ld.tmp" | |
826 | set cmdret [lindex $cmdret 0] | |
cfe5266f | 827 | |
f364d1ca | 828 | if { $cmdret == 0 && $run_objcopy } { |
cfe5266f HPN |
829 | set infile $objfile |
830 | set objfile "tmpdir/dump1" | |
7f6a71ff | 831 | remote_file host delete $objfile |
cfe5266f HPN |
832 | |
833 | # Note that we don't use OBJCOPYFLAGS here; any flags must be | |
834 | # explicitly specified. | |
835 | set cmd "$OBJCOPY $opts(objcopy_linked_file) $infile $objfile" | |
836 | ||
837 | send_log "$cmd\n" | |
7f6a71ff JM |
838 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"] |
839 | remote_upload host "ld.tmp" | |
d3746675 | 840 | append comp_output [file_contents "ld.tmp"] |
7f6a71ff JM |
841 | remote_file host delete "ld.tmp" |
842 | remote_file build delete "ld.tmp" | |
843 | set cmdret [lindex $cmdret 0] | |
f364d1ca AM |
844 | } |
845 | ||
7f6a71ff | 846 | regsub "\n$" $comp_output "" comp_output |
f364d1ca AM |
847 | if { $cmdret != 0 || $comp_output != "" || $expmsg != "" } then { |
848 | set exitstat "succeeded" | |
849 | if { $cmdret != 0 } { set exitstat "failed" } | |
850 | verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>" | |
851 | send_log "$comp_output\n" | |
852 | verbose "$comp_output" 3 | |
853 | ||
164de317 HPN |
854 | if { ($expmsg == "") == ($comp_output == "") \ |
855 | && [regexp $expmsg $comp_output] \ | |
856 | && (($cmdret == 0) == ($opts(error) == "")) } { | |
f364d1ca AM |
857 | # We have the expected output from ld. |
858 | if { $opts(error) != "" || $program == "" } { | |
859 | pass $testname | |
860 | return | |
cfe5266f | 861 | } |
f364d1ca AM |
862 | } else { |
863 | verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>" | |
cfe5266f HPN |
864 | fail $testname |
865 | return | |
866 | } | |
867 | } | |
261def70 HPN |
868 | } else { |
869 | set objfile "tmpdir/dump0.o" | |
870 | } | |
871 | ||
872 | # We must not have expected failure if we get here. | |
873 | if { $opts(error) != "" } { | |
874 | fail $testname | |
cfe5266f | 875 | return |
261def70 HPN |
876 | } |
877 | ||
f364d1ca AM |
878 | set progopts1 $opts($program) |
879 | eval set progopts \$[string toupper $program]FLAGS | |
880 | eval set binary \$[string toupper $program] | |
881 | ||
7f6a71ff | 882 | if { ![is_remote host] && [which $binary] == 0 } { |
261def70 HPN |
883 | untested $testname |
884 | return | |
885 | } | |
886 | ||
887 | if { $progopts1 == "" } { set $progopts1 "-r" } | |
888 | verbose "running $binary $progopts $progopts1" 3 | |
889 | ||
890 | # Objcopy, unlike the other two, won't send its output to stdout, | |
891 | # so we have to run it specially. | |
3e8cba19 | 892 | set cmd "$binary $progopts $progopts1 $objfile > $dumpfile" |
261def70 HPN |
893 | if { $program == "objcopy" } { |
894 | set cmd "$binary $progopts $progopts1 $objfile $dumpfile" | |
3e8cba19 AM |
895 | } |
896 | ||
897 | # Ensure consistent sorting of symbols | |
898 | if {[info exists env(LC_ALL)]} { | |
899 | set old_lc_all $env(LC_ALL) | |
900 | } | |
901 | set env(LC_ALL) "C" | |
902 | send_log "$cmd\n" | |
7f6a71ff | 903 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>ld.tmp"]] "" "/dev/null"] |
164de317 | 904 | set cmdret [lindex $cmdret 0] |
7f6a71ff JM |
905 | remote_upload host "ld.tmp" |
906 | set comp_output [prune_warnings [file_contents "ld.tmp"]] | |
907 | remote_file host delete "ld.tmp" | |
908 | remote_file build delete "ld.tmp" | |
3e8cba19 AM |
909 | if {[info exists old_lc_all]} { |
910 | set env(LC_ALL) $old_lc_all | |
261def70 | 911 | } else { |
3e8cba19 AM |
912 | unset env(LC_ALL) |
913 | } | |
164de317 HPN |
914 | if { $cmdret != 0 || $comp_output != "" } { |
915 | send_log "exited abnormally with $cmdret, output:$comp_output\n" | |
3e8cba19 AM |
916 | fail $testname |
917 | return | |
261def70 HPN |
918 | } |
919 | ||
9a2ee7fc | 920 | if { $verbose > 2 } then { verbose "output is [file_contents $dumpfile]" 3 } |
ef2b5578 | 921 | if { [regexp_diff $dumpfile "${dfile}"] } then { |
261def70 | 922 | fail $testname |
9a2ee7fc | 923 | if { $verbose == 2 } then { verbose "output is [file_contents $dumpfile]" 2 } |
261def70 HPN |
924 | return |
925 | } | |
926 | ||
927 | pass $testname | |
928 | } | |
929 | ||
930 | proc slurp_options { file } { | |
5a68afcf RM |
931 | # If options_regsub(foo) is set to {a b}, then the contents of a |
932 | # "#foo:" line will have regsub -all applied to replace a with b. | |
933 | global options_regsub | |
934 | ||
261def70 HPN |
935 | if [catch { set f [open $file r] } x] { |
936 | #perror "couldn't open `$file': $x" | |
937 | perror "$x" | |
938 | return -1 | |
939 | } | |
940 | set opt_array {} | |
941 | # whitespace expression | |
942 | set ws {[ ]*} | |
943 | set nws {[^ ]*} | |
944 | # whitespace is ignored anywhere except within the options list; | |
cfe5266f HPN |
945 | # option names are alphabetic plus underscore only. |
946 | set pat "^#${ws}(\[a-zA-Z_\]*)$ws:${ws}(.*)$ws\$" | |
261def70 HPN |
947 | while { [gets $f line] != -1 } { |
948 | set line [string trim $line] | |
949 | # Whitespace here is space-tab. | |
950 | if [regexp $pat $line xxx opt_name opt_val] { | |
951 | # match! | |
5a68afcf RM |
952 | if [info exists options_regsub($opt_name)] { |
953 | set subst $options_regsub($opt_name) | |
954 | regsub -all -- [lindex $subst 0] $opt_val [lindex $subst 1] \ | |
955 | opt_val | |
956 | } | |
261def70 HPN |
957 | lappend opt_array [list $opt_name $opt_val] |
958 | } else { | |
959 | break | |
960 | } | |
961 | } | |
962 | close $f | |
963 | return $opt_array | |
964 | } | |
965 | ||
261def70 HPN |
966 | proc file_contents { filename } { |
967 | set file [open $filename r] | |
968 | set contents [read $file] | |
969 | close $file | |
970 | return $contents | |
971 | } | |
bffbf940 | 972 | |
5d3236ee DK |
973 | proc set_file_contents { filename contents } { |
974 | set file [open $filename w] | |
975 | puts $file "$contents" | |
976 | close $file | |
977 | } | |
978 | ||
d8880531 L |
979 | # Create an archive using ar |
980 | # | |
fa0a16b1 | 981 | proc ar_simple_create { ar aropts target objects } { |
d8880531 L |
982 | remote_file host delete $target |
983 | ||
fa0a16b1 | 984 | set exec_output [run_host_cmd "$ar" "$aropts rc $target $objects"] |
d8880531 L |
985 | set exec_output [prune_warnings $exec_output] |
986 | ||
987 | if [string match "" $exec_output] then { | |
988 | send_log "$exec_output\n" | |
989 | return 1 | |
990 | } else { | |
991 | return 0 | |
992 | } | |
993 | } | |
994 | ||
9147e853 JJ |
995 | # List contains test-items with 3 items followed by 2 lists, one item and |
996 | # one optional item: | |
894891db NC |
997 | # 0:name |
998 | # 1:ld/ar options | |
999 | # 2:assembler options | |
1000 | # 3:filenames of assembler files | |
1001 | # 4:list of actions, options and expected outputs. | |
1002 | # 5:name of output file | |
1003 | # 6:compiler flags (optional) | |
3b6fe0cc | 1004 | # |
894891db NC |
1005 | # Actions: { command command-line-options file-containg-expected-output-regexps } |
1006 | # Commands: | |
1007 | # objdump: Apply objdump options on result. | |
1008 | # nm: Apply nm options on result. | |
1009 | # readelf: Apply readelf options on result. | |
5a68afcf | 1010 | # ld: Don't apply anything on result. Compare output during linking with |
894891db NC |
1011 | # the file containing regexps (which is the second arg, not the third). |
1012 | # Note that this *must* be the first action if it is to be used at all; | |
1013 | # in all other cases, any output from the linker during linking is | |
1014 | # treated as a sign of an error and FAILs the test. | |
3b6fe0cc | 1015 | # |
bffbf940 JJ |
1016 | proc run_ld_link_tests { ldtests } { |
1017 | global ld | |
1018 | global as | |
1019 | global nm | |
d8880531 | 1020 | global ar |
bffbf940 JJ |
1021 | global objdump |
1022 | global READELF | |
1023 | global srcdir | |
1024 | global subdir | |
1025 | global env | |
9147e853 JJ |
1026 | global CC |
1027 | global CFLAGS | |
eca41774 | 1028 | global runtests |
5d3236ee | 1029 | global exec_output |
bffbf940 JJ |
1030 | |
1031 | foreach testitem $ldtests { | |
1032 | set testname [lindex $testitem 0] | |
eca41774 DK |
1033 | |
1034 | if ![runtest_file_p $runtests $testname] then { | |
1035 | continue | |
1036 | } | |
1037 | ||
bffbf940 JJ |
1038 | set ld_options [lindex $testitem 1] |
1039 | set as_options [lindex $testitem 2] | |
9147e853 | 1040 | set src_files [lindex $testitem 3] |
bffbf940 JJ |
1041 | set actions [lindex $testitem 4] |
1042 | set binfile tmpdir/[lindex $testitem 5] | |
9147e853 | 1043 | set cflags [lindex $testitem 6] |
bffbf940 JJ |
1044 | set objfiles {} |
1045 | set is_unresolved 0 | |
1046 | set failed 0 | |
5d3236ee DK |
1047 | set maybe_failed 0 |
1048 | set ld_output "" | |
bffbf940 JJ |
1049 | |
1050 | # verbose -log "Testname is $testname" | |
1051 | # verbose -log "ld_options is $ld_options" | |
1052 | # verbose -log "as_options is $as_options" | |
9147e853 | 1053 | # verbose -log "src_files is $src_files" |
bffbf940 JJ |
1054 | # verbose -log "actions is $actions" |
1055 | # verbose -log "binfile is $binfile" | |
1056 | ||
1057 | # Assemble each file in the test. | |
9147e853 | 1058 | foreach src_file $src_files { |
74d44110 MR |
1059 | set fileroot "[file rootname [file tail $src_file]]" |
1060 | set objfile "tmpdir/$fileroot.o" | |
bffbf940 JJ |
1061 | lappend objfiles $objfile |
1062 | ||
9147e853 | 1063 | if { [file extension $src_file] == ".c" } { |
74d44110 | 1064 | set as_file "tmpdir/$fileroot.s" |
9147e853 JJ |
1065 | if ![ld_compile "$CC -S $CFLAGS $cflags" $srcdir/$subdir/$src_file $as_file] { |
1066 | set is_unresolved 1 | |
1067 | break | |
1068 | } | |
1069 | } else { | |
1070 | set as_file "$srcdir/$subdir/$src_file" | |
1071 | } | |
1072 | if ![ld_assemble $as "$as_options $as_file" $objfile] { | |
bffbf940 JJ |
1073 | set is_unresolved 1 |
1074 | break | |
1075 | } | |
1076 | } | |
1077 | ||
1078 | # Catch assembler errors. | |
77c56f44 | 1079 | if { $is_unresolved } { |
bffbf940 JJ |
1080 | unresolved $testname |
1081 | continue | |
1082 | } | |
1083 | ||
a7470592 | 1084 | if { [regexp ".*\\.a$" $binfile] } { |
fa0a16b1 | 1085 | if { ![ar_simple_create $ar $ld_options $binfile "$objfiles"] } { |
d8880531 | 1086 | set failed 1 |
d8880531 | 1087 | } |
fa0a16b1 | 1088 | } elseif { ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] } { |
5d3236ee DK |
1089 | set maybe_failed 1 |
1090 | set ld_output "$exec_output" | |
d8880531 L |
1091 | } |
1092 | ||
77c56f44 | 1093 | if { !$failed } { |
bffbf940 JJ |
1094 | foreach actionlist $actions { |
1095 | set action [lindex $actionlist 0] | |
1096 | set progopts [lindex $actionlist 1] | |
1097 | ||
1098 | # There are actions where we run regexp_diff on the | |
1099 | # output, and there are other actions (presumably). | |
1100 | # Handling of the former look the same. | |
1101 | set dump_prog "" | |
1102 | switch -- $action { | |
1103 | objdump | |
1104 | { set dump_prog $objdump } | |
1105 | nm | |
1106 | { set dump_prog $nm } | |
1107 | readelf | |
1108 | { set dump_prog $READELF } | |
5d3236ee DK |
1109 | ld |
1110 | { set dump_prog "ld" } | |
bffbf940 JJ |
1111 | default |
1112 | { | |
1113 | perror "Unrecognized action $action" | |
1114 | set is_unresolved 1 | |
1115 | break | |
1116 | } | |
1117 | } | |
1118 | ||
5d3236ee | 1119 | if { $action == "ld" } { |
894891db NC |
1120 | set regexpfile $progopts |
1121 | verbose "regexpfile is $srcdir/$subdir/$regexpfile" | |
5d3236ee DK |
1122 | set_file_contents "tmpdir/ld.messages" "$ld_output" |
1123 | verbose "ld.messages has '[file_contents tmpdir/ld.messages]'" | |
894891db | 1124 | if { [regexp_diff "tmpdir/ld.messages" "$srcdir/$subdir/$regexpfile"] } then { |
5d3236ee DK |
1125 | verbose "output is $ld_output" 2 |
1126 | set failed 1 | |
1127 | break | |
1128 | } | |
1129 | set maybe_failed 0 | |
77c56f44 | 1130 | } elseif { !$maybe_failed && $dump_prog != "" } { |
bffbf940 JJ |
1131 | set dumpfile [lindex $actionlist 2] |
1132 | set binary $dump_prog | |
1133 | ||
1134 | # Ensure consistent sorting of symbols | |
1135 | if {[info exists env(LC_ALL)]} { | |
1136 | set old_lc_all $env(LC_ALL) | |
1137 | } | |
1138 | set env(LC_ALL) "C" | |
7f6a71ff JM |
1139 | set cmd "$binary $progopts $binfile" |
1140 | set status [remote_exec host [concat sh -c [list "$cmd >dump.out 2>ld.stderr"]] "" "/dev/null"] | |
bffbf940 | 1141 | send_log "$cmd\n" |
7f6a71ff JM |
1142 | remote_upload host "ld.stderr" |
1143 | set comp_output [prune_warnings [file_contents "ld.stderr"]] | |
1144 | remote_file host delete "ld.stderr" | |
1145 | remote_file build delete "ld.stderr" | |
5a68afcf | 1146 | |
bffbf940 JJ |
1147 | if {[info exists old_lc_all]} { |
1148 | set env(LC_ALL) $old_lc_all | |
1149 | } else { | |
1150 | unset env(LC_ALL) | |
1151 | } | |
bffbf940 JJ |
1152 | |
1153 | if ![string match "" $comp_output] then { | |
1154 | send_log "$comp_output\n" | |
1155 | set failed 1 | |
1156 | break | |
1157 | } | |
1158 | ||
7f6a71ff JM |
1159 | remote_upload host "dump.out" |
1160 | ||
bffbf940 JJ |
1161 | if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then { |
1162 | verbose "output is [file_contents "dump.out"]" 2 | |
1163 | set failed 1 | |
7f6a71ff JM |
1164 | remote_file build delete "dump.out" |
1165 | remote_file host delete "dump.out" | |
bffbf940 JJ |
1166 | break |
1167 | } | |
7f6a71ff JM |
1168 | remote_file build delete "dump.out" |
1169 | remote_file host delete "dump.out" | |
bffbf940 JJ |
1170 | } |
1171 | } | |
bffbf940 JJ |
1172 | } |
1173 | ||
77c56f44 | 1174 | if { $is_unresolved } { |
bffbf940 | 1175 | unresolved $testname |
77c56f44 RS |
1176 | } elseif { $maybe_failed || $failed } { |
1177 | fail $testname | |
1178 | } else { | |
1179 | pass $testname | |
bffbf940 JJ |
1180 | } |
1181 | } | |
1182 | } | |
1183 | ||
252b5132 RH |
1184 | # This definition is taken from an unreleased version of DejaGnu. Once |
1185 | # that version gets released, and has been out in the world for a few | |
1186 | # months at least, it may be safe to delete this copy. | |
1187 | if ![string length [info proc prune_warnings]] { | |
1188 | # | |
1189 | # prune_warnings -- delete various system verbosities from TEXT | |
1190 | # | |
1191 | # An example is: | |
1192 | # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9 | |
1193 | # | |
1194 | # Sites with particular verbose os's may wish to override this in site.exp. | |
1195 | # | |
1196 | proc prune_warnings { text } { | |
1197 | # This is from sun4's. Do it for all machines for now. | |
1198 | # The "\\1" is to try to preserve a "\n" but only if necessary. | |
1199 | regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text | |
1200 | ||
1201 | # It might be tempting to get carried away and delete blank lines, etc. | |
1202 | # Just delete *exactly* what we're ask to, and that's it. | |
1203 | return $text | |
1204 | } | |
1205 | } | |
24edc24d | 1206 | |
c8c140d9 BE |
1207 | # targets_to_xfail is a list of target triplets to be xfailed. |
1208 | # ldtests contains test-items with 3 items followed by 1 lists, 2 items | |
fab4a87f | 1209 | # and 3 optional items: |
c8c140d9 BE |
1210 | # 0:name |
1211 | # 1:ld options | |
1212 | # 2:assembler options | |
55255dae | 1213 | # 3:filenames of source files |
c8c140d9 BE |
1214 | # 4:name of output file |
1215 | # 5:expected output | |
1216 | # 6:compiler flags (optional) | |
55255dae | 1217 | # 7:language (optional) |
fab4a87f | 1218 | # 8:linker warning (optional) |
c8c140d9 BE |
1219 | |
1220 | proc run_ld_link_exec_tests { targets_to_xfail ldtests } { | |
24edc24d L |
1221 | global ld |
1222 | global as | |
1223 | global srcdir | |
1224 | global subdir | |
1225 | global env | |
1226 | global CC | |
55255dae | 1227 | global CXX |
24edc24d | 1228 | global CFLAGS |
58ffc3bd | 1229 | global CXXFLAGS |
22ec3bd1 | 1230 | global errcnt |
fab4a87f | 1231 | global exec_output |
24edc24d L |
1232 | |
1233 | foreach testitem $ldtests { | |
c8c140d9 BE |
1234 | foreach target $targets_to_xfail { |
1235 | setup_xfail $target | |
1236 | } | |
24edc24d L |
1237 | set testname [lindex $testitem 0] |
1238 | set ld_options [lindex $testitem 1] | |
1239 | set as_options [lindex $testitem 2] | |
1240 | set src_files [lindex $testitem 3] | |
1241 | set binfile tmpdir/[lindex $testitem 4] | |
1242 | set expfile [lindex $testitem 5] | |
1243 | set cflags [lindex $testitem 6] | |
55255dae | 1244 | set lang [lindex $testitem 7] |
fab4a87f | 1245 | set warning [lindex $testitem 8] |
24edc24d | 1246 | set objfiles {} |
24edc24d L |
1247 | set failed 0 |
1248 | ||
1249 | # verbose -log "Testname is $testname" | |
1250 | # verbose -log "ld_options is $ld_options" | |
1251 | # verbose -log "as_options is $as_options" | |
1252 | # verbose -log "src_files is $src_files" | |
24edc24d L |
1253 | # verbose -log "binfile is $binfile" |
1254 | ||
1255 | # Assemble each file in the test. | |
1256 | foreach src_file $src_files { | |
74d44110 MR |
1257 | set fileroot "[file rootname [file tail $src_file]]" |
1258 | set objfile "tmpdir/$fileroot.o" | |
24edc24d L |
1259 | lappend objfiles $objfile |
1260 | ||
a10e6b21 L |
1261 | # We ignore warnings since some compilers may generate |
1262 | # incorrect section attributes and the assembler will warn | |
1263 | # them. | |
58ffc3bd MF |
1264 | if { [ string match "c++" $lang ] } { |
1265 | ld_compile "$CXX -c $CXXFLAGS $cflags" $srcdir/$subdir/$src_file $objfile | |
1266 | } else { | |
1267 | ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/$src_file $objfile | |
1268 | } | |
cb5ab6c8 | 1269 | } |
a10e6b21 | 1270 | |
cb5ab6c8 L |
1271 | # We have to use $CC to build PIE and shared library. |
1272 | if { [ string match "c" $lang ] } { | |
1273 | set link_proc ld_simple_link | |
1274 | set link_cmd $CC | |
1275 | } elseif { [ string match "c++" $lang ] } { | |
1276 | set link_proc ld_simple_link | |
1277 | set link_cmd $CXX | |
1278 | } elseif { [ string match "-shared" $ld_options ] \ | |
1279 | || [ string match "-pie" $ld_options ] } { | |
1280 | set link_proc ld_simple_link | |
1281 | set link_cmd $CC | |
1282 | } else { | |
1283 | set link_proc ld_link | |
1284 | set link_cmd $ld | |
1285 | } | |
24edc24d | 1286 | |
cb5ab6c8 L |
1287 | if ![$link_proc $link_cmd $binfile "-L$srcdir/$subdir $ld_options $objfiles"] { |
1288 | set failed 1 | |
1289 | } else { | |
1290 | set failed 0 | |
1291 | } | |
1292 | ||
1293 | # Check if exec_output is expected. | |
1294 | if { $warning != "" } then { | |
1295 | verbose -log "returned with: <$exec_output>, expected: <$warning>" | |
1296 | if { [regexp $warning $exec_output] } then { | |
a10e6b21 | 1297 | set failed 0 |
cb5ab6c8 L |
1298 | } else { |
1299 | set failed 1 | |
fab4a87f | 1300 | } |
cb5ab6c8 | 1301 | } |
fab4a87f | 1302 | |
cb5ab6c8 L |
1303 | if { $failed == 0 } { |
1304 | send_log "Running: $binfile > $binfile.out\n" | |
1305 | verbose "Running: $binfile > $binfile.out" | |
1306 | catch "exec $binfile > $binfile.out" exec_output | |
fab4a87f | 1307 | |
cb5ab6c8 L |
1308 | if ![string match "" $exec_output] then { |
1309 | send_log "$exec_output\n" | |
1310 | verbose "$exec_output" 1 | |
1311 | set failed 1 | |
1312 | } else { | |
1313 | send_log "diff $binfile.out $srcdir/$subdir/$expfile\n" | |
1314 | verbose "diff $binfile.out $srcdir/$subdir/$expfile" | |
1315 | catch "exec diff $binfile.out $srcdir/$subdir/$expfile" exec_output | |
1316 | set exec_output [prune_warnings $exec_output] | |
5a68afcf | 1317 | |
24edc24d L |
1318 | if ![string match "" $exec_output] then { |
1319 | send_log "$exec_output\n" | |
1320 | verbose "$exec_output" 1 | |
1321 | set failed 1 | |
1322 | } | |
1323 | } | |
cb5ab6c8 | 1324 | } |
24edc24d | 1325 | |
cb5ab6c8 L |
1326 | if { $failed != 0 } { |
1327 | fail $testname | |
1328 | } else { | |
1329 | set errcnt 0 | |
1330 | pass $testname | |
24edc24d | 1331 | } |
24edc24d L |
1332 | } |
1333 | } | |
d2dee3b2 L |
1334 | |
1335 | # List contains test-items with 3 items followed by 2 lists, one item and | |
1336 | # one optional item: | |
55255dae | 1337 | # 0:name |
fa0a16b1 | 1338 | # 1:ld or ar options |
55255dae L |
1339 | # 2:compile options |
1340 | # 3:filenames of source files | |
1341 | # 4:action and options. | |
1342 | # 5:name of output file | |
1343 | # 6:language (optional) | |
dd98f8d2 | 1344 | # 7:linker warnings (optional) |
d2dee3b2 L |
1345 | # |
1346 | # Actions: | |
1347 | # objdump: Apply objdump options on result. Compare with regex (last arg). | |
1348 | # nm: Apply nm options on result. Compare with regex (last arg). | |
1349 | # readelf: Apply readelf options on result. Compare with regex (last arg). | |
1350 | # | |
1351 | proc run_cc_link_tests { ldtests } { | |
1352 | global nm | |
1353 | global objdump | |
1354 | global READELF | |
1355 | global srcdir | |
1356 | global subdir | |
1357 | global env | |
1358 | global CC | |
55255dae | 1359 | global CXX |
d2dee3b2 | 1360 | global CFLAGS |
58ffc3bd | 1361 | global CXXFLAGS |
d8880531 | 1362 | global ar |
dd98f8d2 | 1363 | global exec_output |
d2dee3b2 L |
1364 | |
1365 | foreach testitem $ldtests { | |
1366 | set testname [lindex $testitem 0] | |
1367 | set ldflags [lindex $testitem 1] | |
1368 | set cflags [lindex $testitem 2] | |
1369 | set src_files [lindex $testitem 3] | |
1370 | set actions [lindex $testitem 4] | |
1371 | set binfile tmpdir/[lindex $testitem 5] | |
55255dae | 1372 | set lang [lindex $testitem 6] |
dd98f8d2 | 1373 | set warnings [lindex $testitem 7] |
d2dee3b2 L |
1374 | set objfiles {} |
1375 | set is_unresolved 0 | |
1376 | set failed 0 | |
1377 | ||
1378 | # Compile each file in the test. | |
1379 | foreach src_file $src_files { | |
74d44110 MR |
1380 | set fileroot "[file rootname [file tail $src_file]]" |
1381 | set objfile "tmpdir/$fileroot.o" | |
d2dee3b2 L |
1382 | lappend objfiles $objfile |
1383 | ||
1384 | # We ignore warnings since some compilers may generate | |
1385 | # incorrect section attributes and the assembler will warn | |
1386 | # them. | |
58ffc3bd MF |
1387 | if { [ string match "c++" $lang ] } { |
1388 | ld_compile "$CXX -c $CXXFLAGS $cflags" $srcdir/$subdir/$src_file $objfile | |
1389 | } else { | |
1390 | ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/$src_file $objfile | |
1391 | } | |
d2dee3b2 L |
1392 | } |
1393 | ||
1394 | # Clear error and warning counts. | |
1395 | reset_vars | |
1396 | ||
55255dae L |
1397 | if { [ string match "c++" $lang ] } { |
1398 | set cc_cmd $CXX | |
1399 | } else { | |
1400 | set cc_cmd $CC | |
1401 | } | |
1402 | ||
a7470592 | 1403 | if { [regexp ".*\\.a$" $binfile] } { |
fa0a16b1 | 1404 | if { ![ar_simple_create $ar $ldflags $binfile "$objfiles"] } { |
d8880531 L |
1405 | fail $testname |
1406 | set failed 1 | |
1407 | } else { | |
1408 | set failed 0 | |
1409 | } | |
fa0a16b1 | 1410 | } elseif { ![ld_simple_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles"] } { |
dd98f8d2 NC |
1411 | # Check if exec_output is expected. |
1412 | if { $warnings != "" } then { | |
1413 | verbose -log "returned with: <$exec_output>, expected: <$warnings>" | |
1414 | if { [regexp $warnings $exec_output] } then { | |
1415 | set failed 0 | |
1416 | } else { | |
1417 | set failed 1 | |
1418 | } | |
1419 | } else { | |
1420 | fail $testname | |
1421 | set failed 1 | |
1422 | } | |
d2dee3b2 L |
1423 | } else { |
1424 | set failed 0 | |
d8880531 L |
1425 | } |
1426 | ||
1427 | if { $failed == 0 } { | |
d2dee3b2 L |
1428 | foreach actionlist $actions { |
1429 | set action [lindex $actionlist 0] | |
1430 | set progopts [lindex $actionlist 1] | |
1431 | ||
1432 | # There are actions where we run regexp_diff on the | |
1433 | # output, and there are other actions (presumably). | |
1434 | # Handling of the former look the same. | |
1435 | set dump_prog "" | |
1436 | switch -- $action { | |
1437 | objdump | |
1438 | { set dump_prog $objdump } | |
1439 | nm | |
1440 | { set dump_prog $nm } | |
1441 | readelf | |
1442 | { set dump_prog $READELF } | |
1443 | default | |
1444 | { | |
1445 | perror "Unrecognized action $action" | |
1446 | set is_unresolved 1 | |
1447 | break | |
1448 | } | |
1449 | } | |
1450 | ||
1451 | if { $dump_prog != "" } { | |
1452 | set dumpfile [lindex $actionlist 2] | |
1453 | set binary $dump_prog | |
1454 | ||
1455 | # Ensure consistent sorting of symbols | |
1456 | if {[info exists env(LC_ALL)]} { | |
1457 | set old_lc_all $env(LC_ALL) | |
1458 | } | |
1459 | set env(LC_ALL) "C" | |
1460 | set cmd "$binary $progopts $binfile > dump.out" | |
1461 | send_log "$cmd\n" | |
1462 | catch "exec $cmd" comp_output | |
1463 | if {[info exists old_lc_all]} { | |
1464 | set env(LC_ALL) $old_lc_all | |
1465 | } else { | |
1466 | unset env(LC_ALL) | |
1467 | } | |
1468 | set comp_output [prune_warnings $comp_output] | |
1469 | ||
1470 | if ![string match "" $comp_output] then { | |
1471 | send_log "$comp_output\n" | |
1472 | set failed 1 | |
1473 | break | |
1474 | } | |
1475 | ||
1476 | if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then { | |
1477 | verbose "output is [file_contents "dump.out"]" 2 | |
1478 | set failed 1 | |
1479 | break | |
1480 | } | |
1481 | } | |
1482 | } | |
1483 | ||
1484 | if { $failed != 0 } { | |
1485 | fail $testname | |
1486 | } else { if { $is_unresolved == 0 } { | |
1487 | pass $testname | |
1488 | } } | |
1489 | } | |
1490 | ||
1491 | # Catch action errors. | |
1492 | if { $is_unresolved != 0 } { | |
1493 | unresolved $testname | |
1494 | continue | |
1495 | } | |
1496 | } | |
1497 | } | |
430a16a5 NC |
1498 | |
1499 | # Returns true if --gc-sections is supported on the target. | |
1500 | ||
1501 | proc check_gc_sections_available { } { | |
1502 | global gc_sections_available_saved | |
1503 | global ld | |
5a68afcf | 1504 | |
430a16a5 NC |
1505 | if {![info exists gc_sections_available_saved]} { |
1506 | # Some targets don't support gc-sections despite whatever's | |
1507 | # advertised by ld's options. | |
a06ea964 NC |
1508 | if {[istarget aarch64*-*-*] |
1509 | || [istarget arc-*-*] | |
de5c4ae2 AM |
1510 | || [istarget d30v-*-*] |
1511 | || [istarget dlx-*-*] | |
1512 | || [istarget i960-*-*] | |
1513 | || [istarget or32-*-*] | |
1514 | || [istarget pj*-*-*] | |
1515 | || [istarget alpha-*-*] | |
1d5316ab | 1516 | || [istarget hppa*64-*-*] |
de5c4ae2 AM |
1517 | || [istarget i370-*-*] |
1518 | || [istarget i860-*-*] | |
5a7c5e86 | 1519 | || [istarget ia64-*-*] |
de5c4ae2 AM |
1520 | || [istarget mep-*-*] |
1521 | || [istarget mn10200-*-*] | |
b1435da1 | 1522 | || [istarget *-*-cygwin] |
5a7c5e86 | 1523 | || [istarget *-*-mingw*] } { |
430a16a5 NC |
1524 | set gc_sections_available_saved 0 |
1525 | return 0 | |
1526 | } | |
1527 | ||
1528 | # elf2flt uses -q (--emit-relocs), which is incompatible with | |
1529 | # --gc-sections. | |
1530 | if { [board_info target exists ldflags] | |
1531 | && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } { | |
1532 | set gc_sections_available_saved 0 | |
1533 | return 0 | |
1534 | } | |
1535 | ||
430a16a5 | 1536 | # Check if the ld used by gcc supports --gc-sections. |
1d5316ab AM |
1537 | # FIXME: this test is useless since ld --help always says |
1538 | # --gc-sections is available | |
430a16a5 NC |
1539 | set ld_output [remote_exec host $ld "--help"] |
1540 | if { [ string first "--gc-sections" $ld_output ] >= 0 } { | |
1541 | set gc_sections_available_saved 1 | |
1542 | } else { | |
1543 | set gc_sections_available_saved 0 | |
1544 | } | |
1545 | } | |
1546 | return $gc_sections_available_saved | |
1547 | } | |
33aa234e | 1548 | |
1d5316ab AM |
1549 | # Returns true if -shared is supported on the target |
1550 | # Only used and accurate for ELF targets at the moment | |
1551 | ||
1552 | proc check_shared_lib_support { } { | |
1553 | if {![istarget arc-*-*] | |
1554 | && ![istarget avr-*-*] | |
1555 | && ![istarget cr16-*-*] | |
1556 | && ![istarget cris*-*-*] | |
1557 | && ![istarget crx-*-*] | |
1558 | && ![istarget d10v-*-*] | |
1559 | && ![istarget d30v-*-*] | |
1560 | && ![istarget dlx-*-*] | |
cfb8c092 | 1561 | && ![istarget epiphany-*-*] |
1d5316ab AM |
1562 | && ![istarget fr30-*-*] |
1563 | && ![istarget frv-*-*] | |
1564 | && ![istarget h8300-*-*] | |
1565 | && ![istarget i860-*-*] | |
1566 | && ![istarget i960-*-*] | |
1567 | && ![istarget ip2k-*-*] | |
1568 | && ![istarget iq2000-*-*] | |
1569 | && ![istarget lm32-*-*] | |
1570 | && ![istarget m32c-*-*] | |
1571 | && ![istarget m32r-*-*] | |
32d79e68 AM |
1572 | && ![istarget m6811-*-*] |
1573 | && ![istarget m6812-*-*] | |
1d5316ab AM |
1574 | && ![istarget m68hc1*-*-*] |
1575 | && ![istarget mcore*-*-*] | |
1576 | && ![istarget mep-*-*] | |
1577 | && ![istarget microblaze-*-*] | |
1578 | && ![istarget mn10200-*-*] | |
1579 | && ![istarget moxie-*-*] | |
1580 | && ![istarget msp430-*-*] | |
1581 | && ![istarget mt-*-*] | |
1582 | && ![istarget openrisc-*-*] | |
1583 | && ![istarget or32-*-*] | |
1584 | && ![istarget pj-*-*] | |
1585 | && ![istarget rx-*-*] | |
1586 | && ![istarget spu-*-*] | |
1587 | && ![istarget v850*-*-*] | |
1588 | && ![istarget xstormy16-*-*] | |
1589 | && ![istarget *-*-irix*] | |
1590 | && ![istarget *-*-rtems] } { | |
1591 | return 1 | |
1592 | } | |
1593 | return 0 | |
1594 | } | |
1595 | ||
5d3236ee DK |
1596 | # Returns true if the target ld supports the plugin API. |
1597 | proc check_plugin_api_available { } { | |
1598 | global plugin_api_available_saved | |
1599 | global ld | |
1600 | if {![info exists plugin_api_available_saved]} { | |
1601 | # Check if the ld used by gcc supports --plugin. | |
1602 | set ld_output [remote_exec host $ld "--help"] | |
1603 | if { [ string first "-plugin" $ld_output ] >= 0 } { | |
1604 | set plugin_api_available_saved 1 | |
1605 | } else { | |
1606 | set plugin_api_available_saved 0 | |
1607 | } | |
1608 | } | |
1609 | return $plugin_api_available_saved | |
1610 | } | |
1611 | ||
33aa234e JK |
1612 | # Check if the assembler supports CFI statements. |
1613 | ||
1614 | proc check_as_cfi { } { | |
1615 | global check_as_cfi_result | |
1616 | global as | |
1617 | if [info exists check_as_cfi_result] { | |
1618 | return $check_as_cfi_result | |
1619 | } | |
1620 | set as_file "tmpdir/check_as_cfi.s" | |
1621 | set as_fh [open $as_file w 0666] | |
1622 | puts $as_fh "# Generated file. DO NOT EDIT" | |
1623 | puts $as_fh "\t.cfi_startproc" | |
1624 | puts $as_fh "\t.cfi_endproc" | |
1625 | close $as_fh | |
1626 | remote_download host $as_file | |
1627 | verbose -log "Checking CFI support:" | |
1628 | rename "perror" "check_as_cfi_perror" | |
1629 | proc perror { args } { } | |
1630 | set success [ld_assemble $as $as_file "/dev/null"] | |
1631 | rename "perror" "" | |
1632 | rename "check_as_cfi_perror" "perror" | |
1633 | #remote_file host delete $as_file | |
1634 | set check_as_cfi_result $success | |
1635 | return $success | |
1636 | } | |
1637 | ||
1638 | # Provide virtual target "cfi" for targets supporting CFI. | |
1639 | ||
1640 | rename "istarget" "istarget_ld" | |
1641 | proc istarget { target } { | |
1642 | if {$target == "cfi"} { | |
1643 | return [check_as_cfi] | |
1644 | } | |
1645 | return [istarget_ld $target] | |
1646 | } |