Improve binutils testsuite coverage for GNU/Hurd.
[binutils.git] / binutils / testsuite / binutils-all / objcopy.exp
blob0e2345e5cd1fbdc48d43b11357f8c23a92af3f86
1 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2 # 2004, 2006, 2007, 2009, 2010
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-*-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 interleaved copy of multiple byte width
149 set sequence_file sequence_file
150 set file [open ${sequence_file} w]
151 puts ${file} "12345678"
152 close ${file}
154 if [is_remote host] {
155 remote_upload host ${sequence_file} tmpdir/sequence_file
156 set sequence_file tmpdir/sequence_file
159 set got [binutils_run $OBJCOPY "-I binary -i 4 -b 0 --interleave-width 2 ${sequence_file} ${copyfile}"]
161 if ![string match "" $got] then {
162 fail "objcopy -i --interleave-width"
163 } else {
164 if [is_remote host] {
165 remote_upload host ${copyfile} tmpdir/interleave_output
166 set interleave_output tmpdir/interleave_output
167 } else {
168 set interleave_output ${copyfile}
171 set file [open ${interleave_output} r]
172 gets $file line
173 send_log "$line\n"
174 verbose $line
176 if ![string match "1256" $line] then {
177 fail "objcopy -i --interleave-width"
179 pass "objcopy -i --interleave-width"
181 close $file
184 # Test generating S records.
186 # We make the srec filename 8.3 compatible. Note that the header string
187 # matched against depends on the name of the file. Ugh.
189 if [is_remote host] {
190 set srecfile copy.sre
191 set header_string S00B0000636F70792E737265C1
192 } else {
193 set srecfile ${copyfile}.srec
194 set header_string S0130000746D706469722F636F70792E7372656397
197 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"]
199 if ![string match "" $got] then {
200 fail "objcopy -O srec"
201 } else {
202 if [is_remote host] {
203 remote_upload host ${srecfile} tmpdir/copy.srec
204 set srecfile tmpdir/copy.srec
206 set file [open ${srecfile} r]
208 # The first S record is fixed by the file name we are using.
209 gets $file line
210 send_log "$line\n"
211 verbose $line
212 if ![regexp "$header_string.*" $line] {
213 send_log "bad header\n"
214 fail "objcopy -O srec"
215 } else {
216 while {[gets $file line] != -1 \
217 && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} {
218 send_log "$line\n"
219 verbose $line
220 set line "**EOF**"
222 send_log "$line\n"
223 verbose $line
224 if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then {
225 send_log "bad trailer\n"
226 fail "objcopy -O srec"
227 } else {
228 if {[gets $file line] != -1} then {
229 send_log "garbage at end\n"
230 send_log "$line\n"
231 verbose $line
232 fail "objcopy -O srec"
233 } else {
234 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${srecfile}"]
235 if ![regexp "file format srec" $got] then {
236 send_log "objdump failed\n"
237 fail "objcopy -O srec"
238 } else {
239 pass "objcopy -O srec"
245 close $file
248 # Test setting and adjusting the start address. We only test this
249 # while generating S records, because we may not be able to set the
250 # start address for other object file formats, and the S record case
251 # is the only useful one anyhow.
253 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $tempfile"]
254 if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
255 perror "objdump can not recognize bintest.o"
256 set origstart ""
257 } else {
258 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --set-start 0x7654 $tempfile ${copyfile}.srec"]
259 if ![string match "" $got] then {
260 fail "objcopy --set-start"
261 } else {
262 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
263 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
264 fail "objcopy --set-start"
265 } else {
266 if {$srecstart != 0x7654} then {
267 send_log "$srecstart != 0x7654\n"
268 fail "objcopy --set-start"
269 } else {
270 pass "objcopy --set-start"
275 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-start 0x123 $tempfile ${copyfile}.srec"]
276 if ![string match "" $got] then {
277 fail "objcopy --adjust-start"
278 } else {
279 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
280 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
281 fail "objcopy --adjust-start"
282 } else {
283 if {$srecstart != $origstart + 0x123} then {
284 send_log "$srecstart != $origstart + 0x123\n"
285 fail "objcopy --adjust-start"
286 } else {
287 pass "objcopy --adjust-start"
293 # Test adjusting the overall VMA, and adjusting the VMA of a
294 # particular section. We again only test this when generating S
295 # records.
297 set low ""
298 set lowname ""
300 set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $tempfile"]
302 set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)"
304 set got $headers
305 while {[regexp $headers_regexp $got all name size vma rest]} {
306 set vma 0x$vma
307 set size 0x$size
308 if {$size != 0} {
309 if {$low == "" || $vma < $low} {
310 set low $vma
311 set lowname $name
314 set got $rest
317 if {$low == "" || $origstart == ""} then {
318 perror "objdump can not recognize bintest.o"
319 } else {
320 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-vma 0x123 $tempfile ${copyfile}.srec"]
321 if ![string match "" $got] then {
322 fail "objcopy --adjust-vma"
323 } else {
324 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"]
325 set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
326 if ![regexp $want $got all start vma] then {
327 fail "objcopy --adjust-vma"
328 } else {
329 set vma 0x$vma
330 if {$vma != $low + 0x123} then {
331 send_log "$vma != $low + 0x123\n"
332 fail "objcopy --adjust-vma"
333 } else {
334 if {$start != $origstart + 0x123} then {
335 send_log "$start != $origstart + 0x123\n"
336 fail "objcopy --adjust-vma"
337 } else {
338 pass "objcopy --adjust-vma"
344 set arg ""
345 set got $headers
346 while {[regexp $headers_regexp $got all name size vma rest]} {
347 set vma 0x$vma
348 if {$vma == $low} then {
349 set arg "$arg --adjust-section-vma $name+4"
351 set got $rest
354 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $arg $tempfile ${copyfile}.srec"]
355 if ![string match "" $got] then {
356 fail "objcopy --adjust-section-vma +"
357 } else {
358 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
359 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
360 if ![regexp $want $got all vma] then {
361 fail "objcopy --adjust-section-vma +"
362 } else {
363 set vma 0x$vma
364 if {$vma != $low + 4} then {
365 send_log "$vma != $low + 4\n"
366 fail "objcopy --adjust-section-vma +"
367 } else {
368 pass "objcopy --adjust-section-vma +"
373 regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
374 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $argeq $tempfile ${copyfile}.srec"]
375 if ![string match "" $got] then {
376 fail "objcopy --adjust-section-vma ="
377 } else {
378 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
379 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
380 if ![regexp $want $got all vma] then {
381 fail "objcopy --adjust-section-vma ="
382 } else {
383 set vma 0x$vma
384 if {$vma != $low + 4} then {
385 send_log "$vma != $low + 4\n"
386 fail "objcopy --adjust-section-vma ="
387 } else {
388 pass "objcopy --adjust-section-vma ="
394 # Test stripping an object.
396 proc strip_test { } {
397 global AR
398 global CC
399 global STRIP
400 global STRIPFLAGS
401 global NM
402 global NMFLAGS
403 global srcdir
404 global subdir
406 set test "strip"
408 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
409 untested $test
410 return
413 if [is_remote host] {
414 set archive libstrip.a
415 set objfile [remote_download host tmpdir/testprog.o]
416 remote_file host delete $archive
417 } else {
418 set archive tmpdir/libstrip.a
419 set objfile tmpdir/testprog.o
422 remote_file build delete tmpdir/libstrip.a
424 set exec_output [binutils_run $AR "rc $archive ${objfile}"]
425 if ![string match "" $exec_output] {
426 fail $test
427 return
430 set exec_output [binutils_run $STRIP "-g $archive"]
431 if ![string match "" $exec_output] {
432 fail $test
433 return
436 set exec_output [binutils_run $STRIP "$STRIPFLAGS $archive"]
437 if ![string match "" $exec_output] {
438 fail $test
439 return
442 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
443 untested $test
444 return
447 if [is_remote host] {
448 set objfile [remote_download host tmpdir/testprog.o]
449 } else {
450 set objfile tmpdir/testprog.o
453 set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"]
454 if ![string match "" $exec_output] {
455 fail $test
456 return
459 set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"]
460 if ![string match "*: no symbols*" $exec_output] {
461 fail $test
462 return
465 pass $test
468 strip_test
470 # Test stripping an object file with saving a symbol
472 proc strip_test_with_saving_a_symbol { } {
473 global CC
474 global STRIP
475 global STRIPFLAGS
476 global NM
477 global NMFLAGS
478 global srcdir
479 global subdir
481 set test "strip with saving a symbol"
483 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
484 untested $test
485 return
488 if [is_remote host] {
489 set objfile [remote_download host tmpdir/testprog.o]
490 } else {
491 set objfile tmpdir/testprog.o
494 set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main -K _main $objfile"]
495 if ![string match "" $exec_output] {
496 fail $test
497 return
500 set exec_output [binutils_run $NM "$NMFLAGS $objfile"]
501 if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \
502 && ![regexp {^([0-9a-fA-F]+)?[ ]+T _main} $exec_output]} {
503 fail $test
504 return
507 pass $test
510 strip_test_with_saving_a_symbol
512 # Build a final executable.
514 if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } {
515 set test_prog "testprog.exe"
516 } else {
517 set test_prog "testprog"
520 proc copy_setup { } {
521 global srcdir
522 global subdir
523 global gcc_gas_flag
524 global test_prog
525 global host_triplet
527 set res [build_wrapper testglue.o]
528 set flags { debug }
530 if { [istarget *-*-uclinux*] } {
531 return 1
534 if { $res != "" } {
535 lappend flags "additional_flags=[lindex $res 1]"
536 set add_libs "testglue.o"
537 } else {
538 set add_libs ""
541 if { [istarget *-*-linux*]
542 || [istarget *-*-gnu*] } {
543 foreach i $gcc_gas_flag {
544 set flags "additional_flags=$i $flags"
547 if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/$test_prog executable $flags] != "" } {
548 return 2
551 set result [remote_load target tmpdir/$test_prog]
552 set status [lindex $result 0]
554 if { $status != "pass" } {
555 send_log "cannot run executable, status = ${status} on ${host_triplet}\n"
556 if { [istarget $host_triplet] } {
557 return 3
559 set status "pass"
562 return 0
565 # Test copying an executable.
567 proc copy_executable { prog flags test1 test2 } {
568 global test_prog
569 global host_triplet
571 if [is_remote host] {
572 set testfile [remote_download host tmpdir/$test_prog]
573 set testcopy copyprog
574 } else {
575 set testfile tmpdir/$test_prog
576 set testcopy tmpdir/copyprog
578 remote_file host delete $testcopy
580 set exec_output [binutils_run $prog "$flags $testfile $testcopy"]
582 if ![string match "" $exec_output] {
583 fail $test1
584 if [string match "" $test2] {
585 return
587 fail $test2
588 return
591 if [is_remote host] {
592 remote_upload host $testcopy tmpdir/copyprog
595 set status [remote_exec build "cmp" "tmpdir/$test_prog tmpdir/copyprog"]
596 set exec_output [lindex $status 1]
598 if [string match "" $exec_output] then {
599 pass $test1
600 } else {
601 send_log "$exec_output\n"
602 verbose "$exec_output"
604 # This will fail for many reasons. For example, it will most
605 # likely fail if a non-GNU linker is used. Therefore, we do
606 # not insist that it pass. If you are using an assembler and
607 # linker based on the same BFD as objcopy, it is worth
608 # investigating to see why this failure occurs. If we are
609 # cross compiling, we assume that a GNU linker is being used,
610 # and expect it to succeed.
611 if {[isnative]} then {
612 setup_xfail "*-*-*"
615 # This also fails for mips*-*-elf targets. See elf32-mips.c
616 # mips_elf_sym_is_global.
617 setup_xfail "mips*-*-elf"
619 setup_xfail "*arm*-*-coff"
620 setup_xfail "xscale-*-coff"
621 setup_xfail "arm*-*-pe"
622 setup_xfail "thumb*-*-coff"
623 setup_xfail "thumb*-*-pe"
624 setup_xfail "*-*-mingw*"
625 setup_xfail "*-*-cygwin*"
627 fail $test1
630 if [string match "" $test2] {
631 return
634 set output [remote_load target tmpdir/copyprog]
635 set status [lindex $output 0]
636 if { ![istarget $host_triplet] } {
637 set status "pass"
639 if { $status != "pass" } {
640 fail $test2
641 } else {
642 pass $test2
646 # Test stripping an executable
648 proc strip_executable { prog flags test } {
649 global NM
650 global NMFLAGS
651 global host_triplet
653 remote_file build delete tmpdir/striprog
654 remote_download build tmpdir/copyprog tmpdir/striprog
655 if [is_remote host] {
656 set copyfile [remote_download host tmpdir/striprog]
657 } else {
658 set copyfile tmpdir/striprog
661 set exec_output [binutils_run $prog "$flags ${copyfile}"]
662 if ![string match "" $exec_output] {
663 fail $test
664 return
667 if [is_remote host] {
668 remote_upload host ${copyfile} tmpdir/striprog
671 set result [remote_load target tmpdir/striprog]
672 set status [lindex $result 0]
673 if { ![istarget $host_triplet] } {
674 set status "pass"
676 if { $status != "pass" } {
677 fail $test
678 return
681 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
682 if ![string match "*: no symbols*" $exec_output] {
683 fail $test
684 return
686 pass $test
689 # Test stripping an executable with saving a symbol
691 proc strip_executable_with_saving_a_symbol { prog flags test } {
692 global NM
693 global NMFLAGS
694 global host_triplet
696 remote_file build delete tmpdir/striprog
697 remote_download build tmpdir/copyprog tmpdir/striprog
698 if [is_remote host] {
699 set copyfile [remote_download host tmpdir/striprog]
700 } else {
701 set copyfile tmpdir/striprog
704 set exec_output [binutils_run $prog "$flags ${copyfile}"]
705 if ![string match "" $exec_output] {
706 fail $test
707 return
710 if [is_remote host] {
711 remote_upload host ${copyfile} tmpdir/striprog
714 set result [remote_load target tmpdir/striprog]
715 set status [lindex $result 0]
716 if { ![istarget $host_triplet] } {
717 set status "pass"
719 if { $status != "pass" } {
720 fail $test
721 return
724 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
725 if { [istarget mmix-knuth-mmixware] } {
726 # Whenever there's a symbol in the mmo format, there's the symbol
727 # Main, so remove it manually from the expected output for sake of
728 # this test.
730 # Using "" not {} to get the \n and \r translated.
731 regsub "^\[0-9a-fA-F\]+\[ \]+T Main\[\n\r\]+" $exec_output "" exec_output
734 if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \
735 && ![regexp {^([0-9a-fA-F]+)?[ ]+[TD] _main} $exec_output]} {
736 fail $test
737 return
739 pass $test
742 # Test keeping only debug symbols of an executable
744 proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } {
745 global NM
746 global NMFLAGS
748 remote_file build delete tmpdir/striprog
749 remote_download build tmpdir/copyprog tmpdir/striprog
750 if [is_remote host] {
751 set copyfile [remote_download host tmpdir/striprog]
752 } else {
753 set copyfile tmpdir/striprog
756 set exec_output [binutils_run $prog1 "$flags1 ${copyfile}"]
757 if ![string match "" $exec_output] {
758 fail $test1
759 return
761 pass $test1
763 set exec_output [binutils_run $prog2 "$flags2 ${copyfile}"]
764 if ![string match "" $exec_output] {
765 fail $test2
766 return
768 pass $test2
771 set test1 "simple objcopy of executable"
772 set test2 "run objcopy of executable"
773 set test3 "run stripped executable"
774 set test4 "run stripped executable with saving a symbol"
775 set test5 "keep only debug data"
776 set test6 "simple objcopy of debug data"
778 switch [copy_setup] {
779 "1" {
780 # do nothing
782 "2" {
783 untested $test1
784 untested $test2
785 untested $test3
786 untested $test4
787 untested $test5
788 untested $test6
790 "3" {
791 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" ""
792 unsupported $test2
793 unsupported $test3
794 unsupported $test4
795 unsupported $test5
796 unsupported $test6
798 "0" {
799 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2"
800 strip_executable "$STRIP" "$STRIPFLAGS" "$test3"
801 strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test4"
802 keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test5" \
803 "$OBJCOPY" "$OBJCOPYFLAGS" "$test6"
807 proc objcopy_test_readelf {testname srcfile} {
808 global OBJCOPY
809 global OBJCOPYFLAGS
810 global READELF
811 global srcdir
812 global subdir
814 if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then {
815 unresolved "objcopy ($testname)"
816 return
819 verbose -log "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"
820 set exec_output [remote_exec host "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"]
821 if { [lindex $exec_output 0] != 0
822 || ![string match "" [lindex $exec_output 1]] } then {
823 fail "objcopy ($testname)"
824 return
827 verbose -log "$READELF -a tmpdir/bintest.o > tmpdir/bintest.o.out"
828 set exec_output [remote_exec host "$READELF -a tmpdir/bintest.o" "" "/dev/null" "tmpdir/bintest.o.out"]
829 if { [lindex $exec_output 0] != 0 } then {
830 unresolved "objcopy ($testname)"
831 return
833 set exec_output [prune_warnings [lindex $exec_output 1]]
834 if ![string match "" $exec_output] then {
835 unresolved "objcopy ($testname)"
836 return
839 verbose -log "$READELF -a tmpdir/copy.o > tmpdir/copy.o.out"
840 set exec_output [remote_exec host "$READELF -a tmpdir/copy.o" "" "/dev/null" "tmpdir/copy.o.out"]
841 if { [lindex $exec_output 0] != 0 } then {
842 unresolved "objcopy ($testname)"
843 return
845 set exec_output [prune_warnings [lindex $exec_output 1]]
846 if ![string match "" $exec_output] then {
847 unresolved "objcopy ($testname)"
848 return
851 verbose -log "diff tmpdir/bintest.o.out tmpdir/copy.o.out"
852 catch "exec diff tmpdir/bintest.o.out tmpdir/copy.o.out" exec_output
853 set exec_output [prune_warnings $exec_output]
855 if [string match "" $exec_output] then {
856 pass "objcopy ($testname)"
857 } else {
858 fail "objcopy ($testname)"
862 # ia64 specific tests
863 if { ([istarget "ia64-*-elf*"]
864 || [istarget "ia64-*-linux*"]) } {
865 objcopy_test "ia64 link order" link-order.s
868 # ELF specific tests
869 if [is_elf_format] {
870 objcopy_test "ELF unknown section type" unknown.s
871 objcopy_test_readelf "ELF group" group.s
872 objcopy_test_readelf "ELF group" group-2.s
873 objcopy_test_readelf "ELF group" group-3.s
874 objcopy_test_readelf "ELF group" group-4.s
875 run_dump_test "group-5"
876 run_dump_test "copy-1"
877 run_dump_test "note-1"
880 run_dump_test "copy-2"
881 run_dump_test "copy-3"
882 run_dump_test "copy-4"
884 if [is_elf_format] {
885 run_dump_test "strip-1"
886 run_dump_test "strip-2"
887 run_dump_test "strip-3"
888 run_dump_test "strip-4"
889 run_dump_test "strip-5"
890 run_dump_test "strip-6"
891 run_dump_test "strip-7"
892 run_dump_test "strip-8"
893 run_dump_test "strip-9"
894 if { ![istarget "*-*-hpux*"]
895 && ![istarget "msp*-*-*"] } {
896 run_dump_test "strip-10"
899 if { [istarget "i*86-*"] || [istarget "x86_64-*-*"] } {
900 # Check to make sure we don't strip a symbol named in relocations.
901 set test "objcopy keeps symbols needed by relocs"
903 set srcfile $srcdir/$subdir/needed-by-reloc.s
905 if {![binutils_assemble $srcfile tmpdir/bintest.o]} then {
906 unresolved $test
907 } else {
908 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS --strip-symbol=foo tmpdir/bintest.o ${copyfile}.o"]
910 if [regexp "not stripping symbol `foo' because it is named in a relocation" $got] {
911 pass $test
912 } else {
913 fail $test
918 run_dump_test "localize-hidden-1"
919 run_dump_test "testranges"
920 run_dump_test "testranges-ia64"
922 run_dump_test "add-section"
923 run_dump_test "add-empty-section"
925 run_dump_test "exclude-1a"
926 run_dump_test "exclude-1b"
928 run_dump_test "localize-hidden-2"