bfd/
[binutils.git] / binutils / testsuite / binutils-all / objcopy.exp
blobfe87f6280e0cce3db168b30fb3feed1af9563187
1 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2 # 2004, 2006, 2007
3 # Free Software Foundation, Inc.
5 # This program 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.
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, MA 02110-1301, USA.
19 # Please email any bugs, comments, and/or additions to this file to:
20 # bug-dejagnu@prep.ai.mit.edu
22 # Written by Ian Lance Taylor <ian@cygnus.com>
24 if ![is_remote host] {
25 if {[which $OBJCOPY] == 0} then {
26 perror "$OBJCOPY does not exist"
27 return
31 send_user "Version [binutil_version $OBJCOPY]"
33 if ![is_remote host] {
34 set tempfile tmpdir/bintest.o
35 set copyfile tmpdir/copy
36 } else {
37 set tempfile [remote_download host tmpdir/bintest.o]
38 set copyfile copy
41 # Test that objcopy does not modify a file when copying it.
43 proc objcopy_test {testname srcfile} {
44 global OBJCOPY
45 global OBJCOPYFLAGS
46 global srcdir
47 global subdir
48 global tempfile
49 global copyfile
51 if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then {
52 perror "unresolved $testname"
53 unresolved "objcopy ($testname)"
54 return
57 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS $tempfile ${copyfile}.o"]
59 if ![string match "" $got] then {
60 fail "objcopy ($testname)"
61 } else {
62 send_log "cmp $tempfile ${copyfile}.o\n"
63 verbose "cmp $tempfile ${copyfile}.o"
64 if [is_remote host] {
65 set src1 tmpdir/bintest.o
66 set src2 tmpdir/copy.o
67 remote_upload host $tempfile $src1
68 remote_upload host ${copyfile}.o $src2
69 } else {
70 set src1 ${tempfile}
71 set src2 ${copyfile}.o
73 set status [remote_exec build cmp "${src1} ${src2}"]
74 set exec_output [lindex $status 1]
75 set exec_output [prune_warnings $exec_output]
77 # On some systems the result of objcopy will not be identical.
78 # Usually this is just because gas isn't using bfd to write the
79 # files in the first place, and may order things a little
80 # differently. Those systems should use setup_xfail here.
82 setup_xfail "h8300-*-rtems*" "h8300-*-coff"
83 setup_xfail "h8500-*-rtems*" "h8500-*-coff"
84 setup_xfail "hppa*-*-*"
85 setup_xfail "i960-*"
86 setup_xfail "m68*-*-*coff" "m68*-*-hpux*" "m68*-*-lynxos*"
87 setup_xfail "m68*-*-sysv*" "m68*-apple-aux*"
88 setup_xfail "m8*-*"
89 setup_xfail "or32-*-rtems*" "or32-*-coff"
90 setup_xfail "sh-*-coff*" "sh-*-rtems*"
91 setup_xfail "tic4x-*-*" "tic80-*-*" "w65-*"
93 clear_xfail "hppa*64*-*-hpux*" "hppa*-*-linux*" "hppa*-*-lites*"
94 clear_xfail "hppa*-*-*n*bsd*" "hppa*-*-rtems*" "*-*-*elf*"
95 clear_xfail "m68*-*-sysv4*"
97 if [string match "" $exec_output] then {
98 pass "objcopy ($testname)"
99 } else {
100 send_log "$exec_output\n"
101 verbose "$exec_output" 1
103 # On OSF/1, this succeeds with gas and fails with /bin/as.
104 setup_xfail "alpha*-*-osf*"
106 fail "objcopy ($testname)"
111 objcopy_test "simple copy" bintest.s
113 # Test reversing bytes in a section.
115 set reversed ${tempfile}-reversed
116 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -j .data --reverse-bytes=4 $tempfile $reversed"]
118 if ![string match "" $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
126 set origdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $tempfile"]
127 set revdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $reversed"]
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]
133 if {$found_orig == 0 || $found_rev == 0} then {
134 fail "objcopy --reverse-bytes"
135 } else {
136 scan $origdata "%2x%2x%2x%2x" b1 b2 b3 b4
137 scan $revdata "%2x%2x%2x%2x" c4 c3 c2 c1
139 if {$b1 == $c1 && $b2 == $c2 && $b3 == $c3 && $b4 == $c4} then {
140 pass "objcopy --reverse-bytes"
141 } else {
142 fail "objcopy --reverse-bytes"
147 # Test generating S records.
149 # We make the srec filename 8.3 compatible. Note that the header string
150 # matched against depends on the name of the file. Ugh.
152 if [is_remote host] {
153 set srecfile copy.sre
154 set header_string S00B0000636F70792E737265C1
155 } else {
156 set srecfile ${copyfile}.srec
157 set header_string S0130000746D706469722F636F70792E7372656397
160 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"]
162 if ![string match "" $got] then {
163 fail "objcopy -O srec"
164 } else {
165 if [is_remote host] {
166 remote_upload host ${srecfile} tmpdir/copy.srec
167 set srecfile tmpdir/copy.srec
169 set file [open ${srecfile} r]
171 # The first S record is fixed by the file name we are using.
172 gets $file line
173 send_log "$line\n"
174 verbose $line
175 if ![regexp "$header_string.*" $line] {
176 send_log "bad header\n"
177 fail "objcopy -O srec"
178 } else {
179 while {[gets $file line] != -1 \
180 && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} {
181 send_log "$line\n"
182 verbose $line
183 set line "**EOF**"
185 send_log "$line\n"
186 verbose $line
187 if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then {
188 send_log "bad trailer\n"
189 fail "objcopy -O srec"
190 } else {
191 if {[gets $file line] != -1} then {
192 send_log "garbage at end\n"
193 send_log "$line\n"
194 verbose $line
195 fail "objcopy -O srec"
196 } else {
197 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${srecfile}"]
198 if ![regexp "file format srec" $got] then {
199 send_log "objdump failed\n"
200 fail "objcopy -O srec"
201 } else {
202 pass "objcopy -O srec"
208 close $file
211 # Test setting and adjusting the start address. We only test this
212 # while generating S records, because we may not be able to set the
213 # start address for other object file formats, and the S record case
214 # is the only useful one anyhow.
216 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $tempfile"]
217 if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
218 perror "objdump can not recognize bintest.o"
219 set origstart ""
220 } else {
221 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --set-start 0x7654 $tempfile ${copyfile}.srec"]
222 if ![string match "" $got] then {
223 fail "objcopy --set-start"
224 } else {
225 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
226 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
227 fail "objcopy --set-start"
228 } else {
229 if {$srecstart != 0x7654} then {
230 send_log "$srecstart != 0x7654\n"
231 fail "objcopy --set-start"
232 } else {
233 pass "objcopy --set-start"
238 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-start 0x123 $tempfile ${copyfile}.srec"]
239 if ![string match "" $got] then {
240 fail "objcopy --adjust-start"
241 } else {
242 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
243 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
244 fail "objcopy --adjust-start"
245 } else {
246 if {$srecstart != $origstart + 0x123} then {
247 send_log "$srecstart != $origstart + 0x123\n"
248 fail "objcopy --adjust-start"
249 } else {
250 pass "objcopy --adjust-start"
256 # Test adjusting the overall VMA, and adjusting the VMA of a
257 # particular section. We again only test this when generating S
258 # records.
260 set low ""
261 set lowname ""
263 set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $tempfile"]
265 set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)"
267 set got $headers
268 while {[regexp $headers_regexp $got all name size vma rest]} {
269 set vma 0x$vma
270 set size 0x$size
271 if {$size != 0} {
272 if {$low == "" || $vma < $low} {
273 set low $vma
274 set lowname $name
277 set got $rest
280 if {$low == "" || $origstart == ""} then {
281 perror "objdump can not recognize bintest.o"
282 } else {
283 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-vma 0x123 $tempfile ${copyfile}.srec"]
284 if ![string match "" $got] then {
285 fail "objcopy --adjust-vma"
286 } else {
287 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"]
288 set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
289 if ![regexp $want $got all start vma] then {
290 fail "objcopy --adjust-vma"
291 } else {
292 set vma 0x$vma
293 if {$vma != $low + 0x123} then {
294 send_log "$vma != $low + 0x123\n"
295 fail "objcopy --adjust-vma"
296 } else {
297 if {$start != $origstart + 0x123} then {
298 send_log "$start != $origstart + 0x123\n"
299 fail "objcopy --adjust-vma"
300 } else {
301 pass "objcopy --adjust-vma"
307 set arg ""
308 set got $headers
309 while {[regexp $headers_regexp $got all name size vma rest]} {
310 set vma 0x$vma
311 if {$vma == $low} then {
312 set arg "$arg --adjust-section-vma $name+4"
314 set got $rest
317 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $arg $tempfile ${copyfile}.srec"]
318 if ![string match "" $got] then {
319 fail "objcopy --adjust-section-vma +"
320 } else {
321 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
322 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
323 if ![regexp $want $got all vma] then {
324 fail "objcopy --adjust-section-vma +"
325 } else {
326 set vma 0x$vma
327 if {$vma != $low + 4} then {
328 send_log "$vma != $low + 4\n"
329 fail "objcopy --adjust-section-vma +"
330 } else {
331 pass "objcopy --adjust-section-vma +"
336 regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
337 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $argeq $tempfile ${copyfile}.srec"]
338 if ![string match "" $got] then {
339 fail "objcopy --adjust-section-vma ="
340 } else {
341 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
342 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
343 if ![regexp $want $got all vma] then {
344 fail "objcopy --adjust-section-vma ="
345 } else {
346 set vma 0x$vma
347 if {$vma != $low + 4} then {
348 send_log "$vma != $low + 4\n"
349 fail "objcopy --adjust-section-vma ="
350 } else {
351 pass "objcopy --adjust-section-vma ="
357 # Test stripping an object.
359 proc strip_test { } {
360 global AR
361 global CC
362 global STRIP
363 global STRIPFLAGS
364 global NM
365 global NMFLAGS
366 global srcdir
367 global subdir
369 set test "strip"
371 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
372 untested $test
373 return
376 if [is_remote host] {
377 set archive libstrip.a
378 set objfile [remote_download host tmpdir/testprog.o]
379 remote_file host delete $archive
380 } else {
381 set archive tmpdir/libstrip.a
382 set objfile tmpdir/testprog.o
385 remote_file build delete tmpdir/libstrip.a
387 set exec_output [binutils_run $AR "rc $archive ${objfile}"]
388 if ![string match "" $exec_output] {
389 fail $test
390 return
393 set exec_output [binutils_run $STRIP "-g $archive"]
394 if ![string match "" $exec_output] {
395 fail $test
396 return
399 set exec_output [binutils_run $STRIP "$STRIPFLAGS $archive"]
400 if ![string match "" $exec_output] {
401 fail $test
402 return
405 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
406 untested $test
407 return
410 if [is_remote host] {
411 set objfile [remote_download host tmpdir/testprog.o]
412 } else {
413 set objfile tmpdir/testprog.o
416 set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"]
417 if ![string match "" $exec_output] {
418 fail $test
419 return
422 set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"]
423 if ![string match "*: no symbols*" $exec_output] {
424 fail $test
425 return
428 pass $test
431 strip_test
433 # Test stripping an object file with saving a symbol
435 proc strip_test_with_saving_a_symbol { } {
436 global CC
437 global STRIP
438 global STRIPFLAGS
439 global NM
440 global NMFLAGS
441 global srcdir
442 global subdir
444 set test "strip with saving a symbol"
446 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
447 untested $test
448 return
451 if [is_remote host] {
452 set objfile [remote_download host tmpdir/testprog.o]
453 } else {
454 set objfile tmpdir/testprog.o
457 set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main -K _main $objfile"]
458 if ![string match "" $exec_output] {
459 fail $test
460 return
463 set exec_output [binutils_run $NM "$NMFLAGS $objfile"]
464 if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \
465 && ![regexp {^([0-9a-fA-F]+)?[ ]+T _main} $exec_output]} {
466 fail $test
467 return
470 pass $test
473 strip_test_with_saving_a_symbol
475 # Build a final executable.
477 if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } {
478 set test_prog "testprog.exe"
479 } else {
480 set test_prog "testprog"
483 proc copy_setup { } {
484 global srcdir
485 global subdir
486 global gcc_gas_flag
487 global test_prog
489 set res [build_wrapper testglue.o]
490 set flags { debug }
492 if { [istarget *-*-uclinux*] } {
493 return 1
496 if { $res != "" } {
497 lappend flags "additional_flags=[lindex $res 1]"
498 set add_libs "testglue.o"
499 } else {
500 set add_libs ""
503 if { [istarget *-*-linux*] } {
504 foreach i $gcc_gas_flag {
505 set flags "additional_flags=$i $flags"
508 if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/$test_prog executable $flags] != "" } {
509 return 2
512 set result [remote_load target tmpdir/$test_prog]
513 set status [lindex $result 0]
515 if { $status != "pass" } {
516 send_log "cannot run executable, status = ${status}\n"
517 return 3
520 return 0
523 # Test copying an executable.
525 proc copy_executable { prog flags test1 test2 } {
526 global test_prog
528 if [is_remote host] {
529 set testfile [remote_download host tmpdir/$test_prog]
530 set testcopy copyprog
531 } else {
532 set testfile tmpdir/$test_prog
533 set testcopy tmpdir/copyprog
535 remote_file host delete $testcopy
537 set exec_output [binutils_run $prog "$flags $testfile $testcopy"]
539 if ![string match "" $exec_output] {
540 fail $test1
541 if [string match "" $test2] {
542 return
544 fail $test2
545 return
548 if [is_remote host] {
549 remote_upload host $testcopy tmpdir/copyprog
552 set status [remote_exec build "cmp" "tmpdir/$test_prog tmpdir/copyprog"]
553 set exec_output [lindex $status 1]
555 if [string match "" $exec_output] then {
556 pass $test1
557 } else {
558 send_log "$exec_output\n"
559 verbose "$exec_output"
561 # This will fail for many reasons. For example, it will most
562 # likely fail if a non-GNU linker is used. Therefore, we do
563 # not insist that it pass. If you are using an assembler and
564 # linker based on the same BFD as objcopy, it is worth
565 # investigating to see why this failure occurs. If we are
566 # cross compiling, we assume that a GNU linker is being used,
567 # and expect it to succeed.
568 if {[isnative]} then {
569 setup_xfail "*-*-*"
572 # This also fails for mips*-*-elf targets. See elf32-mips.c
573 # mips_elf_sym_is_global.
574 setup_xfail "mips*-*-elf"
576 setup_xfail "*arm*-*-coff"
577 setup_xfail "xscale-*-coff"
578 setup_xfail "arm*-*-pe"
579 setup_xfail "thumb*-*-coff"
580 setup_xfail "thumb*-*-pe"
582 fail $test1
585 if [string match "" $test2] {
586 return
589 set output [remote_load target tmpdir/copyprog]
590 set status [lindex $output 0]
591 if { $status != "pass" } {
592 fail $test2
593 } else {
594 pass $test2
598 # Test stripping an executable
600 proc strip_executable { prog flags test } {
601 global NM
602 global NMFLAGS
604 remote_download build tmpdir/copyprog tmpdir/striprog
605 if [is_remote host] {
606 set copyfile [remote_download host tmpdir/striprog]
607 } else {
608 set copyfile tmpdir/striprog
611 set exec_output [binutils_run $prog "$flags ${copyfile}"]
612 if ![string match "" $exec_output] {
613 fail $test
614 return
617 if [is_remote host] {
618 remote_upload host ${copyfile} tmpdir/striprog
621 set result [remote_load target tmpdir/striprog]
622 set status [lindex $result 0]
623 if { $status != "pass" } {
624 fail $test
625 return
628 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
629 if ![string match "*: no symbols*" $exec_output] {
630 fail $test
631 return
633 pass $test
636 # Test stripping an executable with saving a symbol
638 proc strip_executable_with_saving_a_symbol { prog flags test } {
639 global NM
640 global NMFLAGS
642 remote_download build tmpdir/copyprog tmpdir/striprog
643 if [is_remote host] {
644 set copyfile [remote_download host tmpdir/striprog]
645 } else {
646 set copyfile tmpdir/striprog
649 set exec_output [binutils_run $prog "$flags ${copyfile}"]
650 if ![string match "" $exec_output] {
651 fail $test
652 return
655 if [is_remote host] {
656 remote_upload host ${copyfile} tmpdir/striprog
659 set result [remote_load target tmpdir/striprog]
660 set status [lindex $result 0]
661 if { $status != "pass" } {
662 fail $test
663 return
666 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
667 if { [istarget mmix-knuth-mmixware] } {
668 # Whenever there's a symbol in the mmo format, there's the symbol
669 # Main, so remove it manually from the expected output for sake of
670 # this test.
672 # Using "" not {} to get the \n and \r translated.
673 regsub "^\[0-9a-fA-F\]+\[ \]+T Main\[\n\r\]+" $exec_output "" exec_output
676 if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \
677 && ![regexp {^([0-9a-fA-F]+)?[ ]+[TD] _main} $exec_output]} {
678 fail $test
679 return
681 pass $test
684 # Test keeping only debug symbols of an executable
686 proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } {
687 global NM
688 global NMFLAGS
690 remote_download build tmpdir/copyprog tmpdir/striprog
691 if [is_remote host] {
692 set copyfile [remote_download host tmpdir/striprog]
693 } else {
694 set copyfile tmpdir/striprog
697 set exec_output [binutils_run $prog1 "$flags1 ${copyfile}"]
698 if ![string match "" $exec_output] {
699 fail $test1
700 return
702 pass $test1
704 set exec_output [binutils_run $prog2 "$flags2 ${copyfile}"]
705 if ![string match "" $exec_output] {
706 fail $test2
707 return
709 pass $test2
712 set test1 "simple objcopy of executable"
713 set test2 "run objcopy of executable"
714 set test3 "run stripped executable"
715 set test4 "run stripped executable with saving a symbol"
716 set test5 "keep only debug data"
717 set test6 "simple objcopy of debug data"
719 switch [copy_setup] {
720 "1" {
721 # do nothing
723 "2" {
724 untested $test1
725 untested $test2
726 untested $test3
727 untested $test4
728 untested $test5
729 untested $test6
731 "3" {
732 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" ""
733 unsupported $test2
734 unsupported $test3
735 unsupported $test4
736 unsupported $test5
737 unsupported $test6
739 "0" {
740 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2"
741 strip_executable "$STRIP" "$STRIPFLAGS" "$test3"
742 strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test4"
743 keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test5" \
744 "$OBJCOPY" "$OBJCOPYFLAGS" "$test6"
748 proc objcopy_test_readelf {testname srcfile} {
749 global OBJCOPY
750 global OBJCOPYFLAGS
751 global READELF
752 global srcdir
753 global subdir
755 if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then {
756 unresolved "objcopy ($testname)"
757 return
760 verbose -log "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"
761 set exec_output [remote_exec host "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"]
762 if { [lindex $exec_output 0] != 0
763 || ![string match "" [lindex $exec_output 1]] } then {
764 fail "objcopy ($testname)"
765 return
768 verbose -log "$READELF -a tmpdir/bintest.o > tmpdir/bintest.o.out"
769 set exec_output [remote_exec host "$READELF -a tmpdir/bintest.o" "" "/dev/null" "tmpdir/bintest.o.out"]
770 if { [lindex $exec_output 0] != 0 } then {
771 unresolved "objcopy ($testname)"
772 return
774 set exec_output [prune_warnings [lindex $exec_output 1]]
775 if ![string match "" $exec_output] then {
776 unresolved "objcopy ($testname)"
777 return
780 verbose -log "$READELF -a tmpdir/copy.o > tmpdir/copy.o.out"
781 set exec_output [remote_exec host "$READELF -a tmpdir/copy.o" "" "/dev/null" "tmpdir/copy.o.out"]
782 if { [lindex $exec_output 0] != 0 } then {
783 unresolved "objcopy ($testname)"
784 return
786 set exec_output [prune_warnings [lindex $exec_output 1]]
787 if ![string match "" $exec_output] then {
788 unresolved "objcopy ($testname)"
789 return
792 verbose -log "diff tmpdir/bintest.o.out tmpdir/copy.o.out"
793 catch "exec diff tmpdir/bintest.o.out tmpdir/copy.o.out" exec_output
794 set exec_output [prune_warnings $exec_output]
796 if [string match "" $exec_output] then {
797 pass "objcopy ($testname)"
798 } else {
799 fail "objcopy ($testname)"
803 # ia64 specific tests
804 if { ([istarget "ia64-*-elf*"]
805 || [istarget "ia64-*-linux*"]) } {
806 objcopy_test "ia64 link order" link-order.s
809 # ELF specific tests
810 if [is_elf_format] {
811 objcopy_test "ELF unknown section type" unknown.s
812 objcopy_test_readelf "ELF group" group.s
813 run_dump_test "copy-1"
816 run_dump_test "copy-2"
817 run_dump_test "copy-3"
819 if [is_elf_format] {
820 run_dump_test "strip-1"
821 run_dump_test "strip-2"
822 run_dump_test "strip-3"
824 if { [istarget "i*86-*"] || [istarget "x86_64-*-*"] } {
825 # Check to make sure we don't strip a symbol named in relocations.
826 set test "objcopy keeps symbols needed by relocs"
828 set srcfile $srcdir/$subdir/needed-by-reloc.s
830 if {![binutils_assemble $srcfile tmpdir/bintest.o]} then {
831 unresolved $test
832 } else {
833 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS --strip-symbol=foo tmpdir/bintest.o ${copyfile}.o"]
835 if [regexp "not stripping symbol `foo' because it is named in a relocation" $got] {
836 pass $test
837 } else {
838 fail $test
843 run_dump_test "localize-hidden-1"
845 run_dump_test "localize-hidden-2"