Commit | Line | Data |
---|---|---|
82704155 | 1 | # Copyright (C) 1993-2019 Free Software Foundation, Inc. |
f3097f33 RS |
2 | # |
3 | # This file is part of the GNU Binutils. | |
4 | # | |
5 | # This file is free software; you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
7 | # the Free Software Foundation; either version 3 of the License, or | |
8 | # (at your option) any later version. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program; if not, write to the Free Software | |
17 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
18 | # MA 02110-1301, USA. | |
19 | ||
20 | # True if the object format is known to be ELF. | |
21 | # | |
22 | proc is_elf_format {} { | |
b3066ae8 AM |
23 | # config.sub for these targets curiously transforms a target doublet |
24 | # ending in -elf to -none. eg. m68hc12-elf to m68hc12-unknown-none | |
25 | # They are always elf. | |
7b4ae824 | 26 | if { [istarget m68hc1*-*] || [istarget s12z*-*] || [istarget xgate-*] } { |
b3066ae8 AM |
27 | return 1; |
28 | } | |
679ca975 AM |
29 | # vxworks (and windiss) excluded due to number of ELF tests that need |
30 | # modifying to pass on those targets. | |
31 | # && ![istarget *-*-vxworks*] | |
32 | # && ![istarget *-*-windiss*] | |
b3066ae8 | 33 | |
679ca975 AM |
34 | if { ![istarget *-*-chorus*] |
35 | && ![istarget *-*-cloudabi*] | |
36 | && ![istarget *-*-eabi*] | |
37 | && ![istarget *-*-*elf*] | |
38 | && ![istarget *-*-*freebsd*] | |
39 | && ![istarget *-*-fuchsia*] | |
f3097f33 | 40 | && ![istarget *-*-gnu*] |
f3097f33 RS |
41 | && ![istarget *-*-irix5*] |
42 | && ![istarget *-*-irix6*] | |
679ca975 AM |
43 | && ![istarget *-*-kaos*] |
44 | && ![istarget *-*-*linux*] | |
c43b2c54 | 45 | && ![istarget *-*-lynxos*] |
4a85cc09 | 46 | && ![istarget *-*-nacl*] |
f3097f33 | 47 | && ![istarget *-*-netbsd*] |
679ca975 | 48 | && ![istarget *-*-nto*] |
f3097f33 | 49 | && ![istarget *-*-openbsd*] |
4a85cc09 SKS |
50 | && ![istarget *-*-rtems*] |
51 | && ![istarget *-*-solaris2*] | |
52 | && ![istarget *-*-sysv4*] | |
53 | && ![istarget *-*-unixware*] | |
f96bd6c2 | 54 | && ![istarget *-*-wasm32*] |
4a85cc09 | 55 | && ![istarget avr-*-*] |
4a85cc09 | 56 | && ![istarget hppa*64*-*-hpux*] |
679ca975 | 57 | && ![istarget ia64-*-hpux*] } { |
f3097f33 RS |
58 | return 0 |
59 | } | |
60 | ||
c65c21e1 AM |
61 | if { [istarget *-*-linux*ecoff*] |
62 | || [istarget *-*-rtemscoff*] } { | |
f3097f33 RS |
63 | return 0 |
64 | } | |
65 | ||
66 | if { ![istarget *-*-netbsdelf*] | |
c65c21e1 | 67 | && ( [istarget vax-*-netbsd*] |
f3097f33 RS |
68 | || [istarget ns32k-*-netbsd*]) } { |
69 | return 0 | |
70 | } | |
71 | ||
4a85cc09 | 72 | if { [istarget arm-*-openbsd*] |
f3097f33 | 73 | || [istarget ns32k-*-openbsd*] |
f3097f33 RS |
74 | || [istarget vax-*-openbsd*] } { |
75 | return 0 | |
76 | } | |
77 | ||
78 | return 1 | |
79 | } | |
80 | ||
81 | # True if the object format is known to be a.out. | |
82 | # | |
83 | proc is_aout_format {} { | |
c65c21e1 | 84 | if { [istarget *-*-*aout*] |
f3097f33 RS |
85 | || [istarget *-*-bsd*] |
86 | || [istarget *-*-msdos*] | |
f3097f33 RS |
87 | || [istarget ns32k-*-*] |
88 | || [istarget pdp11-*-*] | |
f3097f33 RS |
89 | || [istarget vax-*-netbsd] } { |
90 | return 1 | |
91 | } | |
92 | return 0 | |
93 | } | |
94 | ||
95 | # True if the object format is known to be PE COFF. | |
96 | # | |
97 | proc is_pecoff_format {} { | |
5b537ffc AM |
98 | if { [istarget *-*-beospe*] |
99 | || [istarget *-*-cegcc*] | |
100 | || [istarget *-*-cygwin*] | |
101 | || [istarget *-*-interix*] | |
102 | || [istarget *-*-mingw*] | |
103 | || [istarget *-*-netbsdpe*] | |
104 | || [istarget *-*-pe*] | |
105 | || [istarget *-*-winnt*] } { | |
106 | return 1 | |
f3097f33 | 107 | } |
5b537ffc | 108 | return 0 |
f3097f33 RS |
109 | } |
110 | ||
0b1352e0 AM |
111 | proc is_som_format {} { |
112 | if { ![istarget hppa*-*-*] || [istarget hppa*64*-*-*] } { | |
113 | return 0; | |
114 | } | |
115 | if { [istarget *-*-osf*] \ | |
116 | || [istarget {*-*-h[ip]ux*}] \ | |
117 | || [istarget *-*-mpeix*] \ | |
118 | || [istarget *-*-bsd*] } { | |
119 | return 1; | |
120 | } | |
121 | return 0; | |
122 | } | |
123 | ||
f3097f33 RS |
124 | # True if the object format is known to be 64-bit ELF. |
125 | # | |
126 | proc is_elf64 { binary_file } { | |
127 | global READELF | |
128 | global READELFFLAGS | |
129 | ||
506b86a4 | 130 | set tmpfile [file dirname $binary_file]/readelf.out |
f3097f33 | 131 | set readelf_size "" |
506b86a4 | 132 | catch "exec $READELF $READELFFLAGS -h $binary_file > $tmpfile" got |
f3097f33 RS |
133 | |
134 | if ![string match "" $got] then { | |
135 | return 0 | |
136 | } | |
137 | ||
138 | if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \ | |
506b86a4 | 139 | [file_contents $tmpfile] nil readelf_size] } { |
f3097f33 RS |
140 | return 0 |
141 | } | |
142 | ||
143 | if { $readelf_size == "64" } { | |
144 | return 1 | |
145 | } | |
146 | ||
147 | return 0 | |
148 | } | |
eb22018c | 149 | |
506b86a4 AM |
150 | # True if the object format is known to use RELA relocations. |
151 | # | |
152 | proc is_rela { binary_file } { | |
153 | global READELF | |
154 | global READELFFLAGS | |
155 | ||
156 | set tmpfile [file dirname $binary_file]/readelf.out | |
157 | catch "exec $READELF $READELFFLAGS -S $binary_file > $tmpfile" got | |
158 | ||
159 | if ![string match "" $got] then { | |
160 | return 0 | |
161 | } | |
162 | ||
163 | if { ![regexp "RELA" [file_contents $tmpfile]] } { | |
164 | return 0 | |
165 | } | |
166 | ||
167 | return 1 | |
168 | } | |
169 | ||
6d9dabbb MR |
170 | # True if the target matches TARGET, specified as a TCL procedure if |
171 | # in square brackets or as machine triplet otherwise. | |
172 | # | |
173 | proc match_target { target } { | |
174 | if [string match {\[*\]} $target] { | |
175 | return $target | |
176 | } else { | |
177 | return [istarget $target] | |
178 | } | |
179 | } | |
180 | ||
a43942db MR |
181 | # True if the ELF target supports STB_GNU_UNIQUE with the ELF header's |
182 | # OSABI field set to ELFOSABI_GNU. | |
183 | # | |
184 | # This generally depends on the target OS only, however there are a | |
185 | # number of exceptions for bare metal targets as follows. The MSP430 | |
186 | # and Visium targets set OSABI to ELFOSABI_STANDALONE and cannot | |
187 | # support STB_GNU_UNIQUE. Likewise non-EABI ARM targets set OSABI to | |
188 | # ELFOSABI_ARM, and TI C6X targets to ELFOSABI_C6000_*. Finally | |
6ff185b8 AM |
189 | # rather than `bfd_elf_final_link' a number of targets use |
190 | # `_bfd_generic_final_link', which does not support STB_GNU_UNIQUE | |
191 | # symbol binding causing assertion failures. | |
a43942db MR |
192 | # |
193 | proc supports_gnu_unique {} { | |
194 | if { [istarget *-*-gnu*] | |
195 | || [istarget *-*-linux*] | |
196 | || [istarget *-*-nacl*] } { | |
197 | return 1 | |
198 | } | |
199 | if { [istarget "arm*-*-*eabi*"] } { | |
200 | return 1 | |
201 | } | |
f96bd6c2 PC |
202 | if { [istarget "wasm32*-*-*"] } { |
203 | return 1 | |
204 | } | |
a43942db MR |
205 | if { ![istarget "*-*-elf*"] } { |
206 | return 0 | |
207 | } | |
208 | if { [istarget "arm*-*-*"] | |
209 | || [istarget "msp430-*-*"] | |
210 | || [istarget "tic6x-*-*"] | |
211 | || [istarget "visium-*-*"] } { | |
212 | return 0 | |
213 | } | |
214 | if { [istarget "am33_2.0-*-*"] | |
215 | || [istarget "d30v-*-*"] | |
216 | || [istarget "dlx-*-*"] | |
be570f06 | 217 | || [istarget "pj*-*-*"] |
6ff185b8 | 218 | || [istarget "s12z-*-*"] |
be570f06 | 219 | || [istarget "xgate-*-*"] } { |
a43942db MR |
220 | return 0 |
221 | } | |
222 | return 1 | |
223 | } | |
224 | ||
9cc0123f AM |
225 | # True for targets that do not sort .symtab as per the ELF standard. |
226 | # ie. any that have mips_elf32_be_vec, mips_elf32_le_vec, | |
227 | # mips_elf32_n_be_vec or mips_elf32_n_le_vec as the primary bfd target | |
228 | # vector in config.bfd. When syncing with config.bfd, don't forget that | |
229 | # earlier case-matches trump later ones. | |
230 | proc is_bad_symtab {} { | |
231 | if { ![istarget "mips*-*-*"] } { | |
232 | return 0; | |
233 | } | |
234 | if { [istarget "*-*-chorus*"] | |
235 | || [istarget "*-*-irix5*"] | |
236 | || [istarget "*-*-irix6*"] | |
237 | || [istarget "*-*-none"] | |
238 | || [istarget "*-*-rtems*"] | |
239 | || [istarget "*-*-windiss"] } { | |
240 | return 1; | |
241 | } | |
242 | if { [istarget "*-*-elf*"] | |
243 | && ![istarget "*-sde-*"] | |
244 | && ![istarget "*-mti-*"] | |
245 | && ![istarget "*-img-*"] } { | |
246 | return 1; | |
247 | } | |
248 | if { [istarget "*-*-openbsd*"] | |
249 | && ![istarget "mips64*-*-*"] } { | |
250 | return 1; | |
251 | } | |
252 | return 0; | |
253 | } | |
254 | ||
33ea299c TP |
255 | # Returns true if -shared is supported on the target |
256 | ||
257 | proc check_shared_lib_support { } { | |
258 | global shared_available_saved | |
259 | global ld | |
260 | ||
261 | if {![info exists shared_available_saved]} { | |
262 | set ld_output [remote_exec host $ld "-shared"] | |
263 | if { [ string first "not supported" $ld_output ] >= 0 } { | |
264 | set shared_available_saved 0 | |
265 | } else { | |
266 | set shared_available_saved 1 | |
267 | } | |
268 | } | |
269 | return $shared_available_saved | |
270 | } | |
271 | ||
eb22018c RS |
272 | # Compare two files line-by-line. FILE_1 is the actual output and FILE_2 |
273 | # is the expected output. Ignore blank lines in either file. | |
274 | # | |
275 | # FILE_2 is a series of regexps, comments and # directives. The directives | |
276 | # are: | |
277 | # | |
278 | # #pass | |
279 | # Treat the test as a PASS if everything up till this point has | |
280 | # matched. Ignore any remaining lines in either FILE_1 or FILE_2. | |
281 | # | |
282 | # #failif | |
283 | # Reverse the sense of the test: expect differences to exist. | |
284 | # | |
285 | # #... | |
286 | # REGEXP | |
287 | # Skip all lines in FILE_1 until the first that matches REGEXP. | |
288 | # | |
738f4d98 MR |
289 | # Other # lines are comments. Regexp lines starting with the `!' character |
290 | # specify inverse matching (use `\!' for literal matching against a leading | |
291 | # `!'). Skip empty lines in both files. | |
eb22018c RS |
292 | # |
293 | # The first optional argument is a list of regexp substitutions of the form: | |
294 | # | |
295 | # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ... | |
296 | # | |
297 | # This tells the function to apply each regexp substitution EXPi->SUBSPECi | |
298 | # in order to every line of FILE_2. | |
299 | # | |
300 | # Return nonzero if differences exist. | |
301 | proc regexp_diff { file_1 file_2 args } { | |
302 | set eof -1 | |
303 | set end_1 0 | |
304 | set end_2 0 | |
305 | set differences 0 | |
306 | set diff_pass 0 | |
307 | set fail_if_match 0 | |
308 | set ref_subst "" | |
309 | if { [llength $args] > 0 } { | |
310 | set ref_subst [lindex $args 0] | |
311 | } | |
312 | if { [llength $args] > 1 } { | |
313 | perror "Too many arguments to regexp_diff" | |
314 | return 1 | |
315 | } | |
316 | ||
317 | if [file exists $file_1] then { | |
318 | set file_a [open $file_1 r] | |
319 | } else { | |
320 | perror "$file_1 doesn't exist" | |
321 | return 1 | |
322 | } | |
323 | ||
324 | if [file exists $file_2] then { | |
325 | set file_b [open $file_2 r] | |
326 | } else { | |
327 | perror "$file_2 doesn't exist" | |
328 | close $file_a | |
329 | return 1 | |
330 | } | |
331 | ||
332 | verbose " Regexp-diff'ing: $file_1 $file_2" 2 | |
333 | ||
334 | while { 1 } { | |
335 | set line_a "" | |
336 | set line_b "" | |
337 | while { [string length $line_a] == 0 } { | |
338 | # Ignore blank line in FILE_1. | |
339 | if { [gets $file_a line_a] == $eof } { | |
340 | set end_1 1 | |
341 | break | |
342 | } | |
343 | } | |
344 | while { [string length $line_b] == 0 || [string match "#*" $line_b] } { | |
345 | if { [string match "#pass" $line_b] } { | |
346 | set end_2 1 | |
347 | set diff_pass 1 | |
348 | break | |
349 | } elseif { [string match "#failif" $line_b] } { | |
350 | send_log "fail if no difference\n" | |
351 | verbose "fail if no difference" 3 | |
352 | set fail_if_match 1 | |
353 | } elseif { [string match "#..." $line_b] } { | |
354 | if { [gets $file_b line_b] == $eof } { | |
355 | set end_2 1 | |
356 | set diff_pass 1 | |
357 | break | |
358 | } | |
47a50e5b | 359 | set negated [expr { [string index $line_b 0] == "!" }] |
738f4d98 MR |
360 | set line_bx [string range $line_b $negated end] |
361 | set n [expr { $negated ? "! " : "" }] | |
eb22018c RS |
362 | # Substitute on the reference. |
363 | foreach {name value} $ref_subst { | |
738f4d98 | 364 | regsub -- $name $line_bx $value line_bx |
eb22018c | 365 | } |
738f4d98 MR |
366 | verbose "looking for $n\"^$line_bx$\"" 3 |
367 | while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } { | |
eb22018c RS |
368 | verbose "skipping \"$line_a\"" 3 |
369 | if { [gets $file_a line_a] == $eof } { | |
370 | set end_1 1 | |
371 | break | |
372 | } | |
373 | } | |
374 | break | |
375 | } | |
376 | if { [gets $file_b line_b] == $eof } { | |
377 | set end_2 1 | |
378 | break | |
379 | } | |
380 | } | |
381 | ||
382 | if { $diff_pass } { | |
383 | break | |
384 | } elseif { $end_1 && $end_2 } { | |
385 | break | |
386 | } elseif { $end_1 } { | |
387 | send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n" | |
388 | verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3 | |
389 | set differences 1 | |
390 | break | |
391 | } elseif { $end_2 } { | |
392 | send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" | |
393 | verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3 | |
394 | set differences 1 | |
395 | break | |
396 | } else { | |
47a50e5b | 397 | set negated [expr { [string index $line_b 0] == "!" }] |
738f4d98 MR |
398 | set line_bx [string range $line_b $negated end] |
399 | set n [expr { $negated ? "! " : "" }] | |
400 | set s [expr { $negated ? " " : "" }] | |
eb22018c RS |
401 | # Substitute on the reference. |
402 | foreach {name value} $ref_subst { | |
738f4d98 | 403 | regsub -- $name $line_bx $value line_bx |
eb22018c | 404 | } |
738f4d98 MR |
405 | verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3 |
406 | if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } { | |
eb22018c | 407 | send_log "regexp_diff match failure\n" |
738f4d98 | 408 | send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n" |
eb22018c RS |
409 | verbose "regexp_diff match failure\n" 3 |
410 | set differences 1 | |
411 | } | |
412 | } | |
413 | } | |
414 | ||
415 | if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } { | |
416 | send_log "$file_1 and $file_2 are different lengths\n" | |
417 | verbose "$file_1 and $file_2 are different lengths" 3 | |
418 | set differences 1 | |
419 | } | |
420 | ||
421 | if { $fail_if_match } { | |
422 | if { $differences == 0 } { | |
423 | set differences 1 | |
424 | } else { | |
425 | set differences 0 | |
426 | } | |
427 | } | |
428 | ||
429 | close $file_a | |
430 | close $file_b | |
431 | ||
432 | return $differences | |
433 | } | |
7dd36a6f L |
434 | |
435 | # prune_warnings_extra -- delete extra warnings from TEXT. | |
436 | # | |
437 | # An example is: | |
438 | # ld: warning: /lib64/ld-linux-x86-64.so.2: unsupported GNU_PROPERTY_TYPE (5) type : 0xc0010001 | |
439 | proc prune_warnings_extra { text } { | |
440 | global experimental | |
441 | # Warnings are only pruned from non-experimental code (ie code not | |
442 | # on a release branch). For experimental code we want the warnings | |
443 | # as they indicate that the sources need to be updated to recognise | |
444 | # the new properties. | |
445 | if { "$experimental" == "false" } { | |
446 | # The "\\1" is to try to preserve a "\n" but only if necessary. | |
447 | regsub -all "(^|\n)(\[^\n\]*: warning:\[^\n\]*unsupported GNU_PROPERTY_TYPE\[^\n\]*\n?)+" $text "\\1" text | |
448 | } | |
f92f9e87 L |
449 | # PR binutils/23898: It is OK to have gaps in build notes. |
450 | regsub -all "(^|\n)(\[^\n\]*: Warning: Gap in build notes detected from\[^\n\]*\n?)+" $text "\\1" text | |
7dd36a6f L |
451 | return $text |
452 | } | |
453 | ||
454 | # This definition is taken from an unreleased version of DejaGnu. Once | |
455 | # that version gets released, and has been out in the world for a few | |
456 | # months at least, it may be safe to delete this copy. | |
457 | if ![string length [info proc prune_warnings]] { | |
458 | # | |
459 | # prune_warnings -- delete various system verbosities from TEXT | |
460 | # | |
461 | # An example is: | |
462 | # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9 | |
463 | # | |
464 | # Sites with particular verbose os's may wish to override this in site.exp. | |
465 | # | |
466 | proc prune_warnings { text } { | |
467 | # This is from sun4's. Do it for all machines for now. | |
468 | # The "\\1" is to try to preserve a "\n" but only if necessary. | |
469 | regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text | |
470 | # It might be tempting to get carried away and delete blank lines, etc. | |
471 | # Just delete *exactly* what we're ask to, and that's it. | |
472 | set text [prune_warnings_extra $text] | |
473 | return $text | |
474 | } | |
475 | } elseif { [info procs saved-prune_warnings] == [list] } { | |
476 | rename prune_warnings saved-prune_warnings | |
477 | proc prune_warnings { text } { | |
478 | set text [saved-prune_warnings $text] | |
479 | set text [prune_warnings_extra $text] | |
480 | return $text | |
481 | } | |
482 | } | |
8ffb70eb AM |
483 | |
484 | # run_dump_test FILE (optional:) EXTRA_OPTIONS | |
485 | # | |
486 | # Assemble a .s file, then run some utility on it and check the output. | |
487 | # | |
488 | # There should be an assembly language file named FILE.s in the test | |
489 | # suite directory, and a pattern file called FILE.d. run_dump_test | |
490 | # will assemble FILE.s, optionally run objcopy on the object file, | |
491 | # optionally run ld, optionally run another objcopy, optionally run | |
492 | # another tool under test specified by PROG, then run a dump tool like | |
493 | # addr2line, nm, objdump, readelf or size on the object file to produce | |
494 | # textual output, and then analyze that with regexps. | |
495 | # The FILE.d file specifies what program to run, and what to expect in | |
496 | # its output. | |
497 | # | |
498 | # The FILE.d file begins with zero or more option lines, which specify | |
499 | # flags to pass to the assembler, the program to run to dump the | |
500 | # assembler's output, and the options it wants. The option lines have | |
501 | # the syntax: | |
502 | # | |
503 | # # OPTION: VALUE | |
504 | # | |
505 | # OPTION is the name of some option, like "name" or "objdump", and | |
506 | # VALUE is OPTION's value. The valid options are described below. | |
507 | # Whitespace is ignored everywhere, except within VALUE. The option | |
508 | # list ends with the first line that doesn't match the above syntax. | |
509 | # However, a line within the options that begins with a #, but doesn't | |
510 | # have a recognizable option name followed by a colon, is considered a | |
511 | # comment and entirely ignored. | |
512 | # | |
513 | # The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of | |
514 | # two-element lists. The first element of each is an option name, and | |
515 | # the second additional arguments to be added on to the end of the | |
516 | # option list as given in FILE.d. (If omitted, no additional options | |
517 | # are added.) | |
518 | # | |
519 | # The interesting options are: | |
520 | # | |
521 | # name: TEST-NAME | |
522 | # The name of this test, passed to DejaGNU's `pass' and `fail' | |
523 | # commands. If omitted, this defaults to FILE, the root of the | |
524 | # .s and .d files' names. | |
525 | # | |
526 | # as: FLAGS | |
527 | # When assembling, pass FLAGS to the assembler. | |
528 | # If assembling several files, you can pass different assembler | |
529 | # options in the "source" directives. See below. | |
52d6f3ee MM |
530 | # Multiple instances of this directive tells run_dump_test to run the test |
531 | # multiple times -- one time with each set of flags provided. | |
532 | # Each instance will run exactly as a file with a single "as" line, it is | |
533 | # not possible to condition any behaviour on which set of "as" flags is | |
534 | # used. That means that the "source" specific options are appended to | |
535 | # the "as" flags for their corresponding files, and any extra processing | |
536 | # (e.g. with "ld" and "objcopy") is repeated for each test. | |
8ffb70eb AM |
537 | # |
538 | # ld: FLAGS | |
539 | # Link assembled files using FLAGS, in the order of the "source" | |
540 | # directives, when using multiple files. | |
541 | # | |
542 | # ld_after_inputfiles: FLAGS | |
543 | # Similar to "ld", but put FLAGS after all input files. | |
544 | # | |
545 | # objcopy_objects: FLAGS | |
546 | # Run objcopy with the specified flags after assembling any source | |
547 | # that has the special marker RUN_OBJCOPY in the source specific | |
548 | # flags. | |
549 | # | |
550 | # objcopy_linked_file: FLAGS | |
551 | # Run objcopy on the linked file with the specified flags. | |
552 | # This lets you transform the linked file using objcopy, before the | |
553 | # result is analyzed by an analyzer program specified below. | |
554 | # | |
555 | # PROG: PROGRAM-NAME | |
556 | # The name of a program under test, to run to modify or analyze the | |
557 | # .o file produced by the assembler. Recognised names are: ar, | |
558 | # elfedit, nm, objcopy, ranlib, strings, and strip. | |
559 | # | |
560 | # DUMPPROG: PROGRAM-NAME | |
561 | # The name of the program to run to analyze the file produced | |
562 | # by the assembler or the linker. This can be omitted; | |
563 | # run_dump_test will guess which program to run from which of | |
564 | # the flags options below is present. | |
565 | # | |
566 | # addr2line: FLAGS | |
567 | # nm: FLAGS | |
568 | # objdump: FLAGS | |
569 | # readelf: FLAGS | |
570 | # size: FLAGS | |
571 | # Use the specified program to analyze the output file, and pass it | |
572 | # FLAGS, in addition to the output name. Note that they are run | |
573 | # with LC_ALL=C in the environment to give consistent sorting of | |
574 | # symbols. If no FLAGS are needed then you can use: | |
575 | # DUMPPROG: [nm objdump readelf addr2line] | |
576 | # instead, or just pass a flag that happens to be the default. | |
577 | # If objdump is the dump tool and we're not dumping binary, nor | |
578 | # have run ld, then the standard section names (.text, .data and | |
579 | # .bss) are replaced by target ones if any (eg. rx-elf uses "P" | |
580 | # instead of .text). The substition is done for both the | |
581 | # objdump options (eg: "-j .text" is replaced by "-j P") and the | |
582 | # reference file. | |
583 | # | |
584 | # source: SOURCE [FLAGS] | |
585 | # Assemble the file SOURCE.s using the flags in the "as" directive | |
586 | # and the (optional) FLAGS. If omitted, the source defaults to | |
587 | # FILE.s. | |
588 | # This is useful if several .d files want to share a .s file. | |
589 | # More than one "source" directive can be given, which is useful | |
590 | # when testing linking. | |
591 | # | |
592 | # dump: DUMP | |
593 | # Match against DUMP.d. If omitted, this defaults to FILE.d. This | |
594 | # is useful if several .d files differ by options only. Options are | |
595 | # always read from FILE.d. | |
596 | # | |
597 | # target: GLOB|PROC ... | |
598 | # Run this test only on a specified list of targets. More precisely, | |
599 | # in the space-separated list each glob is passed to "istarget" and | |
600 | # each proc is called as a TCL procedure. List items are interpreted | |
601 | # such that procs are denoted by surrounding square brackets, and any | |
602 | # other items are consired globs. If the call evaluates true for any | |
603 | # of them, the test will be run, otherwise it will be marked | |
604 | # unsupported. | |
605 | # | |
606 | # notarget: GLOB|PROC ... | |
607 | # Do not run this test on a specified list of targets. Again, each | |
608 | # glob in the space-separated list is passed to "istarget" and each | |
609 | # proc is called as a TCL procedure, and the test is run if it | |
610 | # evaluates *false* for *all* of them. Otherwise it will be marked | |
611 | # unsupported. | |
612 | # | |
613 | # alltargets: GLOB|PROC ... | |
614 | # Run this test on a specified list of targets. Again, each | |
615 | # glob in the space-separated list is passed to "istarget" and each | |
616 | # proc is called as a TCL procedure, and the test is run if it | |
617 | # evaluates *true* for *all* of them. Otherwise it will be marked | |
618 | # unsupported. | |
619 | # | |
620 | # skip: GLOB|PROC ... | |
621 | # anyskip: GLOB|PROC ... | |
622 | # noskip: GLOB|PROC ... | |
623 | # These are exactly the same as "notarget", "alltargets" and | |
624 | # "target" respectively, except that they do nothing at all if the | |
625 | # check fails. They should only be used in groups, to construct a | |
626 | # single test which is run on all targets but with variant options | |
627 | # or expected output on some targets. (For example, see | |
628 | # gas/arm/inst.d and gas/arm/wince_inst.d.) | |
629 | # | |
630 | # xfail: GLOB|PROC ... | |
631 | # Run this test and it is is expected to fail on a specified list | |
632 | # of targets. | |
633 | # | |
634 | # error: REGEX | |
635 | # An error with message matching REGEX must be emitted for the test | |
636 | # to pass. The DUMPPROG, addr2line, nm, objdump, readelf and size | |
637 | # options have no meaning and need not supplied if this is present. | |
638 | # Multiple "error" directives append to the expected error message. | |
639 | # | |
640 | # error_output: FILE | |
641 | # Means the same as 'error', except the regular expression lines | |
642 | # are contains in FILE. | |
643 | # | |
644 | # warning: REGEX | |
645 | # Expect a warning matching REGEX. It is an error to issue | |
646 | # both "error" and "warning". Multiple "warning" directives | |
647 | # append to the expected warning message. | |
648 | # | |
649 | # warning_output: FILE | |
650 | # Means the same as 'warning', except the regular expression | |
651 | # lines are contains in FILE. | |
652 | # | |
653 | # map: FILE | |
654 | # Adding this option will cause the linker to generate a linker | |
655 | # map file, using the -Map=MAPFILE command line option. If | |
656 | # there is no -Map=MAPFILE in the 'ld: FLAGS' then one will be | |
657 | # added to the linker command line. The contents of the | |
658 | # generated MAPFILE are then compared against the regexp lines | |
659 | # in FILE using `regexp_diff' (see below for details). | |
660 | # | |
661 | # section_subst: no | |
662 | # Means that the section substitution for objdump is disabled. | |
663 | # | |
664 | # Each option may occur at most once unless otherwise mentioned. | |
665 | # | |
666 | # After the option lines come regexp lines. run_dump_test calls | |
667 | # regexp_diff to compare the output of the dumping tool against the | |
668 | # regexps in FILE.d. | |
669 | # | |
670 | proc run_dump_test { name {extra_options {}} } { | |
671 | global ADDR2LINE ADDR2LINEFLAGS AS ASFLAGS ELFEDIT ELFEDITFLAGS LD LDFLAGS | |
672 | global NM NMFLAGS OBJCOPY OBJCOPYFLAGS OBJDUMP OBJDUMPFLAGS | |
673 | global READELF READELFFLAGS STRIP STRIPFLAGS | |
674 | global copyfile env ld_elf_shared_opt runtests srcdir subdir verbose | |
675 | ||
676 | if [string match "*/*" $name] { | |
677 | set file $name | |
678 | set name [file tail $name] | |
679 | } else { | |
680 | set file "$srcdir/$subdir/$name" | |
681 | } | |
682 | ||
683 | if ![runtest_file_p $runtests $name] then { | |
684 | return | |
685 | } | |
686 | ||
687 | set opt_array [slurp_options "${file}.d"] | |
688 | if { $opt_array == -1 } { | |
689 | perror "error reading options from $file.d" | |
690 | unresolved $subdir/$name | |
691 | return | |
692 | } | |
693 | set dumpfile tmpdir/dump.out | |
694 | set run_ld 0 | |
695 | set run_objcopy 0 | |
696 | set objfile_names {} | |
697 | set opts(PROG) {} | |
698 | set opts(DUMPPROG) {} | |
699 | set opts(addr2line) {} | |
700 | set opts(alltargets) {} | |
701 | set opts(anyskip) {} | |
702 | set opts(ar) {} | |
703 | set opts(as) {} | |
52d6f3ee MM |
704 | set as_final_flags {} |
705 | set as_additional_flags {} | |
8ffb70eb AM |
706 | set opts(dump) {} |
707 | set opts(elfedit) {} | |
708 | set opts(error) {} | |
709 | set opts(error_output) {} | |
710 | set opts(ld) {} | |
711 | set opts(ld_after_inputfiles) {} | |
712 | set opts(map) {} | |
713 | set opts(name) {} | |
714 | set opts(nm) {} | |
715 | set opts(noskip) {} | |
716 | set opts(notarget) {} | |
717 | set opts(objcopy) {} | |
718 | set opts(objcopy_linked_file) {} | |
719 | set opts(objcopy_objects) {} | |
720 | set opts(objdump) {} | |
721 | set opts(ranlib) {} | |
722 | set opts(readelf) {} | |
723 | set opts(section_subst) {} | |
724 | set opts(size) {} | |
725 | set opts(strings) {} | |
726 | set opts(strip) {} | |
727 | set opts(skip) {} | |
728 | set opts(source) {} | |
729 | set opts(strip) {} | |
730 | set opts(target) {} | |
731 | set opts(warning) {} | |
732 | set opts(warning_output) {} | |
733 | set opts(xfail) {} | |
734 | ||
735 | set in_extra 0 | |
736 | foreach i [concat $opt_array {{} {}} $extra_options] { | |
737 | set opt_name [lindex $i 0] | |
738 | set opt_val [lindex $i 1] | |
739 | if { $opt_name == "" } { | |
740 | set in_extra 1 | |
741 | continue | |
742 | } | |
743 | if ![info exists opts($opt_name)] { | |
744 | perror "unknown option $opt_name in file $file.d" | |
745 | unresolved $subdir/$name | |
746 | return | |
747 | } | |
748 | ||
749 | # Allow more substitutions, including tcl functions, for as and ld. | |
750 | # Not done in general because extra quoting is needed for glob | |
751 | # args used for example in binutils-all/remove-relocs-04.d. | |
752 | if { $opt_name == "as" || $opt_name == "ld" } { | |
753 | set opt_val [subst $opt_val] | |
754 | } else { | |
755 | # Just substitute $srcdir and $subdir | |
756 | regsub -all {\$srcdir} "$opt_val" "$srcdir" opt_val | |
757 | regsub -all {\$subdir} "$opt_val" "$subdir" opt_val | |
758 | } | |
759 | ||
760 | switch -- $opt_name { | |
761 | xfail {} | |
762 | target {} | |
763 | alltargets {} | |
764 | notarget {} | |
765 | skip {} | |
766 | anyskip {} | |
767 | noskip {} | |
768 | warning {} | |
769 | error {} | |
770 | source { | |
771 | # Move any source-specific as-flags to a separate list to | |
772 | # simplify processing. | |
773 | if { [llength $opt_val] > 1 } { | |
774 | lappend asflags [lrange $opt_val 1 end] | |
775 | set opt_val [lindex $opt_val 0] | |
776 | } else { | |
777 | lappend asflags {} | |
778 | } | |
779 | ||
780 | # Create the object file name based on nothing but the source | |
781 | # file name. | |
782 | set new_objfile \ | |
783 | [concat tmpdir/[file rootname [file tail [lindex $opt_val 0]]].o] | |
784 | # But, sometimes, we have the exact same source filename in | |
785 | # different directories (foo/src.s bar/src.s) which would lead | |
786 | # us to try and create two src.o files. We detect this | |
787 | # conflict here, and instead create src.o and src1.o. | |
788 | set j 0 | |
789 | while { [lsearch $objfile_names $new_objfile] != -1 } { | |
790 | incr j | |
791 | set new_objfile \ | |
792 | [concat tmpdir/[file rootname [file tail [lindex $opt_val 0]]]${j}.o] | |
793 | } | |
794 | lappend objfile_names $new_objfile | |
795 | } | |
796 | default { | |
52d6f3ee MM |
797 | if { !$in_extra |
798 | && [string length $opts($opt_name)] | |
799 | && $opt_name != "as" } { | |
8ffb70eb AM |
800 | perror "option $opt_name multiply set in $file.d" |
801 | unresolved $subdir/$name | |
802 | return | |
803 | } | |
804 | ||
805 | # A single "#ld:" with no options should do the right thing. | |
806 | if { $opt_name == "ld" } { | |
807 | set run_ld 1 | |
808 | } | |
809 | # Likewise objcopy_linked_file. | |
810 | if { $opt_name == "objcopy_linked_file" } { | |
811 | set run_objcopy 1 | |
812 | } | |
813 | } | |
814 | } | |
815 | ||
816 | # Append differently whether it's a message (without space) or | |
817 | # an option or list (with space). | |
818 | switch -- $opt_name { | |
819 | warning - | |
820 | error { | |
821 | append opts($opt_name) $opt_val | |
822 | } | |
52d6f3ee MM |
823 | as { |
824 | if { $in_extra } { | |
825 | set as_additional_flags [concat $as_additional_flags $opt_val] | |
826 | } else { | |
827 | lappend opts(as) $opt_val | |
828 | } | |
829 | } | |
8ffb70eb AM |
830 | default { |
831 | set opts($opt_name) [concat $opts($opt_name) $opt_val] | |
832 | } | |
833 | } | |
834 | } | |
835 | ||
093f70cc | 836 | # Ensure there is something in $opts(as) for the foreach loop below. |
52d6f3ee MM |
837 | if { [llength $opts(as)] == 0 } { |
838 | set opts(as) [list " "] | |
8ffb70eb | 839 | } |
093f70cc | 840 | foreach x $opts(as) { |
52d6f3ee MM |
841 | if { [string length $x] && [string length $as_additional_flags] } { |
842 | append x " " | |
843 | } | |
844 | append x $as_additional_flags | |
845 | regsub {\[big_or_little_endian\]} $x \ | |
846 | [big_or_little_endian] x | |
093f70cc MM |
847 | lappend as_final_flags $x |
848 | } | |
52d6f3ee MM |
849 | |
850 | regsub {\[big_or_little_endian\]} $opts(ld) \ | |
851 | [big_or_little_endian] opts(ld) | |
8ffb70eb AM |
852 | |
853 | if { $opts(name) == "" } { | |
854 | set testname "$subdir/$name" | |
855 | } else { | |
856 | set testname $opts(name) | |
857 | } | |
858 | ||
859 | set err_warn 0 | |
860 | foreach opt { warning error warning_output error_output } { | |
861 | if { $opts($opt) != "" } { | |
862 | if { $err_warn } { | |
863 | perror "$testname: bad mix of warning and error test directives" | |
864 | unresolved $testname | |
865 | return | |
866 | } | |
867 | set err_warn 1 | |
868 | } | |
869 | } | |
870 | ||
871 | # Decide early whether we should run the test for this target. | |
872 | if { [llength $opts(noskip)] > 0 } { | |
873 | set targmatch 0 | |
874 | foreach targ $opts(noskip) { | |
875 | if [match_target $targ] { | |
876 | set targmatch 1 | |
877 | break | |
878 | } | |
879 | } | |
880 | if { $targmatch == 0 } { | |
881 | return | |
882 | } | |
883 | } | |
884 | foreach targ $opts(anyskip) { | |
885 | if ![match_target $targ] { | |
886 | return | |
887 | } | |
888 | } | |
889 | foreach targ $opts(skip) { | |
890 | if [match_target $targ] { | |
891 | return | |
892 | } | |
893 | } | |
894 | if { [llength $opts(target)] > 0 } { | |
895 | set targmatch 0 | |
896 | foreach targ $opts(target) { | |
897 | if [match_target $targ] { | |
898 | set targmatch 1 | |
899 | break | |
900 | } | |
901 | } | |
902 | if { $targmatch == 0 } { | |
903 | unsupported $testname | |
904 | return | |
905 | } | |
906 | } | |
907 | foreach targ $opts(alltargets) { | |
908 | if ![match_target $targ] { | |
909 | unsupported $testname | |
910 | return | |
911 | } | |
912 | } | |
913 | foreach targ $opts(notarget) { | |
914 | if [match_target $targ] { | |
915 | unsupported $testname | |
916 | return | |
917 | } | |
918 | } | |
919 | ||
920 | set dumpprogram "" | |
921 | # It's meaningless to require an output-testing method when we | |
922 | # expect an error. | |
923 | if { $opts(error) == "" && $opts(error_output) == "" } { | |
924 | if { $opts(DUMPPROG) != "" } { | |
925 | switch -- $opts(DUMPPROG) { | |
926 | addr2line { set dumpprogram addr2line } | |
927 | nm { set dumpprogram nm } | |
928 | objdump { set dumpprogram objdump } | |
929 | readelf { set dumpprogram readelf } | |
930 | size { set dumpprogram size } | |
931 | default { | |
932 | perror "unrecognized DUMPPROG option $opts(DUMPPROG) in $file.d" | |
933 | unresolved $testname | |
934 | return | |
935 | } | |
936 | } | |
937 | } else { | |
938 | # Guess which program to run, by seeing which option was specified. | |
939 | foreach p {addr2line nm objdump readelf size} { | |
940 | if {$opts($p) != ""} { | |
941 | if {$dumpprogram != ""} { | |
942 | perror "ambiguous dump program in $file.d" | |
943 | unresolved $testname | |
944 | return | |
945 | } else { | |
946 | set dumpprogram $p | |
947 | } | |
948 | } | |
949 | } | |
950 | } | |
951 | if { $dumpprogram == "" && $opts(map) == "" && !$err_warn } { | |
952 | perror "dump program unspecified in $file.d" | |
953 | unresolved $testname | |
954 | return | |
955 | } | |
956 | } | |
957 | ||
958 | if { $opts(source) == "" } { | |
959 | set sourcefiles [list ${file}.s] | |
960 | set asflags [list ""] | |
961 | set objfile_names [list tmpdir/[file tail ${file}].o] | |
962 | } else { | |
963 | set sourcefiles {} | |
964 | foreach sf $opts(source) { | |
171b8e19 | 965 | if { [string match "./*" $sf] } { |
8ffb70eb AM |
966 | lappend sourcefiles "$sf" |
967 | } else { | |
968 | lappend sourcefiles "$srcdir/$subdir/$sf" | |
969 | } | |
970 | } | |
971 | } | |
972 | ||
973 | if { $opts(dump) == "" } { | |
974 | set dfile ${file}.d | |
975 | } else { | |
976 | set dfile $srcdir/$subdir/$opts(dump) | |
977 | } | |
978 | ||
979 | # Time to setup xfailures. | |
980 | foreach targ $opts(xfail) { | |
1336939d AM |
981 | if [match_target $targ] { |
982 | setup_xfail "*-*-*" | |
983 | break | |
984 | } | |
8ffb70eb AM |
985 | } |
986 | ||
52d6f3ee MM |
987 | foreach as_flags $as_final_flags { |
988 | # Assemble each file. | |
989 | set objfiles {} | |
990 | for { set i 0 } { $i < [llength $sourcefiles] } { incr i } { | |
991 | set sourcefile [lindex $sourcefiles $i] | |
992 | set sourceasflags [lindex $asflags $i] | |
993 | set run_objcopy_objects 0 | |
994 | ||
995 | if { [string match "*RUN_OBJCOPY*" $sourceasflags] } { | |
996 | set run_objcopy_objects 1 | |
997 | } | |
998 | regsub "RUN_OBJCOPY" $sourceasflags "" sourceasflags | |
999 | ||
1000 | set objfile [lindex $objfile_names $i] | |
1001 | catch "exec rm -f $objfile" exec_output | |
1002 | lappend objfiles $objfile | |
1003 | ||
1004 | if { $as_flags == "binary" } { | |
1005 | while {[file type $sourcefile] eq "link"} { | |
1006 | set newfile [file readlink $sourcefile] | |
1007 | if {[string index $newfile 0] ne "/"} { | |
1008 | set newfile [file dirname $sourcefile]/$newfile | |
1009 | } | |
1010 | set sourcefile $newfile | |
1011 | } | |
1012 | set newfile [remote_download host $sourcefile $objfile] | |
1013 | set cmdret 0 | |
1014 | if { $newfile == "" } { | |
1015 | set cmdret 1 | |
1016 | } | |
1017 | } else { | |
1018 | if { [istarget "hppa*-*-*"] \ | |
1019 | && ![istarget "*-*-linux*"] \ | |
1020 | && ![istarget "*-*-netbsd*" ] } { | |
1021 | set cmd "sed -e 's/^\[ \]*\.comm \\(\[^,\]*\\),\\(.*\\)/\\1 .comm \\2/' < $sourcefile > tmpdir/asm.s" | |
1022 | send_log "$cmd\n" | |
1023 | set cmdret [remote_exec host [concat sh -c [list "$cmd"]]] | |
1024 | set cmdret [lindex $cmdret 0] | |
1025 | if { $cmdret != 0 } { | |
1026 | perror "sed failure" | |
1027 | unresolved $testname | |
1028 | continue | |
1029 | } | |
1030 | set sourcefile tmpdir/asm.s | |
1031 | } | |
1032 | set cmd "$AS $ASFLAGS $as_flags $sourceasflags -o $objfile $sourcefile" | |
1033 | ||
1034 | send_log "$cmd\n" | |
1035 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "dump.tmp"] | |
1036 | remote_upload host "dump.tmp" | |
1037 | set comp_output [prune_warnings [file_contents "dump.tmp"]] | |
1038 | remote_file host delete "dump.tmp" | |
1039 | remote_file build delete "dump.tmp" | |
1040 | set cmdret [lindex $cmdret 0] | |
1041 | } | |
1042 | if { $cmdret == 0 && $run_objcopy_objects } { | |
1043 | set cmd "$OBJCOPY $opts(objcopy_objects) $objfile" | |
1044 | ||
1045 | send_log "$cmd\n" | |
1046 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] \ | |
1047 | "" "/dev/null" "dump.tmp"] | |
1048 | remote_upload host "dump.tmp" | |
1049 | append comp_output [prune_warnings [file_contents "dump.tmp"]] | |
1050 | remote_file host delete "dump.tmp" | |
1051 | remote_file build delete "dump.tmp" | |
1052 | set cmdret [lindex $cmdret 0] | |
1053 | } | |
1054 | } | |
1055 | ||
1056 | # Perhaps link the file(s). | |
1057 | if { $cmdret == 0 && $run_ld } { | |
1058 | set objfile "tmpdir/dump" | |
1059 | catch "exec rm -f $objfile" exec_output | |
1060 | ||
1061 | set ld_extra_opt "" | |
1062 | global ld | |
1063 | set ld "$LD" | |
1064 | if { [is_elf_format] && [check_shared_lib_support] } { | |
1065 | set ld_extra_opt "$ld_elf_shared_opt" | |
1066 | } | |
1067 | ||
1068 | # Add -L$srcdir/$subdir so that the linker command can use | |
1069 | # linker scripts in the source directory. | |
1070 | set cmd "$LD $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \ | |
8ffb70eb AM |
1071 | $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)" |
1072 | ||
52d6f3ee MM |
1073 | # If needed then check for, or add a -Map option. |
1074 | set mapfile "" | |
1075 | if { $opts(map) != "" } then { | |
1076 | if { [regexp -- "-Map=(\[^ \]+)" $cmd all mapfile] } then { | |
1077 | # Found existing mapfile option | |
1078 | verbose -log "Existing mapfile '$mapfile' found" | |
1079 | } else { | |
1080 | # No mapfile option. | |
1081 | set mapfile "tmpdir/dump.map" | |
1082 | verbose -log "Adding mapfile '$mapfile'" | |
1083 | set cmd "$cmd -Map=$mapfile" | |
1084 | } | |
1085 | } | |
1086 | ||
1087 | send_log "$cmd\n" | |
1088 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "dump.tmp"] | |
1089 | remote_upload host "dump.tmp" | |
1090 | append comp_output [file_contents "dump.tmp"] | |
1091 | remote_file host delete "dump.tmp" | |
1092 | remote_file build delete "dump.tmp" | |
1093 | set cmdret [lindex $cmdret 0] | |
1094 | ||
1095 | if { $cmdret == 0 && $run_objcopy } { | |
1096 | set infile $objfile | |
1097 | set objfile "tmpdir/dump1" | |
1098 | remote_file host delete $objfile | |
1099 | ||
1100 | # Note that we don't use OBJCOPYFLAGS here; any flags must be | |
1101 | # explicitly specified. | |
1102 | set cmd "$OBJCOPY $opts(objcopy_linked_file) $infile $objfile" | |
1103 | ||
1104 | send_log "$cmd\n" | |
1105 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "dump.tmp"] | |
1106 | remote_upload host "dump.tmp" | |
1107 | append comp_output [file_contents "dump.tmp"] | |
1108 | remote_file host delete "dump.tmp" | |
1109 | remote_file build delete "dump.tmp" | |
1110 | set cmdret [lindex $cmdret 0] | |
1111 | } | |
1112 | } else { | |
1113 | set objfile [lindex $objfiles 0] | |
1114 | } | |
1115 | ||
1116 | if { $cmdret == 0 && $opts(PROG) != "" } { | |
1117 | set destopt ${copyfile}.o | |
1118 | switch -- $opts(PROG) { | |
1119 | ar { set program ar } | |
1120 | elfedit { | |
1121 | set program elfedit | |
1122 | set destopt "" | |
1123 | } | |
1124 | nm { set program nm } | |
1125 | objcopy { set program objcopy } | |
1126 | ranlib { set program ranlib } | |
1127 | strings { set program strings } | |
1128 | strip { | |
1129 | set program strip | |
1130 | set destopt "-o $destopt" | |
1131 | } | |
1132 | default { | |
1133 | perror "unrecognized PROG option $opts(PROG) in $file.d" | |
1134 | unresolved $testname | |
1135 | continue | |
1136 | } | |
1137 | } | |
1138 | ||
1139 | set progopts1 $opts($program) | |
1140 | eval set progopts \$[string toupper $program]FLAGS | |
1141 | eval set binary \$[string toupper $program] | |
1142 | ||
1143 | if { ![is_remote host] && [which $binary] == 0 } { | |
1144 | untested $testname | |
1145 | continue | |
1146 | } | |
1147 | ||
1148 | verbose "running $binary $progopts $progopts1" 3 | |
1149 | set cmd "$binary $progopts $progopts1 $objfile $destopt" | |
1150 | ||
1151 | # Ensure consistent sorting of symbols | |
1152 | if {[info exists env(LC_ALL)]} { | |
1153 | set old_lc_all $env(LC_ALL) | |
1154 | } | |
1155 | set env(LC_ALL) "C" | |
1156 | send_log "$cmd\n" | |
1157 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>dump.tmp"]] "" "/dev/null"] | |
1158 | set cmdret [lindex $cmdret 0] | |
1159 | remote_upload host "dump.tmp" | |
1160 | append comp_output [prune_warnings [file_contents "dump.tmp"]] | |
1161 | remote_file host delete "dump.tmp" | |
1162 | remote_file build delete "dump.tmp" | |
1163 | if {[info exists old_lc_all]} { | |
1164 | set env(LC_ALL) $old_lc_all | |
1165 | } else { | |
1166 | unset env(LC_ALL) | |
1167 | } | |
1168 | if { $destopt != "" } { | |
1169 | set objfile ${copyfile}.o | |
1170 | } | |
1171 | } | |
1172 | ||
1173 | set want_out(source) "" | |
1174 | set want_out(terminal) 0 | |
1175 | if { $err_warn } { | |
1176 | if { $opts(error) != "" || $opts(error_output) != "" } { | |
1177 | set want_out(terminal) 1 | |
1178 | } | |
1179 | ||
1180 | if { $opts(error) != "" || $opts(warning) != "" } { | |
1181 | set want_out(source) "regex" | |
1182 | if { $opts(error) != "" } { | |
1183 | set want_out(regex) $opts(error) | |
1184 | } else { | |
1185 | set want_out(regex) $opts(warning) | |
1186 | } | |
1187 | } else { | |
1188 | set want_out(source) "file" | |
1189 | if { $opts(error_output) != "" } { | |
1190 | set want_out(file) $opts(error_output) | |
1191 | } else { | |
1192 | set want_out(file) $opts(warning_output) | |
1193 | } | |
1194 | } | |
1195 | } | |
1196 | ||
1197 | regsub "\n$" $comp_output "" comp_output | |
1198 | if { $cmdret != 0 || $comp_output != "" || $want_out(source) != "" } { | |
1199 | set exitstat "succeeded" | |
1200 | if { $cmdret != 0 } { set exitstat "failed" } | |
1201 | ||
1202 | if { $want_out(source) == "regex" } { | |
1203 | verbose -log "$exitstat with: <$comp_output>, expected: <$want_out(regex)>" | |
1204 | } elseif { $want_out(source) == "file" } { | |
1205 | verbose -log "$exitstat with: <$comp_output>, expected in file $want_out(file)" | |
1206 | set_file_contents "tmpdir/ld.messages" "$comp_output" | |
1207 | } else { | |
1208 | verbose -log "$exitstat with: <$comp_output>, no expected output" | |
1209 | } | |
1210 | ||
1211 | if { (($want_out(source) == "") == ($comp_output == "")) \ | |
1212 | && (($cmdret == 0) == ($want_out(terminal) == 0)) \ | |
1213 | && ((($want_out(source) == "regex") \ | |
1214 | && [regexp -- $want_out(regex) $comp_output]) \ | |
1215 | || (($want_out(source) == "file") \ | |
1216 | && (![regexp_diff "tmpdir/ld.messages" "$srcdir/$subdir/$want_out(file)"]))) } { | |
1217 | # We have the expected output. | |
1218 | if { $want_out(terminal) || $dumpprogram == "" } { | |
1219 | pass $testname | |
1220 | continue | |
1221 | } | |
1222 | } else { | |
1223 | fail $testname | |
1224 | continue | |
1225 | } | |
1226 | } | |
1227 | ||
1228 | # We must not have expected failure if we get here. | |
1229 | if { $opts(error) != "" } { | |
1230 | fail $testname | |
1231 | continue | |
1232 | } | |
1233 | ||
1234 | if { $opts(map) != "" } then { | |
1235 | # Check the map file matches. | |
1236 | set map_pattern_file $srcdir/$subdir/$opts(map) | |
1237 | verbose -log "Compare '$mapfile' against '$map_pattern_file'" | |
1238 | if { [regexp_diff $mapfile $map_pattern_file] } then { | |
1239 | fail "$testname (map file check)" | |
1240 | } else { | |
1241 | pass "$testname (map file check)" | |
1242 | } | |
1243 | ||
1244 | if { $dumpprogram == "" } then { | |
1245 | continue | |
1246 | } | |
1247 | } | |
1248 | ||
1249 | set progopts1 $opts($dumpprogram) | |
1250 | eval set progopts \$[string toupper $dumpprogram]FLAGS | |
1251 | eval set binary \$[string toupper $dumpprogram] | |
1252 | ||
1253 | if { ![is_remote host] && [which $binary] == 0 } { | |
1254 | untested $testname | |
1255 | continue | |
1256 | } | |
1257 | ||
1258 | # For objdump of gas output, automatically translate standard section names | |
1259 | set sect_names "" | |
1260 | if { !$run_ld && $dumpprogram == "objdump" \ | |
1261 | && $opts(section_subst) != "no" \ | |
1262 | && ![string match "*-b binary*" $progopts1] } { | |
1263 | set sect_names [get_standard_section_names] | |
1264 | if { $sect_names != ""} { | |
1265 | regsub -- "\\.text" $progopts1 "[lindex $sect_names 0]" progopts1 | |
1266 | regsub -- "\\.data" $progopts1 "[lindex $sect_names 1]" progopts1 | |
1267 | regsub -- "\\.bss" $progopts1 "[lindex $sect_names 2]" progopts1 | |
1268 | } | |
1269 | } | |
1270 | ||
1271 | if { $progopts1 == "" } { set $progopts1 "-r" } | |
1272 | verbose "running $binary $progopts $progopts1" 3 | |
1273 | ||
1274 | set cmd "$binary $progopts $progopts1 $objfile > $dumpfile" | |
1275 | ||
1276 | # Ensure consistent sorting of symbols | |
1277 | if {[info exists env(LC_ALL)]} { | |
1278 | set old_lc_all $env(LC_ALL) | |
1279 | } | |
1280 | set env(LC_ALL) "C" | |
1281 | send_log "$cmd\n" | |
1282 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>dump.tmp"]] "" "/dev/null"] | |
1283 | set cmdret [lindex $cmdret 0] | |
1284 | remote_upload host "dump.tmp" | |
1285 | set comp_output [prune_warnings [file_contents "dump.tmp"]] | |
1286 | remote_file host delete "dump.tmp" | |
1287 | remote_file build delete "dump.tmp" | |
1288 | if {[info exists old_lc_all]} { | |
1289 | set env(LC_ALL) $old_lc_all | |
1290 | } else { | |
1291 | unset env(LC_ALL) | |
1292 | } | |
1293 | if { $cmdret != 0 || $comp_output != "" } { | |
1294 | send_log "exited abnormally with $cmdret, output:$comp_output\n" | |
1295 | fail $testname | |
1296 | continue | |
1297 | } | |
1298 | ||
1299 | if { $verbose > 2 } then { verbose "output is [file_contents $dumpfile]" 3 } | |
1300 | ||
1301 | # Create the substition list for objdump output. | |
1302 | set regexp_subst "" | |
1303 | if { $sect_names != "" } { | |
1304 | set regexp_subst [list "\\\\?\\.text" [lindex $sect_names 0] \ | |
1305 | "\\\\?\\.data" [lindex $sect_names 1] \ | |
1306 | "\\\\?\\.bss" [lindex $sect_names 2] ] | |
1307 | } | |
1308 | ||
1309 | if { [regexp_diff $dumpfile "${dfile}" $regexp_subst] } then { | |
1310 | fail $testname | |
1311 | if { $verbose == 2 } then { verbose "output is [file_contents $dumpfile]" 2 } | |
1312 | continue | |
1313 | } | |
1314 | ||
1315 | pass $testname | |
8ffb70eb | 1316 | } |
8ffb70eb AM |
1317 | } |
1318 | ||
1319 | proc slurp_options { file } { | |
1320 | # If options_regsub(foo) is set to {a b}, then the contents of a | |
1321 | # "#foo:" line will have regsub -all applied to replace a with b. | |
1322 | global options_regsub | |
1323 | ||
1324 | if [catch { set f [open $file r] } x] { | |
1325 | #perror "couldn't open `$file': $x" | |
1326 | perror "$x" | |
1327 | return -1 | |
1328 | } | |
1329 | set opt_array {} | |
1330 | # whitespace expression | |
1331 | set ws {[ ]*} | |
1332 | set nws {[^ ]*} | |
1333 | # whitespace is ignored anywhere except within the options list; | |
1334 | # option names are alphanumeric plus underscore. | |
1335 | set pat "^#${ws}(\[a-zA-Z0-9_\]*)$ws:${ws}(.*)$ws\$" | |
1336 | while { [gets $f line] != -1 } { | |
1337 | set line [string trim $line] | |
1338 | # Whitespace here is space-tab. | |
1339 | if [regexp $pat $line xxx opt_name opt_val] { | |
1340 | # match! | |
1341 | if [info exists options_regsub($opt_name)] { | |
1342 | set subst $options_regsub($opt_name) | |
1343 | regsub -all -- [lindex $subst 0] $opt_val [lindex $subst 1] \ | |
1344 | opt_val | |
1345 | } | |
1346 | lappend opt_array [list $opt_name $opt_val] | |
1347 | } elseif {![regexp "^#" $line ]} { | |
1348 | break | |
1349 | } | |
1350 | } | |
1351 | close $f | |
1352 | return $opt_array | |
1353 | } | |
1354 | ||
1355 | proc file_contents { filename } { | |
1356 | set file [open $filename r] | |
1357 | set contents [read $file] | |
1358 | close $file | |
1359 | return $contents | |
1360 | } | |
1361 | ||
1362 | proc set_file_contents { filename contents } { | |
1363 | set file [open $filename w] | |
1364 | puts $file "$contents" | |
1365 | close $file | |
1366 | } | |
1367 | ||
1368 | # Look for big-endian or little-endian switches in the multlib | |
1369 | # options and translate these into a -EB or -EL switch. Note | |
1370 | # we cannot rely upon proc process_multilib_options to do this | |
1371 | # for us because for some targets the compiler does not support | |
1372 | # -EB/-EL but it does support -mbig-endian/-mlittle-endian, and | |
1373 | # the site.exp file will include the switch "-mbig-endian" | |
1374 | # (rather than "big-endian") which is not detected by proc | |
1375 | # process_multilib_options. | |
1376 | # | |
1377 | proc big_or_little_endian {} { | |
1378 | ||
1379 | if [board_info [target_info name] exists multilib_flags] { | |
1380 | set tmp_flags " [board_info [target_info name] multilib_flags]" | |
1381 | ||
1382 | foreach x $tmp_flags { | |
1383 | case $x in { | |
1384 | {*big*endian eb EB -eb -EB -mb -meb} { | |
1385 | set flags " -EB" | |
1386 | return $flags | |
1387 | } | |
1388 | {*little*endian el EL -el -EL -ml -mel} { | |
1389 | set flags " -EL" | |
1390 | return $flags | |
1391 | } | |
1392 | } | |
1393 | } | |
1394 | } | |
1395 | ||
1396 | set flags "" | |
1397 | return $flags | |
1398 | } | |
1399 | ||
1400 | # Internal procedure: return the names of the standard sections | |
1401 | # | |
1402 | proc get_standard_section_names {} { | |
8d3c78e4 | 1403 | if [istarget "rx-*-elf"] { |
8ffb70eb AM |
1404 | return { "P" "D_1" "B_1" } |
1405 | } | |
0b1352e0 AM |
1406 | if { [istarget "alpha*-*-*vms*"] || [is_som_format] } { |
1407 | return { {\$CODE\$} {\$DATA\$} {\$BSS\$} } | |
8ffb70eb AM |
1408 | } |
1409 | return | |
1410 | } |