Commit | Line | Data |
---|---|---|
219d1afa | 1 | # Copyright (C) 1993-2018 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. | |
26 | if { [istarget m68hc1*-*] || [istarget xgate-*] } { | |
27 | return 1; | |
28 | } | |
29 | ||
4a85cc09 | 30 | if { ![istarget *-*-eabi*] |
f3097f33 | 31 | && ![istarget *-*-elf*] |
4a85cc09 | 32 | && ![istarget *-*-freebsd*] |
f3097f33 | 33 | && ![istarget *-*-gnu*] |
f3097f33 RS |
34 | && ![istarget *-*-irix5*] |
35 | && ![istarget *-*-irix6*] | |
4a85cc09 | 36 | && ![istarget *-*-linux*] |
c43b2c54 | 37 | && ![istarget *-*-lynxos*] |
4a85cc09 | 38 | && ![istarget *-*-nacl*] |
f3097f33 RS |
39 | && ![istarget *-*-netbsd*] |
40 | && ![istarget *-*-openbsd*] | |
4a85cc09 SKS |
41 | && ![istarget *-*-rtems*] |
42 | && ![istarget *-*-solaris2*] | |
c43b2c54 | 43 | && ![istarget *-*-symbianelf*] |
4a85cc09 SKS |
44 | && ![istarget *-*-sysv4*] |
45 | && ![istarget *-*-unixware*] | |
f96bd6c2 | 46 | && ![istarget *-*-wasm32*] |
f1ac0afe | 47 | && ![istarget arm*-*-uclinuxfdpiceabi] |
4a85cc09 SKS |
48 | && ![istarget avr-*-*] |
49 | && ![istarget bfin-*-uclinux] | |
50 | && ![istarget frv-*-uclinux*] | |
51 | && ![istarget hppa*64*-*-hpux*] | |
52 | && ![istarget ia64-*-hpux*] | |
53 | && ![istarget sh*-*-uclinux*] | |
54 | && ![istarget tic6x*-*-uclinux*] } { | |
f3097f33 RS |
55 | return 0 |
56 | } | |
57 | ||
c65c21e1 AM |
58 | if { [istarget *-*-linux*ecoff*] |
59 | || [istarget *-*-rtemscoff*] } { | |
f3097f33 RS |
60 | return 0 |
61 | } | |
62 | ||
63 | if { ![istarget *-*-netbsdelf*] | |
c65c21e1 | 64 | && ( [istarget vax-*-netbsd*] |
f3097f33 RS |
65 | || [istarget ns32k-*-netbsd*]) } { |
66 | return 0 | |
67 | } | |
68 | ||
4a85cc09 | 69 | if { [istarget arm-*-openbsd*] |
f3097f33 | 70 | || [istarget ns32k-*-openbsd*] |
f3097f33 RS |
71 | || [istarget vax-*-openbsd*] } { |
72 | return 0 | |
73 | } | |
74 | ||
75 | return 1 | |
76 | } | |
77 | ||
78 | # True if the object format is known to be a.out. | |
79 | # | |
80 | proc is_aout_format {} { | |
c65c21e1 | 81 | if { [istarget *-*-*aout*] |
f3097f33 RS |
82 | || [istarget *-*-bsd*] |
83 | || [istarget *-*-msdos*] | |
f3097f33 RS |
84 | || [istarget ns32k-*-*] |
85 | || [istarget pdp11-*-*] | |
f3097f33 RS |
86 | || [istarget vax-*-netbsd] } { |
87 | return 1 | |
88 | } | |
89 | return 0 | |
90 | } | |
91 | ||
92 | # True if the object format is known to be PE COFF. | |
93 | # | |
94 | proc is_pecoff_format {} { | |
95 | if { ![istarget *-*-mingw*] | |
96 | && ![istarget *-*-cygwin*] | |
97 | && ![istarget *-*-cegcc*] | |
98 | && ![istarget *-*-pe*] } { | |
99 | return 0 | |
100 | } | |
101 | ||
102 | return 1 | |
103 | } | |
104 | ||
105 | # True if the object format is known to be 64-bit ELF. | |
106 | # | |
107 | proc is_elf64 { binary_file } { | |
108 | global READELF | |
109 | global READELFFLAGS | |
110 | ||
111 | set readelf_size "" | |
112 | catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got | |
113 | ||
114 | if ![string match "" $got] then { | |
115 | return 0 | |
116 | } | |
117 | ||
118 | if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \ | |
119 | [file_contents readelf.out] nil readelf_size] } { | |
120 | return 0 | |
121 | } | |
122 | ||
123 | if { $readelf_size == "64" } { | |
124 | return 1 | |
125 | } | |
126 | ||
127 | return 0 | |
128 | } | |
eb22018c | 129 | |
a43942db MR |
130 | # True if the ELF target supports STB_GNU_UNIQUE with the ELF header's |
131 | # OSABI field set to ELFOSABI_GNU. | |
132 | # | |
133 | # This generally depends on the target OS only, however there are a | |
134 | # number of exceptions for bare metal targets as follows. The MSP430 | |
135 | # and Visium targets set OSABI to ELFOSABI_STANDALONE and cannot | |
136 | # support STB_GNU_UNIQUE. Likewise non-EABI ARM targets set OSABI to | |
137 | # ELFOSABI_ARM, and TI C6X targets to ELFOSABI_C6000_*. Finally | |
a8eb42a8 | 138 | # rather than `bfd_elf_final_link' AM33/2.0, D30V, DLX, and |
a43942db MR |
139 | # picoJava targets use `_bfd_generic_final_link', which does not |
140 | # support STB_GNU_UNIQUE symbol binding causing assertion failures. | |
141 | # | |
142 | proc supports_gnu_unique {} { | |
143 | if { [istarget *-*-gnu*] | |
144 | || [istarget *-*-linux*] | |
145 | || [istarget *-*-nacl*] } { | |
146 | return 1 | |
147 | } | |
148 | if { [istarget "arm*-*-*eabi*"] } { | |
149 | return 1 | |
150 | } | |
f96bd6c2 PC |
151 | if { [istarget "wasm32*-*-*"] } { |
152 | return 1 | |
153 | } | |
a43942db MR |
154 | if { ![istarget "*-*-elf*"] } { |
155 | return 0 | |
156 | } | |
157 | if { [istarget "arm*-*-*"] | |
158 | || [istarget "msp430-*-*"] | |
159 | || [istarget "tic6x-*-*"] | |
160 | || [istarget "visium-*-*"] } { | |
161 | return 0 | |
162 | } | |
163 | if { [istarget "am33_2.0-*-*"] | |
164 | || [istarget "d30v-*-*"] | |
165 | || [istarget "dlx-*-*"] | |
a43942db MR |
166 | || [istarget "pj*-*-*"] } { |
167 | return 0 | |
168 | } | |
169 | return 1 | |
170 | } | |
171 | ||
9cc0123f AM |
172 | # True for targets that do not sort .symtab as per the ELF standard. |
173 | # ie. any that have mips_elf32_be_vec, mips_elf32_le_vec, | |
174 | # mips_elf32_n_be_vec or mips_elf32_n_le_vec as the primary bfd target | |
175 | # vector in config.bfd. When syncing with config.bfd, don't forget that | |
176 | # earlier case-matches trump later ones. | |
177 | proc is_bad_symtab {} { | |
178 | if { ![istarget "mips*-*-*"] } { | |
179 | return 0; | |
180 | } | |
181 | if { [istarget "*-*-chorus*"] | |
182 | || [istarget "*-*-irix5*"] | |
183 | || [istarget "*-*-irix6*"] | |
184 | || [istarget "*-*-none"] | |
185 | || [istarget "*-*-rtems*"] | |
186 | || [istarget "*-*-windiss"] } { | |
187 | return 1; | |
188 | } | |
189 | if { [istarget "*-*-elf*"] | |
190 | && ![istarget "*-sde-*"] | |
191 | && ![istarget "*-mti-*"] | |
192 | && ![istarget "*-img-*"] } { | |
193 | return 1; | |
194 | } | |
195 | if { [istarget "*-*-openbsd*"] | |
196 | && ![istarget "mips64*-*-*"] } { | |
197 | return 1; | |
198 | } | |
199 | return 0; | |
200 | } | |
201 | ||
eb22018c RS |
202 | # Compare two files line-by-line. FILE_1 is the actual output and FILE_2 |
203 | # is the expected output. Ignore blank lines in either file. | |
204 | # | |
205 | # FILE_2 is a series of regexps, comments and # directives. The directives | |
206 | # are: | |
207 | # | |
208 | # #pass | |
209 | # Treat the test as a PASS if everything up till this point has | |
210 | # matched. Ignore any remaining lines in either FILE_1 or FILE_2. | |
211 | # | |
212 | # #failif | |
213 | # Reverse the sense of the test: expect differences to exist. | |
214 | # | |
215 | # #... | |
216 | # REGEXP | |
217 | # Skip all lines in FILE_1 until the first that matches REGEXP. | |
218 | # | |
738f4d98 MR |
219 | # Other # lines are comments. Regexp lines starting with the `!' character |
220 | # specify inverse matching (use `\!' for literal matching against a leading | |
221 | # `!'). Skip empty lines in both files. | |
eb22018c RS |
222 | # |
223 | # The first optional argument is a list of regexp substitutions of the form: | |
224 | # | |
225 | # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ... | |
226 | # | |
227 | # This tells the function to apply each regexp substitution EXPi->SUBSPECi | |
228 | # in order to every line of FILE_2. | |
229 | # | |
230 | # Return nonzero if differences exist. | |
231 | proc regexp_diff { file_1 file_2 args } { | |
232 | set eof -1 | |
233 | set end_1 0 | |
234 | set end_2 0 | |
235 | set differences 0 | |
236 | set diff_pass 0 | |
237 | set fail_if_match 0 | |
238 | set ref_subst "" | |
239 | if { [llength $args] > 0 } { | |
240 | set ref_subst [lindex $args 0] | |
241 | } | |
242 | if { [llength $args] > 1 } { | |
243 | perror "Too many arguments to regexp_diff" | |
244 | return 1 | |
245 | } | |
246 | ||
247 | if [file exists $file_1] then { | |
248 | set file_a [open $file_1 r] | |
249 | } else { | |
250 | perror "$file_1 doesn't exist" | |
251 | return 1 | |
252 | } | |
253 | ||
254 | if [file exists $file_2] then { | |
255 | set file_b [open $file_2 r] | |
256 | } else { | |
257 | perror "$file_2 doesn't exist" | |
258 | close $file_a | |
259 | return 1 | |
260 | } | |
261 | ||
262 | verbose " Regexp-diff'ing: $file_1 $file_2" 2 | |
263 | ||
264 | while { 1 } { | |
265 | set line_a "" | |
266 | set line_b "" | |
267 | while { [string length $line_a] == 0 } { | |
268 | # Ignore blank line in FILE_1. | |
269 | if { [gets $file_a line_a] == $eof } { | |
270 | set end_1 1 | |
271 | break | |
272 | } | |
273 | } | |
274 | while { [string length $line_b] == 0 || [string match "#*" $line_b] } { | |
275 | if { [string match "#pass" $line_b] } { | |
276 | set end_2 1 | |
277 | set diff_pass 1 | |
278 | break | |
279 | } elseif { [string match "#failif" $line_b] } { | |
280 | send_log "fail if no difference\n" | |
281 | verbose "fail if no difference" 3 | |
282 | set fail_if_match 1 | |
283 | } elseif { [string match "#..." $line_b] } { | |
284 | if { [gets $file_b line_b] == $eof } { | |
285 | set end_2 1 | |
286 | set diff_pass 1 | |
287 | break | |
288 | } | |
47a50e5b | 289 | set negated [expr { [string index $line_b 0] == "!" }] |
738f4d98 MR |
290 | set line_bx [string range $line_b $negated end] |
291 | set n [expr { $negated ? "! " : "" }] | |
eb22018c RS |
292 | # Substitute on the reference. |
293 | foreach {name value} $ref_subst { | |
738f4d98 | 294 | regsub -- $name $line_bx $value line_bx |
eb22018c | 295 | } |
738f4d98 MR |
296 | verbose "looking for $n\"^$line_bx$\"" 3 |
297 | while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } { | |
eb22018c RS |
298 | verbose "skipping \"$line_a\"" 3 |
299 | if { [gets $file_a line_a] == $eof } { | |
300 | set end_1 1 | |
301 | break | |
302 | } | |
303 | } | |
304 | break | |
305 | } | |
306 | if { [gets $file_b line_b] == $eof } { | |
307 | set end_2 1 | |
308 | break | |
309 | } | |
310 | } | |
311 | ||
312 | if { $diff_pass } { | |
313 | break | |
314 | } elseif { $end_1 && $end_2 } { | |
315 | break | |
316 | } elseif { $end_1 } { | |
317 | send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n" | |
318 | verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3 | |
319 | set differences 1 | |
320 | break | |
321 | } elseif { $end_2 } { | |
322 | send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" | |
323 | verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3 | |
324 | set differences 1 | |
325 | break | |
326 | } else { | |
47a50e5b | 327 | set negated [expr { [string index $line_b 0] == "!" }] |
738f4d98 MR |
328 | set line_bx [string range $line_b $negated end] |
329 | set n [expr { $negated ? "! " : "" }] | |
330 | set s [expr { $negated ? " " : "" }] | |
eb22018c RS |
331 | # Substitute on the reference. |
332 | foreach {name value} $ref_subst { | |
738f4d98 | 333 | regsub -- $name $line_bx $value line_bx |
eb22018c | 334 | } |
738f4d98 MR |
335 | verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3 |
336 | if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } { | |
eb22018c | 337 | send_log "regexp_diff match failure\n" |
738f4d98 | 338 | send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n" |
eb22018c RS |
339 | verbose "regexp_diff match failure\n" 3 |
340 | set differences 1 | |
341 | } | |
342 | } | |
343 | } | |
344 | ||
345 | if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } { | |
346 | send_log "$file_1 and $file_2 are different lengths\n" | |
347 | verbose "$file_1 and $file_2 are different lengths" 3 | |
348 | set differences 1 | |
349 | } | |
350 | ||
351 | if { $fail_if_match } { | |
352 | if { $differences == 0 } { | |
353 | set differences 1 | |
354 | } else { | |
355 | set differences 0 | |
356 | } | |
357 | } | |
358 | ||
359 | close $file_a | |
360 | close $file_b | |
361 | ||
362 | return $differences | |
363 | } |