1 # Copyright (C) 1994, 95, 96, 97, 1998 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
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.
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
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@prep.ai.mit.edu
20 # Written by Ian Lance Taylor <ian@cygnus.com>
22 if ![is_remote host] {
23 if {[which $OBJCOPY] == 0} then {
24 perror "$OBJCOPY does not exist"
29 send_user "Version [binutil_version $OBJCOPY]"
31 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
33 unresolved "objcopy (simple copy)"
37 if ![is_remote host] {
38 set tempfile tmpdir/bintest.o;
39 set copyfile tmpdir/copy;
41 set tempfile [remote_download host tmpdir/bintest.o]
45 # Test that objcopy does not modify a file when copying it.
47 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS $tempfile ${copyfile}.o"]
49 if ![string match "" $got] then {
50 fail "objcopy (simple copy)"
52 send_log "cmp $tempfile ${copyfile}.o\n"
53 verbose "cmp $tempfile ${copyfile}.o"
55 set src1 tmpdir/bintest.o
56 set src2 tmpdir/copy.o
57 remote_upload host $tempfile $src1;
58 remote_upload host ${copyfile}.o $src2;
61 set src2 ${copyfile}.o
63 set status [remote_exec build cmp "${src1} ${src2}"];
64 set exec_output [lindex $status 1];
65 set exec_output [prune_warnings $exec_output]
67 # On some systems the result of objcopy will not be identical.
68 # Usually this is just because gas isn't using bfd to write the files
69 # in the first place, and may order things a little differently.
70 # Those systems should use setup_xfail here.
72 setup_xfail "sh-*-coff" "sh-*-hms"
73 setup_xfail "m68*-*-hpux*" "m68*-*-sunos*" "m68*-*-coff" "m68*-*-vxworks*"
74 setup_xfail "m68*-ericsson-ose" "m68k*-motorola-sysv*"
75 setup_xfail "i*86-*-linuxaout*" "i*86-*-aout*"
76 setup_xfail "i*86-*-sysv3" "i*86-*-isc*" "i*86-*-sco*" "i*86-*-coff"
77 setup_xfail "i*86-*-aix*" "i*86-*-go32*"
78 setup_xfail "a29k-*-udi" "a29k-*-coff" "a29k-*-vxworks*"
79 setup_xfail "i960-*-coff"
80 setup_xfail "h8300-*-hms" "h8300-*-coff"
81 setup_xfail "h8500-*-hms" "h8500-*-coff"
82 setup_xfail "hppa*-*-*"
83 clear_xfail "hppa*-*-*elf*"
84 setup_xfail "m88*-*-coff" "m88*-motorola-sysv*"
85 setup_xfail "z8*-*-coff"
87 if [string match "" $exec_output] then {
88 pass "objcopy (simple copy)"
90 send_log "$exec_output\n"
91 verbose "$exec_output" 1
93 # On OSF/1, this succeeds with gas and fails with /bin/as.
94 setup_xfail "alpha*-*-osf*"
96 # This fails for COFF i960-vxworks targets.
97 setup_xfail "i960-*-vxworks*"
99 fail "objcopy (simple copy)"
103 # Test generating S records.
105 # We make the srec filename 8.3 compatible. Note that the header string
106 # matched against depends on the name of the file. Ugh.
108 if [is_remote host] {
109 set srecfile copy.sre
110 set header_string S00B0000636F70792E737265C1
112 set srecfile ${copyfile}.srec
113 set header_string S0130000746D706469722F636F70792E7372656397
116 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"]
118 if ![string match "" $got] then {
119 fail "objcopy -O srec"
121 if [is_remote host] {
122 remote_upload host ${srecfile} tmpdir/copy.srec;
123 set srecfile tmpdir/copy.srec;
125 set file [open ${srecfile} r]
127 # The first S record is fixed by the file name we are using.
131 if ![regexp "$header_string.*" $line] {
132 send_log "bad header\n"
133 fail "objcopy -O srec"
135 while {[gets $file line] != -1 \
136 && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} {
143 if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then {
144 send_log "bad trailer\n"
145 fail "objcopy -O srec"
147 if {[gets $file line] != -1} then {
148 send_log "garbage at end\n"
151 fail "objcopy -O srec"
153 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
154 if ![regexp "file format srec" $got] then {
155 send_log "objdump failed\n"
156 fail "objcopy -O srec"
158 pass "objcopy -O srec"
167 # Test setting and adjusting the start address. We only test this
168 # while generating S records, because we may not be able to set the
169 # start address for other object file formats, and the S record case
170 # is the only useful one anyhow.
172 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $tempfile"]
173 if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
174 perror "objdump can not recognize bintest.o"
177 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec --set-start 0x7654"]
178 if ![string match "" $got] then {
179 fail "objcopy --set-start"
181 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
182 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
183 fail "objcopy --set-start"
185 if {$srecstart != 0x7654} then {
186 send_log "$srecstart != 0x7654\n"
187 fail "objcopy --set-start"
189 pass "objcopy --set-start"
194 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec --adjust-start 0x123"]
195 if ![string match "" $got] then {
196 fail "objcopy --adjust-start"
198 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
199 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
200 fail "objcopy --adjust-start"
202 if {$srecstart != $origstart + 0x123} then {
203 send_log "$srecstart != $origstart + 0x123\n"
204 fail "objcopy --adjust-start"
206 pass "objcopy --adjust-start"
212 # Test adjusting the overall VMA, and adjusting the VMA of a
213 # particular section. We again only test this when generating S
219 set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $tempfile"]
221 set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)"
224 while {[regexp $headers_regexp $got all name size vma rest]} {
228 if {$low == "" || $vma < $low} {
236 if {$low == "" || $origstart == ""} then {
237 perror "objdump can not recognize bintest.o"
239 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec --adjust-vma 0x123"]
240 if ![string match "" $got] then {
241 fail "objcopy --adjust-vma"
243 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"]
244 set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
245 if ![regexp $want $got all start vma] then {
246 fail "objcopy --adjust-vma"
249 if {$vma != $low + 0x123} then {
250 send_log "$vma != $low + 0x123\n"
251 fail "objcopy --adjust-vma"
253 if {$start != $origstart + 0x123} then {
254 send_log "$start != $origstart + 0x123\n"
255 fail "objcopy --adjust-vma"
257 pass "objcopy --adjust-vma"
265 while {[regexp $headers_regexp $got all name size vma rest]} {
267 if {$vma == $low} then {
268 set arg "$arg --adjust-section-vma $name+4"
273 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec $arg"]
274 if ![string match "" $got] then {
275 fail "objcopy --adjust-section-vma +"
277 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
278 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
279 if ![regexp $want $got all vma] then {
280 fail "objcopy --adjust-section-vma +"
283 if {$vma != $low + 4} then {
284 send_log "$vma != $low + 4\n"
285 fail "objcopy --adjust-section-vma +"
287 pass "objcopy --adjust-section-vma +"
292 regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
293 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec $argeq"]
294 if ![string match "" $got] then {
295 fail "objcopy --adjust-section-vma ="
297 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
298 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
299 if ![regexp $want $got all vma] then {
300 fail "objcopy --adjust-section-vma ="
303 if {$vma != $low + 4} then {
304 send_log "$vma != $low + 4\n"
305 fail "objcopy --adjust-section-vma ="
307 pass "objcopy --adjust-section-vma ="
313 # Test stripping an object.
315 proc strip_test { } {
326 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
331 if [is_remote host] {
332 set objfile [remote_download host tmpdir/testprog.o];
334 set objfile tmpdir/testprog.o
337 set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"]
338 if ![string match "" $exec_output] {
343 set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"]
344 if ![string match "No symbols in *" $exec_output] {
354 # Test stripping an object file with saving a symbol
356 proc strip_test_with_saving_a_symbol { } {
365 set test "strip with saving a symbol"
367 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
372 if [is_remote host] {
373 set objfile [remote_download host tmpdir/testprog.o];
375 set objfile tmpdir/testprog.o
378 set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main $objfile"]
379 if ![string match "" $exec_output] {
384 set exec_output [binutils_run $NM "$NMFLAGS $objfile"]
385 if ![regexp {^([0-9a-fA-F]+)?[ ]+T main} $exec_output] {
393 strip_test_with_saving_a_symbol
395 # Build a final executable.
397 proc copy_setup { } {
401 set res [build_wrapper testglue.o];
405 lappend flags "additional_flags=[lindex $res 1]";
406 set add_libs "testglue.o";
411 if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/testprog executable $flags] != "" } {
415 set result [remote_load target tmpdir/testprog];
416 set status [lindex $result 0];
418 if { $status != "pass" } {
419 perror "unresolved setup, status = $status"
426 # Test copying an executable.
428 proc copy_executable { prog flags test1 test2 } {
430 if [is_remote host] {
431 set testfile [remote_download host tmpdir/testprog];
432 set testcopy copyprog
434 set testfile tmpdir/testprog
435 set testcopy tmpdir/copyprog
437 remote_file host delete $testcopy;
439 set exec_output [binutils_run $prog "$flags $testfile $testcopy"]
441 if ![string match "" $exec_output] {
447 if [is_remote host] {
448 remote_upload host $testcopy tmpdir/copyprog
451 set status [remote_exec build "cmp" "tmpdir/testprog tmpdir/copyprog"]
452 set exec_output [lindex $status 1];
454 if [string match "" $exec_output] then {
457 send_log "$exec_output\n"
458 verbose "$exec_output"
460 # This will fail for many reasons. For example, it will most
461 # likely fail if a non-GNU linker is used. Therefore, we do
462 # not insist that it pass. If you are using an assembler and
463 # linker based on the same BFD as objcopy, it is worth
464 # investigating to see why this failure occurs. If we are
465 # cross compiling, we assume that a GNU linker is being used,
466 # and expect it to succeed.
467 if {[isnative]} then {
474 set output [remote_load target tmpdir/copyprog]
475 set status [lindex $output 0];
476 if { $status != "pass" } {
483 # Test stripping an executable
485 proc strip_executable { prog flags test } {
489 remote_download build tmpdir/copyprog tmpdir/striprog
490 if [is_remote host] {
491 set copyfile [remote_download host tmpdir/striprog];
493 set copyfile tmpdir/striprog
496 set exec_output [binutils_run $prog "$flags ${copyfile}"]
497 if ![string match "" $exec_output] {
502 if [is_remote host] {
503 remote_upload host ${copyfile} tmpdir/striprog;
506 set result [remote_load target tmpdir/striprog]
507 set status [lindex $result 0];
508 if { $status != "pass" } {
513 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
514 if ![string match "$copyfile: no symbols*" $exec_output] {
521 # Test stripping an executable with saving a symbol
523 proc strip_executable_with_saving_a_symbol { prog flags test } {
527 remote_download build tmpdir/copyprog tmpdir/striprog
528 if [is_remote host] {
529 set copyfile [remote_download host tmpdir/striprog];
531 set copyfile tmpdir/striprog
534 set exec_output [binutils_run $prog "$flags ${copyfile}"]
535 if ![string match "" $exec_output] {
540 if [is_remote host] {
541 remote_upload host ${copyfile} tmpdir/striprog;
544 set result [remote_load target tmpdir/striprog]
545 set status [lindex $result 0];
546 if { $status != "pass" } {
551 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
552 if ![regexp {^[0-9a-fA-F]+ T main} $exec_output] {
559 set test1 "simple objcopy of executable"
560 set test2 "run objcopy of executable"
561 set test3 "run stripped executable"
562 set test4 "run stripped executable with saving a symbol"
564 switch [copy_setup] {
581 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2"
582 strip_executable "$STRIP" "$STRIPFLAGS" "$test3"
583 strip_executable_with_saving_a_symbol "$STRIP" "-K main $STRIPFLAGS" "$test4"