]>
Commit | Line | Data |
---|---|---|
219d1afa | 1 | # Copyright (C) 1994-2018 Free Software Foundation, Inc. |
252b5132 RH |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
32866df7 | 5 | # the Free Software Foundation; either version 3 of the License, or |
252b5132 | 6 | # (at your option) any later version. |
21c40443 | 7 | # |
252b5132 RH |
8 | # This program is distributed in the hope that it will be useful, |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
21c40443 | 12 | # |
252b5132 RH |
13 | # You should have received a copy of the GNU General Public License |
14 | # along with this program; if not, write to the Free Software | |
b43b5d5f | 15 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
252b5132 RH |
16 | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-dejagnu@prep.ai.mit.edu | |
19 | ||
20 | # Written by Ian Lance Taylor <ian@cygnus.com> | |
21 | ||
22 | if ![is_remote host] { | |
23 | if {[which $OBJCOPY] == 0} then { | |
24 | perror "$OBJCOPY does not exist" | |
25 | return | |
26 | } | |
27 | } | |
28 | ||
29 | send_user "Version [binutil_version $OBJCOPY]" | |
30 | ||
252b5132 | 31 | if ![is_remote host] { |
8d263650 BE |
32 | set tempfile tmpdir/bintest.o |
33 | set copyfile tmpdir/copy | |
252b5132 RH |
34 | } else { |
35 | set tempfile [remote_download host tmpdir/bintest.o] | |
36 | set copyfile copy | |
37 | } | |
38 | ||
39 | # Test that objcopy does not modify a file when copying it. | |
40 | ||
64bb95af L |
41 | proc objcopy_test {testname srcfile} { |
42 | global OBJCOPY | |
43 | global OBJCOPYFLAGS | |
44 | global srcdir | |
45 | global subdir | |
46 | global tempfile | |
47 | global copyfile | |
252b5132 | 48 | |
96037eb0 | 49 | if {![binutils_assemble $srcdir/$subdir/${srcfile} $tempfile]} then { |
64bb95af | 50 | unresolved "objcopy ($testname)" |
96037eb0 | 51 | remote_file host delete $tempfile |
64bb95af | 52 | return |
252b5132 | 53 | } |
252b5132 | 54 | |
64bb95af L |
55 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS $tempfile ${copyfile}.o"] |
56 | ||
21c40443 | 57 | if ![string equal "" $got] then { |
64bb95af | 58 | fail "objcopy ($testname)" |
252b5132 | 59 | } else { |
64bb95af L |
60 | send_log "cmp $tempfile ${copyfile}.o\n" |
61 | verbose "cmp $tempfile ${copyfile}.o" | |
62 | if [is_remote host] { | |
63 | set src1 tmpdir/bintest.o | |
64 | set src2 tmpdir/copy.o | |
65 | remote_upload host $tempfile $src1 | |
66 | remote_upload host ${copyfile}.o $src2 | |
67 | } else { | |
68 | set src1 ${tempfile} | |
69 | set src2 ${copyfile}.o | |
70 | } | |
71 | set status [remote_exec build cmp "${src1} ${src2}"] | |
72 | set exec_output [lindex $status 1] | |
73 | set exec_output [prune_warnings $exec_output] | |
74 | ||
75 | # On some systems the result of objcopy will not be identical. | |
76 | # Usually this is just because gas isn't using bfd to write the | |
77 | # files in the first place, and may order things a little | |
78 | # differently. Those systems should use setup_xfail here. | |
79 | ||
64bb95af | 80 | setup_xfail "hppa*-*-*" |
64bb95af L |
81 | setup_xfail "m68*-*-*coff" "m68*-*-hpux*" "m68*-*-lynxos*" |
82 | setup_xfail "m68*-*-sysv*" "m68*-apple-aux*" | |
83 | setup_xfail "m8*-*" | |
b0a0c50a | 84 | setup_xfail "sh-*-coff*" |
a9a4b302 | 85 | setup_xfail "tic80-*-*" |
64bb95af L |
86 | |
87 | clear_xfail "hppa*64*-*-hpux*" "hppa*-*-linux*" "hppa*-*-lites*" | |
88 | clear_xfail "hppa*-*-*n*bsd*" "hppa*-*-rtems*" "*-*-*elf*" | |
89 | clear_xfail "m68*-*-sysv4*" | |
90 | ||
21c40443 | 91 | if [string equal "" $exec_output] then { |
64bb95af L |
92 | pass "objcopy ($testname)" |
93 | } else { | |
94 | send_log "$exec_output\n" | |
95 | verbose "$exec_output" 1 | |
252b5132 | 96 | |
64bb95af L |
97 | # On OSF/1, this succeeds with gas and fails with /bin/as. |
98 | setup_xfail "alpha*-*-osf*" | |
252b5132 | 99 | |
64bb95af L |
100 | fail "objcopy ($testname)" |
101 | } | |
252b5132 RH |
102 | } |
103 | } | |
104 | ||
64bb95af L |
105 | objcopy_test "simple copy" bintest.s |
106 | ||
96037eb0 NC |
107 | if { [file exists $tempfile] } { |
108 | # Test reversing bytes in a section. | |
9e48b4c6 | 109 | |
96037eb0 NC |
110 | set reversed ${tempfile}-reversed |
111 | set sect_names [get_standard_section_names] | |
112 | if { $sect_names != "" } { | |
113 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -j [lindex $sect_names 1] --reverse-bytes=4 $tempfile $reversed"] | |
114 | } else { | |
115 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -j .data --reverse-bytes=4 $tempfile $reversed"] | |
9e48b4c6 NC |
116 | } |
117 | ||
96037eb0 NC |
118 | if ![string equal "" $got] then { |
119 | fail "objcopy --reverse-bytes" | |
120 | } else { | |
121 | if [is_remote host] { | |
122 | remote_upload host ${reversed} tmpdir/copy-reversed.o | |
123 | set reversed tmpdir/copy-reversed.o | |
124 | } | |
9e48b4c6 | 125 | |
96037eb0 NC |
126 | set origdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $tempfile"] |
127 | set revdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $reversed"] | |
9e48b4c6 | 128 | |
96037eb0 NC |
129 | set want "^ \[0-9\]+ (\[0-9\]+)" |
130 | set found_orig [regexp -lineanchor $want $origdata -> origdata] | |
131 | set found_rev [regexp -lineanchor $want $revdata -> revdata] | |
8941d5e8 | 132 | |
96037eb0 NC |
133 | if {$found_orig == 0 || $found_rev == 0} then { |
134 | # som doesn't have a .data section | |
135 | setup_xfail "hppa*-*-hpux*" | |
136 | clear_xfail "hppa*64*-*-hpux*" | |
9e48b4c6 | 137 | |
96037eb0 NC |
138 | fail "objcopy --reverse-bytes" |
139 | } else { | |
140 | scan $origdata "%2x%2x%2x%2x" b1 b2 b3 b4 | |
141 | scan $revdata "%2x%2x%2x%2x" c4 c3 c2 c1 | |
142 | ||
143 | if {$b1 == $c1 && $b2 == $c2 && $b3 == $c3 && $b4 == $c4} then { | |
144 | pass "objcopy --reverse-bytes" | |
145 | } else { | |
146 | fail "objcopy --reverse-bytes" | |
147 | } | |
148 | } | |
9e48b4c6 NC |
149 | } |
150 | } | |
151 | ||
b7dd81f7 NC |
152 | # Test interleaved copy of multiple byte width |
153 | ||
154 | set sequence_file sequence_file | |
155 | set file [open ${sequence_file} w] | |
156 | puts ${file} "12345678" | |
157 | close ${file} | |
158 | ||
159 | if [is_remote host] { | |
160 | remote_upload host ${sequence_file} tmpdir/sequence_file | |
161 | set sequence_file tmpdir/sequence_file | |
162 | } | |
163 | ||
164 | set got [binutils_run $OBJCOPY "-I binary -i 4 -b 0 --interleave-width 2 ${sequence_file} ${copyfile}"] | |
165 | ||
21c40443 | 166 | if ![string equal "" $got] then { |
b7dd81f7 NC |
167 | fail "objcopy -i --interleave-width" |
168 | } else { | |
169 | if [is_remote host] { | |
170 | remote_upload host ${copyfile} tmpdir/interleave_output | |
171 | set interleave_output tmpdir/interleave_output | |
172 | } else { | |
173 | set interleave_output ${copyfile} | |
174 | } | |
175 | ||
176 | set file [open ${interleave_output} r] | |
177 | gets $file line | |
178 | send_log "$line\n" | |
179 | verbose $line | |
180 | ||
21c40443 | 181 | if ![string equal "1256" $line] then { |
b7dd81f7 NC |
182 | fail "objcopy -i --interleave-width" |
183 | } | |
184 | pass "objcopy -i --interleave-width" | |
185 | ||
186 | close $file | |
187 | } | |
188 | ||
252b5132 RH |
189 | # Test generating S records. |
190 | ||
96037eb0 NC |
191 | if { [file exists $tempfile] } { |
192 | # We make the srec filename 8.3 compatible. Note that the header string | |
193 | # matched against depends on the name of the file. Ugh. | |
252b5132 | 194 | |
252b5132 | 195 | if [is_remote host] { |
96037eb0 NC |
196 | set srecfile copy.sre |
197 | set header_string S00B0000636F70792E737265C1 | |
198 | } else { | |
199 | set srecfile ${copyfile}.srec | |
200 | set header_string S0130000746D706469722F636F70792E7372656397 | |
252b5132 | 201 | } |
252b5132 | 202 | |
96037eb0 NC |
203 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"] |
204 | ||
205 | if ![string equal "" $got] then { | |
252b5132 RH |
206 | fail "objcopy -O srec" |
207 | } else { | |
96037eb0 NC |
208 | if [is_remote host] { |
209 | remote_upload host ${srecfile} tmpdir/copy.srec | |
210 | set srecfile tmpdir/copy.srec | |
252b5132 | 211 | } |
96037eb0 NC |
212 | set file [open ${srecfile} r] |
213 | ||
214 | # The first S record is fixed by the file name we are using. | |
215 | gets $file line | |
252b5132 RH |
216 | send_log "$line\n" |
217 | verbose $line | |
96037eb0 NC |
218 | if ![regexp "$header_string.*" $line] { |
219 | send_log "bad header\n" | |
252b5132 RH |
220 | fail "objcopy -O srec" |
221 | } else { | |
96037eb0 NC |
222 | while {[gets $file line] != -1 \ |
223 | && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} { | |
252b5132 RH |
224 | send_log "$line\n" |
225 | verbose $line | |
96037eb0 NC |
226 | set line "**EOF**" |
227 | } | |
228 | send_log "$line\n" | |
229 | verbose $line | |
230 | if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then { | |
231 | send_log "bad trailer\n" | |
252b5132 RH |
232 | fail "objcopy -O srec" |
233 | } else { | |
96037eb0 NC |
234 | if {[gets $file line] != -1} then { |
235 | send_log "garbage at end\n" | |
236 | send_log "$line\n" | |
237 | verbose $line | |
252b5132 RH |
238 | fail "objcopy -O srec" |
239 | } else { | |
96037eb0 NC |
240 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${srecfile}"] |
241 | if ![regexp "file format srec" $got] then { | |
242 | send_log "objdump failed\n" | |
243 | fail "objcopy -O srec" | |
244 | } else { | |
245 | pass "objcopy -O srec" | |
246 | } | |
252b5132 RH |
247 | } |
248 | } | |
249 | } | |
252b5132 | 250 | |
96037eb0 NC |
251 | close $file |
252 | } | |
252b5132 RH |
253 | } |
254 | ||
255 | # Test setting and adjusting the start address. We only test this | |
256 | # while generating S records, because we may not be able to set the | |
257 | # start address for other object file formats, and the S record case | |
258 | # is the only useful one anyhow. | |
259 | ||
260 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $tempfile"] | |
261 | if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then { | |
262 | perror "objdump can not recognize bintest.o" | |
263 | set origstart "" | |
264 | } else { | |
627fe3fb | 265 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --set-start 0x7654 $tempfile ${copyfile}.srec"] |
21c40443 | 266 | if ![string equal "" $got] then { |
252b5132 RH |
267 | fail "objcopy --set-start" |
268 | } else { | |
269 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] | |
270 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { | |
271 | fail "objcopy --set-start" | |
272 | } else { | |
273 | if {$srecstart != 0x7654} then { | |
274 | send_log "$srecstart != 0x7654\n" | |
275 | fail "objcopy --set-start" | |
276 | } else { | |
277 | pass "objcopy --set-start" | |
278 | } | |
279 | } | |
280 | } | |
281 | ||
627fe3fb | 282 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-start 0x123 $tempfile ${copyfile}.srec"] |
21c40443 | 283 | if ![string equal "" $got] then { |
252b5132 RH |
284 | fail "objcopy --adjust-start" |
285 | } else { | |
286 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] | |
287 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { | |
288 | fail "objcopy --adjust-start" | |
289 | } else { | |
290 | if {$srecstart != $origstart + 0x123} then { | |
291 | send_log "$srecstart != $origstart + 0x123\n" | |
292 | fail "objcopy --adjust-start" | |
293 | } else { | |
294 | pass "objcopy --adjust-start" | |
295 | } | |
296 | } | |
297 | } | |
298 | } | |
299 | ||
300 | # Test adjusting the overall VMA, and adjusting the VMA of a | |
301 | # particular section. We again only test this when generating S | |
302 | # records. | |
303 | ||
304 | set low "" | |
305 | set lowname "" | |
306 | ||
307 | set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $tempfile"] | |
308 | ||
309 | set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)" | |
310 | ||
311 | set got $headers | |
312 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
313 | set vma 0x$vma | |
314 | set size 0x$size | |
315 | if {$size != 0} { | |
316 | if {$low == "" || $vma < $low} { | |
317 | set low $vma | |
318 | set lowname $name | |
319 | } | |
320 | } | |
321 | set got $rest | |
322 | } | |
323 | ||
324 | if {$low == "" || $origstart == ""} then { | |
325 | perror "objdump can not recognize bintest.o" | |
326 | } else { | |
627fe3fb | 327 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-vma 0x123 $tempfile ${copyfile}.srec"] |
21c40443 | 328 | if ![string equal "" $got] then { |
252b5132 RH |
329 | fail "objcopy --adjust-vma" |
330 | } else { | |
331 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"] | |
332 | set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" | |
333 | if ![regexp $want $got all start vma] then { | |
334 | fail "objcopy --adjust-vma" | |
335 | } else { | |
336 | set vma 0x$vma | |
337 | if {$vma != $low + 0x123} then { | |
338 | send_log "$vma != $low + 0x123\n" | |
339 | fail "objcopy --adjust-vma" | |
340 | } else { | |
341 | if {$start != $origstart + 0x123} then { | |
342 | send_log "$start != $origstart + 0x123\n" | |
343 | fail "objcopy --adjust-vma" | |
344 | } else { | |
345 | pass "objcopy --adjust-vma" | |
346 | } | |
347 | } | |
348 | } | |
349 | } | |
350 | ||
351 | set arg "" | |
352 | set got $headers | |
353 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
354 | set vma 0x$vma | |
355 | if {$vma == $low} then { | |
356 | set arg "$arg --adjust-section-vma $name+4" | |
357 | } | |
358 | set got $rest | |
359 | } | |
360 | ||
627fe3fb | 361 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $arg $tempfile ${copyfile}.srec"] |
21c40443 | 362 | if ![string equal "" $got] then { |
252b5132 RH |
363 | fail "objcopy --adjust-section-vma +" |
364 | } else { | |
365 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"] | |
366 | set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" | |
367 | if ![regexp $want $got all vma] then { | |
368 | fail "objcopy --adjust-section-vma +" | |
369 | } else { | |
370 | set vma 0x$vma | |
371 | if {$vma != $low + 4} then { | |
372 | send_log "$vma != $low + 4\n" | |
373 | fail "objcopy --adjust-section-vma +" | |
374 | } else { | |
375 | pass "objcopy --adjust-section-vma +" | |
376 | } | |
377 | } | |
378 | } | |
379 | ||
380 | regsub -all "\\+4" $arg "=[expr $low + 4]" argeq | |
627fe3fb | 381 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $argeq $tempfile ${copyfile}.srec"] |
21c40443 | 382 | if ![string equal "" $got] then { |
252b5132 RH |
383 | fail "objcopy --adjust-section-vma =" |
384 | } else { | |
385 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"] | |
386 | set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" | |
387 | if ![regexp $want $got all vma] then { | |
388 | fail "objcopy --adjust-section-vma =" | |
389 | } else { | |
390 | set vma 0x$vma | |
391 | if {$vma != $low + 4} then { | |
392 | send_log "$vma != $low + 4\n" | |
393 | fail "objcopy --adjust-section-vma =" | |
394 | } else { | |
395 | pass "objcopy --adjust-section-vma =" | |
396 | } | |
397 | } | |
398 | } | |
399 | } | |
400 | ||
401 | # Test stripping an object. | |
402 | ||
403 | proc strip_test { } { | |
1983fbac | 404 | global AR |
252b5132 RH |
405 | global CC |
406 | global STRIP | |
407 | global STRIPFLAGS | |
408 | global NM | |
409 | global NMFLAGS | |
410 | global srcdir | |
411 | global subdir | |
28902555 | 412 | global READELF |
252b5132 RH |
413 | |
414 | set test "strip" | |
415 | ||
416 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { | |
417 | untested $test | |
418 | return | |
419 | } | |
420 | ||
28902555 BS |
421 | set osabi_fail "false" |
422 | if [is_elf_format] { | |
423 | verbose -log "$READELF -a tmpdir/testprog.o > tmpdir/osabi.in" | |
424 | set exec_output [remote_exec host "$READELF -h tmpdir/testprog.o" "" "/dev/null" "tmpdir/osabi.in"] | |
425 | if { [lindex $exec_output 0] != 0 } then { | |
21c40443 | 426 | unresolved "$test preserving OS/ABI" |
28902555 BS |
427 | set osabi_fail "true" |
428 | } else { | |
429 | verbose -log "grep OS/ABI tmpdir/osabi.in" | |
430 | catch "exec grep OS/ABI tmpdir/osabi.in" osabi_in | |
431 | } | |
432 | } | |
433 | ||
252b5132 | 434 | if [is_remote host] { |
1983fbac | 435 | set archive libstrip.a |
8d263650 | 436 | set objfile [remote_download host tmpdir/testprog.o] |
1983fbac L |
437 | remote_file host delete $archive |
438 | } else { | |
439 | set archive tmpdir/libstrip.a | |
440 | set objfile tmpdir/testprog.o | |
441 | } | |
442 | ||
443 | remote_file build delete tmpdir/libstrip.a | |
444 | ||
445 | set exec_output [binutils_run $AR "rc $archive ${objfile}"] | |
21c40443 | 446 | if ![string equal "" $exec_output] { |
1983fbac | 447 | fail $test |
21c40443 | 448 | unresolved "$test preserving OS/ABI" |
1983fbac L |
449 | return |
450 | } | |
451 | ||
8648f88f | 452 | set exec_output [binutils_run $STRIP "-g $archive"] |
21c40443 | 453 | if ![string equal "" $exec_output] { |
8648f88f | 454 | fail $test |
21c40443 | 455 | unresolved "$test preserving OS/ABI" |
8648f88f L |
456 | return |
457 | } | |
458 | ||
1983fbac | 459 | set exec_output [binutils_run $STRIP "$STRIPFLAGS $archive"] |
21c40443 | 460 | if ![string equal "" $exec_output] { |
1983fbac | 461 | fail $test |
21c40443 | 462 | unresolved "$test preserving OS/ABI" |
1983fbac L |
463 | return |
464 | } | |
465 | ||
28902555 BS |
466 | if { $osabi_fail != "true" && [is_elf_format] } { |
467 | verbose -log "$READELF -a tmpdir/testprog.o > tmpdir/osabi.out" | |
468 | set exec_output [remote_exec host "$READELF -h tmpdir/testprog.o" "" "/dev/null" "tmpdir/osabi.out"] | |
469 | if { [lindex $exec_output 0] != 0 } then { | |
21c40443 | 470 | unresolved "$test preserving OS/ABI" |
28902555 BS |
471 | } else { |
472 | verbose -log "grep OS/ABI tmpdir/osabi.out" | |
473 | catch "exec grep OS/ABI tmpdir/osabi.out" osabi_out | |
474 | if { "$osabi_in" == "$osabi_out" } { | |
475 | pass "$test preserving OS/ABI" | |
476 | } else { | |
477 | fail "$test preserving OS/ABI" | |
478 | } | |
479 | } | |
480 | } | |
481 | ||
1983fbac L |
482 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { |
483 | untested $test | |
484 | return | |
485 | } | |
486 | ||
487 | if [is_remote host] { | |
8d263650 | 488 | set objfile [remote_download host tmpdir/testprog.o] |
252b5132 RH |
489 | } else { |
490 | set objfile tmpdir/testprog.o | |
491 | } | |
492 | ||
493 | set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"] | |
21c40443 | 494 | if ![string equal "" $exec_output] { |
252b5132 RH |
495 | fail $test |
496 | return | |
497 | } | |
498 | ||
499 | set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"] | |
68a4c073 | 500 | if ![string match "*: no symbols*" $exec_output] { |
252b5132 RH |
501 | fail $test |
502 | return | |
503 | } | |
504 | ||
505 | pass $test | |
506 | } | |
507 | ||
508 | strip_test | |
509 | ||
510 | # Test stripping an object file with saving a symbol | |
511 | ||
512 | proc strip_test_with_saving_a_symbol { } { | |
513 | global CC | |
514 | global STRIP | |
515 | global STRIPFLAGS | |
516 | global NM | |
517 | global NMFLAGS | |
518 | global srcdir | |
519 | global subdir | |
520 | ||
521 | set test "strip with saving a symbol" | |
522 | ||
523 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { | |
524 | untested $test | |
525 | return | |
526 | } | |
527 | ||
528 | if [is_remote host] { | |
8d263650 | 529 | set objfile [remote_download host tmpdir/testprog.o] |
252b5132 RH |
530 | } else { |
531 | set objfile tmpdir/testprog.o | |
532 | } | |
533 | ||
534 | set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main -K _main $objfile"] | |
21c40443 | 535 | if ![string equal "" $exec_output] { |
252b5132 RH |
536 | fail $test |
537 | return | |
538 | } | |
539 | ||
540 | set exec_output [binutils_run $NM "$NMFLAGS $objfile"] | |
195fe636 | 541 | if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \ |
252b5132 RH |
542 | && ![regexp {^([0-9a-fA-F]+)?[ ]+T _main} $exec_output]} { |
543 | fail $test | |
544 | return | |
545 | } | |
546 | ||
547 | pass $test | |
548 | } | |
549 | ||
550 | strip_test_with_saving_a_symbol | |
551 | ||
552 | # Build a final executable. | |
553 | ||
99ad8390 | 554 | if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } { |
f8a7038a NC |
555 | set test_prog "testprog.exe" |
556 | } else { | |
557 | set test_prog "testprog" | |
558 | } | |
559 | ||
252b5132 RH |
560 | proc copy_setup { } { |
561 | global srcdir | |
562 | global subdir | |
9a580d9a | 563 | global gcc_gas_flag |
f8a7038a | 564 | global test_prog |
72d4c02f | 565 | global host_triplet |
21c40443 | 566 | |
8d263650 BE |
567 | set res [build_wrapper testglue.o] |
568 | set flags { debug } | |
21c40443 | 569 | |
28902555 | 570 | if { [istarget *-*-uclinux*] && ![istarget tic6x-*-*] } { |
903b1f5b NS |
571 | return 1 |
572 | } | |
21c40443 | 573 | |
252b5132 | 574 | if { $res != "" } { |
8d263650 BE |
575 | lappend flags "additional_flags=[lindex $res 1]" |
576 | set add_libs "testglue.o" | |
252b5132 | 577 | } else { |
8d263650 | 578 | set add_libs "" |
252b5132 RH |
579 | } |
580 | ||
5940a93c TS |
581 | if { [istarget *-*-linux*] |
582 | || [istarget *-*-gnu*] } { | |
9a580d9a L |
583 | foreach i $gcc_gas_flag { |
584 | set flags "additional_flags=$i $flags" | |
585 | } | |
586 | } | |
f8a7038a | 587 | if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/$test_prog executable $flags] != "" } { |
252b5132 RH |
588 | return 2 |
589 | } | |
590 | ||
8d263650 BE |
591 | set result [remote_load target tmpdir/$test_prog] |
592 | set status [lindex $result 0] | |
252b5132 RH |
593 | |
594 | if { $status != "pass" } { | |
72d4c02f | 595 | send_log "cannot run executable, status = ${status} on ${host_triplet}\n" |
21c40443 | 596 | return 3 |
252b5132 RH |
597 | } |
598 | ||
599 | return 0 | |
600 | } | |
601 | ||
602 | # Test copying an executable. | |
603 | ||
604 | proc copy_executable { prog flags test1 test2 } { | |
f8a7038a | 605 | global test_prog |
252b5132 RH |
606 | |
607 | if [is_remote host] { | |
8d263650 | 608 | set testfile [remote_download host tmpdir/$test_prog] |
252b5132 RH |
609 | set testcopy copyprog |
610 | } else { | |
f8a7038a | 611 | set testfile tmpdir/$test_prog |
252b5132 RH |
612 | set testcopy tmpdir/copyprog |
613 | } | |
8d263650 | 614 | remote_file host delete $testcopy |
252b5132 RH |
615 | |
616 | set exec_output [binutils_run $prog "$flags $testfile $testcopy"] | |
617 | ||
21c40443 | 618 | if ![string equal "" $exec_output] { |
252b5132 | 619 | fail $test1 |
21c40443 | 620 | if [string equal "" $test2] { |
0d063f63 AM |
621 | return |
622 | } | |
252b5132 RH |
623 | fail $test2 |
624 | return | |
625 | } | |
626 | ||
627 | if [is_remote host] { | |
628 | remote_upload host $testcopy tmpdir/copyprog | |
629 | } | |
630 | ||
f8a7038a | 631 | set status [remote_exec build "cmp" "tmpdir/$test_prog tmpdir/copyprog"] |
8d263650 | 632 | set exec_output [lindex $status 1] |
252b5132 | 633 | |
21c40443 | 634 | if [string equal "" $exec_output] then { |
252b5132 RH |
635 | pass $test1 |
636 | } else { | |
637 | send_log "$exec_output\n" | |
638 | verbose "$exec_output" | |
639 | ||
640 | # This will fail for many reasons. For example, it will most | |
641 | # likely fail if a non-GNU linker is used. Therefore, we do | |
642 | # not insist that it pass. If you are using an assembler and | |
643 | # linker based on the same BFD as objcopy, it is worth | |
644 | # investigating to see why this failure occurs. If we are | |
645 | # cross compiling, we assume that a GNU linker is being used, | |
646 | # and expect it to succeed. | |
647 | if {[isnative]} then { | |
648 | setup_xfail "*-*-*" | |
649 | } | |
650 | ||
9cc0123f | 651 | # This also fails for some mips targets. See elf32-mips.c |
252b5132 | 652 | # mips_elf_sym_is_global. |
9cc0123f AM |
653 | if { [is_bad_symtab] } then { |
654 | setup_xfail "*-*-*" | |
655 | } | |
252b5132 | 656 | |
8c5fc800 | 657 | setup_xfail "arm*-*-coff" |
11d47adc | 658 | setup_xfail "arm*-*-pe" |
88f14853 | 659 | setup_xfail "*-*-mingw*" |
899396fe | 660 | setup_xfail "*-*-cygwin*" |
21c40443 | 661 | |
252b5132 RH |
662 | fail $test1 |
663 | } | |
664 | ||
21c40443 | 665 | if [string equal "" $test2] { |
0d063f63 AM |
666 | return |
667 | } | |
668 | ||
252b5132 | 669 | set output [remote_load target tmpdir/copyprog] |
8d263650 | 670 | set status [lindex $output 0] |
252b5132 RH |
671 | if { $status != "pass" } { |
672 | fail $test2 | |
673 | } else { | |
674 | pass $test2 | |
675 | } | |
676 | } | |
677 | ||
678 | # Test stripping an executable | |
679 | ||
21c40443 | 680 | proc strip_executable { prog flags test1 test2 } { |
252b5132 RH |
681 | global NM |
682 | global NMFLAGS | |
28902555 | 683 | global READELF |
252b5132 | 684 | |
0fcc17f8 | 685 | remote_file build delete tmpdir/striprog |
252b5132 RH |
686 | remote_download build tmpdir/copyprog tmpdir/striprog |
687 | if [is_remote host] { | |
8d263650 | 688 | set copyfile [remote_download host tmpdir/striprog] |
252b5132 RH |
689 | } else { |
690 | set copyfile tmpdir/striprog | |
691 | } | |
692 | ||
28902555 BS |
693 | set osabi_fail "false" |
694 | if [is_elf_format] { | |
695 | verbose -log "$READELF -a ${copyfile} > tmpdir/osabi.in" | |
696 | set exec_output [remote_exec host "$READELF -h ${copyfile}" "" "/dev/null" "tmpdir/osabi.in"] | |
697 | if { [lindex $exec_output 0] != 0 } then { | |
21c40443 | 698 | unresolved "$test1 preserving OS/ABI" |
28902555 BS |
699 | set osabi_fail "true" |
700 | } else { | |
701 | verbose -log "grep OS/ABI tmpdir/osabi.in" | |
702 | catch "exec grep OS/ABI tmpdir/osabi.in" osabi_in | |
703 | } | |
704 | } | |
705 | ||
252b5132 | 706 | set exec_output [binutils_run $prog "$flags ${copyfile}"] |
21c40443 AM |
707 | if ![string equal "" $exec_output] { |
708 | fail $test1 | |
709 | if [string equal "" $test2] { | |
710 | return | |
711 | } | |
712 | fail $test2 | |
252b5132 RH |
713 | return |
714 | } | |
715 | ||
716 | if [is_remote host] { | |
8d263650 | 717 | remote_upload host ${copyfile} tmpdir/striprog |
252b5132 RH |
718 | } |
719 | ||
28902555 BS |
720 | if { $osabi_fail != "true" && [is_elf_format] } { |
721 | verbose -log "$READELF -a ${copyfile} > tmpdir/osabi.out" | |
722 | set exec_output [remote_exec host "$READELF -h ${copyfile}" "" "/dev/null" "tmpdir/osabi.out"] | |
723 | if { [lindex $exec_output 0] != 0 } then { | |
21c40443 | 724 | unresolved "$test1 preserving OS/ABI" |
28902555 BS |
725 | } else { |
726 | verbose -log "grep OS/ABI tmpdir/osabi.out" | |
727 | catch "exec grep OS/ABI tmpdir/osabi.out" osabi_out | |
728 | if { "$osabi_in" == "$osabi_out" } { | |
21c40443 | 729 | pass "$test1 preserving OS/ABI" |
28902555 | 730 | } else { |
21c40443 | 731 | fail "$test1 preserving OS/ABI" |
28902555 BS |
732 | } |
733 | } | |
734 | } | |
735 | ||
252b5132 | 736 | set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] |
68a4c073 | 737 | if ![string match "*: no symbols*" $exec_output] { |
21c40443 | 738 | fail $test1 |
252b5132 RH |
739 | return |
740 | } | |
21c40443 AM |
741 | |
742 | if [string equal "" $test2] { | |
743 | return | |
744 | } | |
745 | ||
746 | set result [remote_load target tmpdir/striprog] | |
747 | set status [lindex $result 0] | |
748 | if { $status != "pass" } { | |
749 | fail $test2 | |
750 | return | |
751 | } | |
752 | ||
753 | pass $test2 | |
252b5132 RH |
754 | } |
755 | ||
756 | # Test stripping an executable with saving a symbol | |
757 | ||
21c40443 | 758 | proc strip_executable_with_saving_a_symbol { prog flags test1 test2 } { |
252b5132 RH |
759 | global NM |
760 | global NMFLAGS | |
761 | ||
0fcc17f8 | 762 | remote_file build delete tmpdir/striprog |
252b5132 RH |
763 | remote_download build tmpdir/copyprog tmpdir/striprog |
764 | if [is_remote host] { | |
8d263650 | 765 | set copyfile [remote_download host tmpdir/striprog] |
252b5132 RH |
766 | } else { |
767 | set copyfile tmpdir/striprog | |
768 | } | |
769 | ||
770 | set exec_output [binutils_run $prog "$flags ${copyfile}"] | |
21c40443 AM |
771 | if ![string equal "" $exec_output] { |
772 | fail $test1 | |
773 | if [string equal "" $test2] { | |
774 | return | |
775 | } | |
776 | fail $test2 | |
252b5132 RH |
777 | return |
778 | } | |
779 | ||
252b5132 | 780 | set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] |
edc45ab9 HPN |
781 | if { [istarget mmix-knuth-mmixware] } { |
782 | # Whenever there's a symbol in the mmo format, there's the symbol | |
783 | # Main, so remove it manually from the expected output for sake of | |
784 | # this test. | |
785 | ||
786 | # Using "" not {} to get the \n and \r translated. | |
787 | regsub "^\[0-9a-fA-F\]+\[ \]+T Main\[\n\r\]+" $exec_output "" exec_output | |
788 | } | |
789 | ||
adacfc81 JJ |
790 | if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \ |
791 | && ![regexp {^([0-9a-fA-F]+)?[ ]+[TD] _main} $exec_output]} { | |
21c40443 | 792 | fail $test1 |
252b5132 RH |
793 | return |
794 | } | |
21c40443 AM |
795 | |
796 | if [string equal "" $test2] { | |
797 | return | |
798 | } | |
799 | ||
800 | if [is_remote host] { | |
801 | remote_upload host ${copyfile} tmpdir/striprog | |
802 | } | |
803 | ||
804 | set result [remote_load target tmpdir/striprog] | |
805 | set status [lindex $result 0] | |
806 | if { $status != "pass" } { | |
807 | fail $test2 | |
808 | return | |
809 | } | |
810 | ||
811 | pass $test2 | |
252b5132 RH |
812 | } |
813 | ||
11701589 JK |
814 | # Test keeping only debug symbols of an executable |
815 | ||
816 | proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } { | |
0fcc17f8 | 817 | remote_file build delete tmpdir/striprog |
11701589 JK |
818 | remote_download build tmpdir/copyprog tmpdir/striprog |
819 | if [is_remote host] { | |
820 | set copyfile [remote_download host tmpdir/striprog] | |
821 | } else { | |
822 | set copyfile tmpdir/striprog | |
823 | } | |
824 | ||
825 | set exec_output [binutils_run $prog1 "$flags1 ${copyfile}"] | |
21c40443 | 826 | if ![string equal "" $exec_output] { |
11701589 JK |
827 | fail $test1 |
828 | return | |
829 | } | |
830 | pass $test1 | |
831 | ||
832 | set exec_output [binutils_run $prog2 "$flags2 ${copyfile}"] | |
21c40443 | 833 | if ![string equal "" $exec_output] { |
11701589 JK |
834 | fail $test2 |
835 | return | |
836 | } | |
837 | pass $test2 | |
838 | } | |
839 | ||
63b9bbb7 | 840 | # Tests that in a debug only copy of a file the sections |
de194d85 | 841 | # headers whose types have been changed to NOBITS still |
63b9bbb7 NC |
842 | # retain their sh_link fields. |
843 | ||
844 | proc keep_debug_symbols_and_check_links { prog flags test } { | |
845 | global READELF | |
846 | ||
847 | remote_file build delete tmpdir/striprog | |
848 | remote_download build tmpdir/copyprog tmpdir/striprog | |
849 | if [is_remote host] { | |
850 | set copyfile [remote_download host tmpdir/striprog] | |
851 | } else { | |
852 | set copyfile tmpdir/striprog | |
853 | } | |
854 | ||
855 | set exec_output [binutils_run $prog "$flags ${copyfile}"] | |
21c40443 | 856 | if ![string equal "" $exec_output] { |
63b9bbb7 NC |
857 | fail $test |
858 | return | |
859 | } | |
860 | ||
861 | set got [binutils_run $READELF "-S --wide ${copyfile}"] | |
862 | ||
863 | set fails 0 | |
864 | # Regexp to match a section with NOBITS type and extract its name and sh_link fields | |
865 | while {[regexp \ | |
866 | {[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ ]+NOBITS[ ]+[0-9a-fA-F]+ [0-9a-fA-F]+ [0-9a-fA-F]+ [0-9]+[ A]+([0-9]+)(.*)} \ | |
867 | $got all name link rest]} { | |
868 | set sh_link 0x$link | |
869 | if {$sh_link == 0} { | |
870 | # Only some NOBITS sections should have a non-zero sh_link field. | |
871 | # Look for them by name. | |
872 | verbose "NOBITS section .$name has a 0 sh_link field\n" | |
873 | switch $name { | |
874 | "rela.*" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
875 | "rel.*" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
876 | "hash" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
877 | "gnu_version" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
878 | "dynsym" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
879 | "gnu.version_r" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
880 | "dynamic" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
881 | "symtab" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
882 | } | |
883 | } | |
884 | set got $rest | |
885 | } | |
886 | ||
887 | if {$fails == 0} { | |
888 | pass $test | |
889 | } else { | |
890 | fail $test | |
891 | } | |
892 | } | |
893 | ||
894 | ||
252b5132 | 895 | set test1 "simple objcopy of executable" |
21c40443 AM |
896 | set test1r "run objcopy of executable" |
897 | set test2 "strip executable" | |
898 | set test2r "run stripped executable" | |
899 | set test3 "strip executable with saving a symbol" | |
900 | set test3r "run stripped executable with saving a symbol" | |
901 | set test4 "keep only debug data" | |
902 | set test5 "simple objcopy of debug data" | |
63b9bbb7 | 903 | if [is_elf_format] { |
21c40443 | 904 | set test6 "NOBITS sections retain sh_link field" |
63b9bbb7 | 905 | } |
252b5132 RH |
906 | |
907 | switch [copy_setup] { | |
908 | "1" { | |
909 | # do nothing | |
910 | } | |
911 | "2" { | |
912 | untested $test1 | |
21c40443 | 913 | untested $test1r |
252b5132 | 914 | untested $test2 |
21c40443 | 915 | untested $test2r |
252b5132 | 916 | untested $test3 |
21c40443 | 917 | untested $test3r |
252b5132 | 918 | untested $test4 |
11701589 | 919 | untested $test5 |
63b9bbb7 | 920 | if [is_elf_format] { |
21c40443 | 921 | untested $test6 |
63b9bbb7 | 922 | } |
252b5132 RH |
923 | } |
924 | "3" { | |
0d063f63 | 925 | copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "" |
21c40443 AM |
926 | unsupported $test1r |
927 | strip_executable "$STRIP" "$STRIPFLAGS" "$test2" "" | |
928 | unsupported $test2r | |
929 | strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test3" "" | |
930 | unsupported $test3r | |
931 | keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test4" \ | |
932 | "$OBJCOPY" "$OBJCOPYFLAGS" "$test5" | |
63b9bbb7 | 933 | if [is_elf_format] { |
21c40443 | 934 | keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6" |
63b9bbb7 | 935 | } |
252b5132 RH |
936 | } |
937 | "0" { | |
21c40443 AM |
938 | copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test1r" |
939 | strip_executable "$STRIP" "$STRIPFLAGS" "$test2" "$test2r" | |
940 | strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test3" "$test3r" | |
941 | keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test4" \ | |
942 | "$OBJCOPY" "$OBJCOPYFLAGS" "$test5" | |
63b9bbb7 | 943 | if [is_elf_format] { |
21c40443 | 944 | keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6" |
63b9bbb7 | 945 | } |
252b5132 RH |
946 | } |
947 | } | |
ad2fb2cd | 948 | |
6a0d0afd L |
949 | proc objcopy_test_readelf {testname srcfile} { |
950 | global OBJCOPY | |
951 | global OBJCOPYFLAGS | |
952 | global READELF | |
953 | global srcdir | |
954 | global subdir | |
955 | ||
956 | if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then { | |
957 | unresolved "objcopy ($testname)" | |
958 | return | |
959 | } | |
960 | ||
961 | verbose -log "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o" | |
7f6a71ff JM |
962 | set exec_output [remote_exec host "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"] |
963 | if { [lindex $exec_output 0] != 0 | |
21c40443 | 964 | || ![string equal "" [lindex $exec_output 1]] } then { |
6a0d0afd | 965 | fail "objcopy ($testname)" |
004314cc | 966 | return |
6a0d0afd L |
967 | } |
968 | ||
969 | verbose -log "$READELF -a tmpdir/bintest.o > tmpdir/bintest.o.out" | |
7f6a71ff JM |
970 | set exec_output [remote_exec host "$READELF -a tmpdir/bintest.o" "" "/dev/null" "tmpdir/bintest.o.out"] |
971 | if { [lindex $exec_output 0] != 0 } then { | |
972 | unresolved "objcopy ($testname)" | |
973 | return | |
974 | } | |
975 | set exec_output [prune_warnings [lindex $exec_output 1]] | |
21c40443 | 976 | if ![string equal "" $exec_output] then { |
6a0d0afd L |
977 | unresolved "objcopy ($testname)" |
978 | return | |
979 | } | |
980 | ||
981 | verbose -log "$READELF -a tmpdir/copy.o > tmpdir/copy.o.out" | |
7f6a71ff JM |
982 | set exec_output [remote_exec host "$READELF -a tmpdir/copy.o" "" "/dev/null" "tmpdir/copy.o.out"] |
983 | if { [lindex $exec_output 0] != 0 } then { | |
984 | unresolved "objcopy ($testname)" | |
985 | return | |
986 | } | |
987 | set exec_output [prune_warnings [lindex $exec_output 1]] | |
21c40443 | 988 | if ![string equal "" $exec_output] then { |
6a0d0afd L |
989 | unresolved "objcopy ($testname)" |
990 | return | |
991 | } | |
992 | ||
993 | verbose -log "diff tmpdir/bintest.o.out tmpdir/copy.o.out" | |
994 | catch "exec diff tmpdir/bintest.o.out tmpdir/copy.o.out" exec_output | |
995 | set exec_output [prune_warnings $exec_output] | |
996 | ||
21c40443 | 997 | if [string equal "" $exec_output] then { |
6a0d0afd L |
998 | pass "objcopy ($testname)" |
999 | } else { | |
1000 | fail "objcopy ($testname)" | |
1001 | } | |
1002 | } | |
1003 | ||
0b45135e AB |
1004 | proc objcopy_test_symbol_manipulation {} { |
1005 | global srcdir | |
1006 | global subdir | |
1007 | ||
1008 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/symbols-*.d]] | |
1009 | foreach t $test_list { | |
1010 | # We need to strip the ".d", but can leave the dirname. | |
1011 | verbose [file rootname $t] | |
1012 | run_dump_test [file rootname $t] | |
1013 | } | |
1014 | } | |
1015 | ||
b8871f35 L |
1016 | proc objcopy_test_elf_common_symbols {} { |
1017 | global srcdir | |
1018 | global subdir | |
1019 | ||
1020 | # hpux has a non-standard common directive. | |
1021 | if { [istarget "*-*-hpux*"] } then { | |
1022 | return | |
1023 | } | |
1024 | ||
1025 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/common-*.d]] | |
1026 | foreach t $test_list { | |
1027 | # We need to strip the ".d", but can leave the dirname. | |
1028 | verbose [file rootname $t] | |
1029 | run_dump_test [file rootname $t] | |
1030 | } | |
1031 | } | |
1032 | ||
ad2fb2cd L |
1033 | # ia64 specific tests |
1034 | if { ([istarget "ia64-*-elf*"] | |
1035 | || [istarget "ia64-*-linux*"]) } { | |
64bb95af L |
1036 | objcopy_test "ia64 link order" link-order.s |
1037 | } | |
ad2fb2cd | 1038 | |
64bb95af L |
1039 | # ELF specific tests |
1040 | if [is_elf_format] { | |
0b45135e | 1041 | objcopy_test_symbol_manipulation |
b8871f35 | 1042 | objcopy_test_elf_common_symbols |
64bb95af | 1043 | objcopy_test "ELF unknown section type" unknown.s |
6a0d0afd | 1044 | objcopy_test_readelf "ELF group" group.s |
eb3980ce | 1045 | objcopy_test_readelf "ELF group" group-2.s |
f206e905 | 1046 | objcopy_test_readelf "ELF group" group-3.s |
e1e87d1e | 1047 | objcopy_test_readelf "ELF group" group-4.s |
a91e1603 | 1048 | objcopy_test_readelf "GNU_MBIND section" mbind1.s |
b2fc24d4 | 1049 | run_dump_test "group-5" |
4c8e8a7e | 1050 | run_dump_test "group-6" |
6e5e9d58 AM |
1051 | run_dump_test "group-7a" |
1052 | run_dump_test "group-7b" | |
1053 | run_dump_test "group-7c" | |
85d7f0b9 | 1054 | run_dump_test "copy-1" |
0930eddd | 1055 | run_dump_test "note-1" |
9ef920e9 NC |
1056 | if [is_elf64 tmpdir/bintest.o] { |
1057 | run_dump_test "note-2-64" | |
714da62f | 1058 | run_dump_test "note-3-64" |
6f156d7a | 1059 | run_dump_test "note-4-64" |
9ef920e9 NC |
1060 | } else { |
1061 | run_dump_test "note-2-32" | |
714da62f | 1062 | run_dump_test "note-3-32" |
6f156d7a | 1063 | run_dump_test "note-4-32" |
9ef920e9 | 1064 | } |
ad2fb2cd | 1065 | } |
af3c5dea | 1066 | |
af3c5dea | 1067 | run_dump_test "copy-2" |
81fc501a | 1068 | run_dump_test "copy-3" |
0691f7af | 1069 | run_dump_test "copy-4" |
cbd44e24 L |
1070 | run_dump_test "pr19020a" |
1071 | run_dump_test "pr19020b" | |
d58c2e3a RS |
1072 | |
1073 | if [is_elf_format] { | |
748fc5e9 L |
1074 | run_dump_test "strip-1" |
1075 | run_dump_test "strip-2" | |
1aa9ef63 | 1076 | run_dump_test "strip-3" |
eb3980ce L |
1077 | run_dump_test "strip-4" |
1078 | run_dump_test "strip-5" | |
f206e905 L |
1079 | run_dump_test "strip-6" |
1080 | run_dump_test "strip-7" | |
e1e87d1e L |
1081 | run_dump_test "strip-8" |
1082 | run_dump_test "strip-9" | |
d4ac1f87 | 1083 | run_dump_test "strip-12" |
2f8ceb38 MR |
1084 | |
1085 | if { [istarget "mips64*-*-openbsd*"] } { | |
1086 | set reloc_format mips64 | |
1087 | } elseif { [istarget "arm-*"] \ | |
1088 | || [istarget "d10v-*"] \ | |
1089 | || [istarget "dlx-*"] \ | |
1090 | || [istarget "i*86-*"] \ | |
2f8ceb38 MR |
1091 | || [istarget "m681*-*"] \ |
1092 | || [istarget "m68hc1*-*"] \ | |
1093 | || ([istarget "mips*-*"] \ | |
1094 | && ![istarget "mips64*-ps2-elf*"] \ | |
1095 | && ![istarget "*-*-irix6*"] \ | |
1096 | && ![istarget "mips64*-*-freebsd*"] \ | |
1097 | && ![istarget "mips64*-*-kfreebsd*-gnu"] \ | |
1098 | && ![istarget "mips64*-*-linux*"]) \ | |
1099 | || [istarget "score*-*"] \ | |
1100 | || [istarget "xgate-*"] } { | |
1101 | set reloc_format rel | |
1102 | } else { | |
1103 | set reloc_format rela | |
1104 | } | |
1105 | run_dump_test "strip-13" [list [list source strip-13${reloc_format}.s]] | |
3f97ba9f MR |
1106 | # Select a relocation number that corresponds to one actually |
1107 | # supported by the target and ABI being tested. | |
1108 | if { [istarget "aarch64*-*"] } { | |
1109 | set reloc 259 | |
1110 | } elseif { [istarget "ia64*-*"] \ | |
1111 | || [istarget "m32r*-*"] \ | |
d4ae1932 | 1112 | || [istarget "nds32*-*"] \ |
3f97ba9f MR |
1113 | || [istarget "v850*-*"] } { |
1114 | set reloc 50 | |
d4ae1932 AM |
1115 | } elseif { [istarget "pru-*"] } { |
1116 | set reloc 11 | |
3f97ba9f MR |
1117 | } else { |
1118 | set reloc 1 | |
1119 | } | |
1120 | run_dump_test "strip-14" [list \ | |
1121 | [list source strip-14${reloc_format}.s] \ | |
1122 | [list as "--defsym RELOC=${reloc}"] \ | |
1123 | [list as [expr {[is_elf64 tmpdir/bintest.o] \ | |
1124 | ? "--defsym ELF64=1" : ""}]]] | |
d52e3d06 MR |
1125 | run_dump_test "strip-15" [list \ |
1126 | [list source strip-15${reloc_format}.s] \ | |
1127 | [list as "--defsym RELOC=${reloc}"] \ | |
1128 | [list as [expr {[is_elf64 tmpdir/bintest.o] \ | |
1129 | ? "--defsym ELF64=1" : ""}]]] | |
f3185997 | 1130 | |
a43942db MR |
1131 | # This requires STB_GNU_UNIQUE support with OSABI set to GNU. |
1132 | if { [supports_gnu_unique] } { | |
4cd28456 AM |
1133 | run_dump_test "strip-10" |
1134 | } | |
211dc24b | 1135 | run_dump_test "strip-11" |
312aaa3c | 1136 | |
b8b6abe0 AM |
1137 | if { [istarget "i*86-*"] || [istarget "x86_64-*-*"] } { |
1138 | # Check to make sure we don't strip a symbol named in relocations. | |
1139 | set test "objcopy keeps symbols needed by relocs" | |
312aaa3c | 1140 | |
b8b6abe0 | 1141 | set srcfile $srcdir/$subdir/needed-by-reloc.s |
312aaa3c | 1142 | |
b8b6abe0 AM |
1143 | if {![binutils_assemble $srcfile tmpdir/bintest.o]} then { |
1144 | unresolved $test | |
1145 | } else { | |
1146 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS --strip-symbol=foo tmpdir/bintest.o ${copyfile}.o"] | |
312aaa3c | 1147 | |
b8b6abe0 AM |
1148 | if [regexp "not stripping symbol `foo' because it is named in a relocation" $got] { |
1149 | pass $test | |
1150 | } else { | |
1151 | fail $test | |
1152 | } | |
1153 | } | |
312aaa3c | 1154 | } |
b8b6abe0 | 1155 | |
8560e02a HPN |
1156 | # The symbol table for some MIPS targets is sorted differently than |
1157 | # the ELF canonical order, so the regexps in localize-hidden-1.d fail | |
9cc0123f AM |
1158 | # to match. |
1159 | if { [is_bad_symtab] } then { | |
1160 | setup_xfail "*-*-*" | |
8560e02a | 1161 | } |
b8b6abe0 | 1162 | run_dump_test "localize-hidden-1" |
afeb3d7f L |
1163 | run_dump_test "testranges" |
1164 | run_dump_test "testranges-ia64" | |
500ee42e ILT |
1165 | |
1166 | run_dump_test "add-section" | |
2b35fb28 | 1167 | run_dump_test "add-symbol" |
500ee42e | 1168 | run_dump_test "add-empty-section" |
18ae9cc1 L |
1169 | |
1170 | run_dump_test "exclude-1a" | |
1171 | run_dump_test "exclude-1b" | |
e511c9b1 AB |
1172 | |
1173 | run_dump_test "only-section-01" | |
1174 | run_dump_test "remove-section-01" | |
d3e5f6c8 AB |
1175 | |
1176 | # Test the remove relocation functionality | |
1177 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/remove-relocs-*.d]] | |
1178 | foreach t $test_list { | |
1179 | # We need to strip the ".d", but can leave the dirname. | |
1180 | verbose [file rootname $t] | |
1181 | run_dump_test [file rootname $t] | |
1182 | } | |
312aaa3c | 1183 | } |
b8b6abe0 | 1184 | run_dump_test "localize-hidden-2" |
14f2c699 L |
1185 | |
1186 | # Test objcopying an object file without global symbol | |
1187 | ||
1188 | proc objcopy_test_without_global_symbol { } { | |
1189 | global OBJCOPY | |
1190 | global OBJCOPYFLAGS | |
1191 | global OBJDUMP | |
1192 | global OBJDUMPFLAGS | |
1193 | global srcdir | |
1194 | global subdir | |
1195 | ||
1196 | set test "strip without global symbol " | |
1197 | ||
1198 | if { [target_compile $srcdir/$subdir/pr19547.c tmpdir/pr19547.o object debug] != "" } { | |
1199 | untested $test | |
1200 | return | |
1201 | } | |
1202 | ||
1203 | if [is_remote host] { | |
1204 | set objfile [remote_download host tmpdir/pr19547.o] | |
1205 | } else { | |
1206 | set objfile tmpdir/pr19547.o | |
1207 | } | |
1208 | ||
1209 | set exec_output [binutils_run $OBJCOPY "$OBJCOPYFLAGS --strip-unneeded $objfile"] | |
1210 | if ![string equal "" $exec_output] { | |
1211 | fail $test | |
1212 | return | |
1213 | } | |
1214 | ||
1215 | set exec_output [binutils_run $OBJDUMP "$OBJDUMPFLAGS -t $objfile"] | |
1216 | if {![regexp "no symbols" $exec_output]} { | |
1217 | fail $test | |
1218 | return | |
1219 | } | |
1220 | ||
1221 | pass $test | |
1222 | } | |
1223 | ||
41699fa4 NC |
1224 | # The AArch64 and ARM targets preserve mapping symbols |
1225 | # in object files, so they will fail this test. | |
1226 | setup_xfail aarch64*-*-* arm*-*-* | |
1227 | ||
14f2c699 | 1228 | objcopy_test_without_global_symbol |