1 # Copyright (C) 1993-2018 Free Software Foundation, Inc.
3 # This file is part of the GNU Binutils.
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.
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.
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,
20 # True if the object format is known to be ELF.
22 proc is_elf_format {} {
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.
26 if { [istarget m68hc1*-*] || [istarget s12z*-*] || [istarget xgate-*] } {
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*]
34 if { ![istarget *-*-chorus*]
35 && ![istarget *-*-cloudabi*]
36 && ![istarget *-*-eabi*]
37 && ![istarget *-*-*elf*]
38 && ![istarget *-*-*freebsd*]
39 && ![istarget *-*-fuchsia*]
40 && ![istarget *-*-gnu*]
41 && ![istarget *-*-irix5*]
42 && ![istarget *-*-irix6*]
43 && ![istarget *-*-kaos*]
44 && ![istarget *-*-*linux*]
45 && ![istarget *-*-lynxos*]
46 && ![istarget *-*-nacl*]
47 && ![istarget *-*-netbsd*]
48 && ![istarget *-*-nto*]
49 && ![istarget *-*-openbsd*]
50 && ![istarget *-*-rtems*]
51 && ![istarget *-*-solaris2*]
52 && ![istarget *-*-sysv4*]
53 && ![istarget *-*-unixware*]
54 && ![istarget *-*-wasm32*]
55 && ![istarget avr-*-*]
56 && ![istarget hppa*64*-*-hpux*]
57 && ![istarget ia64-*-hpux*] } {
61 if { [istarget *-*-linux*ecoff*]
62 || [istarget *-*-rtemscoff*] } {
66 if { ![istarget *-*-netbsdelf*]
67 && ( [istarget vax-*-netbsd*]
68 || [istarget ns32k-*-netbsd*]) } {
72 if { [istarget arm-*-openbsd*]
73 || [istarget ns32k-*-openbsd*]
74 || [istarget vax-*-openbsd*] } {
81 # True if the object format is known to be a.out.
83 proc is_aout_format {} {
84 if { [istarget *-*-*aout*]
85 || [istarget *-*-bsd*]
86 || [istarget *-*-msdos*]
87 || [istarget ns32k-*-*]
88 || [istarget pdp11-*-*]
89 || [istarget vax-*-netbsd] } {
95 # True if the object format is known to be PE COFF.
97 proc is_pecoff_format {} {
98 if { ![istarget *-*-mingw*]
99 && ![istarget *-*-cygwin*]
100 && ![istarget *-*-cegcc*]
101 && ![istarget *-*-pe*] } {
108 # True if the object format is known to be 64-bit ELF.
110 proc is_elf64 { binary_file } {
114 set tmpfile [file dirname $binary_file]/readelf.out
116 catch "exec $READELF $READELFFLAGS -h $binary_file > $tmpfile" got
118 if ![string match "" $got] then {
122 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
123 [file_contents $tmpfile] nil readelf_size] } {
127 if { $readelf_size == "64" } {
134 # True if the object format is known to use RELA relocations.
136 proc is_rela { binary_file } {
140 set tmpfile [file dirname $binary_file]/readelf.out
141 catch "exec $READELF $READELFFLAGS -S $binary_file > $tmpfile" got
143 if ![string match "" $got] then {
147 if { ![regexp "RELA" [file_contents $tmpfile]] } {
154 # True if the target matches TARGET, specified as a TCL procedure if
155 # in square brackets or as machine triplet otherwise.
157 proc match_target { target } {
158 if [string match {\[*\]} $target] {
161 return [istarget $target]
165 # True if the ELF target supports STB_GNU_UNIQUE with the ELF header's
166 # OSABI field set to ELFOSABI_GNU.
168 # This generally depends on the target OS only, however there are a
169 # number of exceptions for bare metal targets as follows. The MSP430
170 # and Visium targets set OSABI to ELFOSABI_STANDALONE and cannot
171 # support STB_GNU_UNIQUE. Likewise non-EABI ARM targets set OSABI to
172 # ELFOSABI_ARM, and TI C6X targets to ELFOSABI_C6000_*. Finally
173 # rather than `bfd_elf_final_link' AM33/2.0, D30V, DLX, and
174 # picoJava targets use `_bfd_generic_final_link', which does not
175 # support STB_GNU_UNIQUE symbol binding causing assertion failures.
177 proc supports_gnu_unique {} {
178 if { [istarget *-*-gnu*]
179 || [istarget *-*-linux*]
180 || [istarget *-*-nacl*] } {
183 if { [istarget "arm*-*-*eabi*"] } {
186 if { [istarget "wasm32*-*-*"] } {
189 if { ![istarget "*-*-elf*"] } {
192 if { [istarget "arm*-*-*"]
193 || [istarget "msp430-*-*"]
194 || [istarget "tic6x-*-*"]
195 || [istarget "visium-*-*"] } {
198 if { [istarget "am33_2.0-*-*"]
199 || [istarget "d30v-*-*"]
200 || [istarget "dlx-*-*"]
201 || [istarget "pj*-*-*"]
202 || [istarget "xgate-*-*"] } {
208 # True for targets that do not sort .symtab as per the ELF standard.
209 # ie. any that have mips_elf32_be_vec, mips_elf32_le_vec,
210 # mips_elf32_n_be_vec or mips_elf32_n_le_vec as the primary bfd target
211 # vector in config.bfd. When syncing with config.bfd, don't forget that
212 # earlier case-matches trump later ones.
213 proc is_bad_symtab {} {
214 if { ![istarget "mips*-*-*"] } {
217 if { [istarget "*-*-chorus*"]
218 || [istarget "*-*-irix5*"]
219 || [istarget "*-*-irix6*"]
220 || [istarget "*-*-none"]
221 || [istarget "*-*-rtems*"]
222 || [istarget "*-*-windiss"] } {
225 if { [istarget "*-*-elf*"]
226 && ![istarget "*-sde-*"]
227 && ![istarget "*-mti-*"]
228 && ![istarget "*-img-*"] } {
231 if { [istarget "*-*-openbsd*"]
232 && ![istarget "mips64*-*-*"] } {
238 # Compare two files line-by-line. FILE_1 is the actual output and FILE_2
239 # is the expected output. Ignore blank lines in either file.
241 # FILE_2 is a series of regexps, comments and # directives. The directives
245 # Treat the test as a PASS if everything up till this point has
246 # matched. Ignore any remaining lines in either FILE_1 or FILE_2.
249 # Reverse the sense of the test: expect differences to exist.
253 # Skip all lines in FILE_1 until the first that matches REGEXP.
255 # Other # lines are comments. Regexp lines starting with the `!' character
256 # specify inverse matching (use `\!' for literal matching against a leading
257 # `!'). Skip empty lines in both files.
259 # The first optional argument is a list of regexp substitutions of the form:
261 # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
263 # This tells the function to apply each regexp substitution EXPi->SUBSPECi
264 # in order to every line of FILE_2.
266 # Return nonzero if differences exist.
267 proc regexp_diff { file_1 file_2 args } {
275 if { [llength $args] > 0 } {
276 set ref_subst [lindex $args 0]
278 if { [llength $args] > 1 } {
279 perror "Too many arguments to regexp_diff"
283 if [file exists $file_1] then {
284 set file_a [open $file_1 r]
286 perror "$file_1 doesn't exist"
290 if [file exists $file_2] then {
291 set file_b [open $file_2 r]
293 perror "$file_2 doesn't exist"
298 verbose " Regexp-diff'ing: $file_1 $file_2" 2
303 while { [string length $line_a] == 0 } {
304 # Ignore blank line in FILE_1.
305 if { [gets $file_a line_a] == $eof } {
310 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
311 if { [string match "#pass" $line_b] } {
315 } elseif { [string match "#failif" $line_b] } {
316 send_log "fail if no difference\n"
317 verbose "fail if no difference" 3
319 } elseif { [string match "#..." $line_b] } {
320 if { [gets $file_b line_b] == $eof } {
325 set negated [expr { [string index $line_b 0] == "!" }]
326 set line_bx [string range $line_b $negated end]
327 set n [expr { $negated ? "! " : "" }]
328 # Substitute on the reference.
329 foreach {name value} $ref_subst {
330 regsub -- $name $line_bx $value line_bx
332 verbose "looking for $n\"^$line_bx$\"" 3
333 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
334 verbose "skipping \"$line_a\"" 3
335 if { [gets $file_a line_a] == $eof } {
342 if { [gets $file_b line_b] == $eof } {
350 } elseif { $end_1 && $end_2 } {
352 } elseif { $end_1 } {
353 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
354 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
357 } elseif { $end_2 } {
358 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
359 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
363 set negated [expr { [string index $line_b 0] == "!" }]
364 set line_bx [string range $line_b $negated end]
365 set n [expr { $negated ? "! " : "" }]
366 set s [expr { $negated ? " " : "" }]
367 # Substitute on the reference.
368 foreach {name value} $ref_subst {
369 regsub -- $name $line_bx $value line_bx
371 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
372 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
373 send_log "regexp_diff match failure\n"
374 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
375 verbose "regexp_diff match failure\n" 3
381 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
382 send_log "$file_1 and $file_2 are different lengths\n"
383 verbose "$file_1 and $file_2 are different lengths" 3
387 if { $fail_if_match } {
388 if { $differences == 0 } {
401 # prune_warnings_extra -- delete extra warnings from TEXT.
404 # ld: warning: /lib64/ld-linux-x86-64.so.2: unsupported GNU_PROPERTY_TYPE (5) type : 0xc0010001
405 proc prune_warnings_extra { text } {
407 # Warnings are only pruned from non-experimental code (ie code not
408 # on a release branch). For experimental code we want the warnings
409 # as they indicate that the sources need to be updated to recognise
410 # the new properties.
411 if { "$experimental" == "false" } {
412 # The "\\1" is to try to preserve a "\n" but only if necessary.
413 regsub -all "(^|\n)(\[^\n\]*: warning:\[^\n\]*unsupported GNU_PROPERTY_TYPE\[^\n\]*\n?)+" $text "\\1" text
418 # This definition is taken from an unreleased version of DejaGnu. Once
419 # that version gets released, and has been out in the world for a few
420 # months at least, it may be safe to delete this copy.
421 if ![string length [info proc prune_warnings]] {
423 # prune_warnings -- delete various system verbosities from TEXT
426 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
428 # Sites with particular verbose os's may wish to override this in site.exp.
430 proc prune_warnings { text } {
431 # This is from sun4's. Do it for all machines for now.
432 # The "\\1" is to try to preserve a "\n" but only if necessary.
433 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
434 # It might be tempting to get carried away and delete blank lines, etc.
435 # Just delete *exactly* what we're ask to, and that's it.
436 set text [prune_warnings_extra $text]
439 } elseif { [info procs saved-prune_warnings] == [list] } {
440 rename prune_warnings saved-prune_warnings
441 proc prune_warnings { text } {
442 set text [saved-prune_warnings $text]
443 set text [prune_warnings_extra $text]