1 # Copyright (C) 1994, 1995, 1996 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 {[which $OBJCOPY] == 0} then {
23 perror "$OBJCOPY does not exist"
27 send_user "Version [binutil_version $OBJCOPY]"
29 if {![binutils_assemble $AS $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
30 unresolved "objcopy (simple copy)"
34 # Test that objcopy does not modify a file when copying it.
36 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"]
38 if ![string match "" $got] then {
39 fail "objcopy (simple copy)"
41 send_log "cmp tmpdir/bintest.o tmpdir/copy.o\n"
42 verbose "cmp tmpdir/bintest.o tmpdir/copy.o"
43 catch "exec cmp tmpdir/bintest.o tmpdir/copy.o" exec_output
44 set exec_output [prune_system_crud $host_triplet $exec_output]
46 # On some systems the result of objcopy will not be identical.
47 # Usually this is just because gas isn't using bfd to write the files
48 # in the first place, and may order things a little differently.
49 # Those systems should use setup_xfail here.
51 setup_xfail "sh-*-coff" "sh-*-hms"
52 setup_xfail "arm-*-pe"
53 setup_xfail "m68*-*-hpux*" "m68*-*-sunos*" "m68*-*-coff" "m68*-*-vxworks*"
54 setup_xfail "m68*-ericsson-ose" "m68k*-motorola-sysv*"
55 setup_xfail "i*86-*-linuxaout*" "i*86-*-aout*"
56 setup_xfail "i*86-*-sysv3" "i*86-*-isc*" "i*86-*-sco*" "i*86-*-coff"
57 setup_xfail "i*86-*-aix*" "i*86-*-go32*"
58 setup_xfail "a29k-*-udi" "a29k-*-coff" "a29k-*-vxworks*"
59 setup_xfail "i960-*-coff"
60 setup_xfail "h8300-*-hms" "h8300-*-coff"
61 setup_xfail "h8500-*-hms" "h8500-*-coff"
62 setup_xfail "hppa*-*-*"
63 clear_xfail "hppa*-*-*elf*"
64 setup_xfail "m88*-*-coff" "m88*-motorola-sysv*"
65 setup_xfail "z8*-*-coff"
67 if [string match "" $exec_output] then {
68 pass "objcopy (simple copy)"
70 send_log "$exec_output\n"
71 verbose "$exec_output" 1
73 # On OSF/1, this succeeds with gas and fails with /bin/as.
74 setup_xfail "alpha*-*-osf*"
76 # This fails for COFF i960-vxworks targets.
77 setup_xfail "i960-*-vxworks*"
79 fail "objcopy (simple copy)"
83 # Test generating S records.
85 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec"]
87 if ![string match "" $got] then {
88 fail "objcopy -O srec"
90 set file [open tmpdir/copy.srec r]
92 # The first S record is fixed by the file name we are using.
96 if ![string match "S0130000746D706469722F636F70792E7372656397*" $line] {
97 send_log "bad header\n"
98 fail "objcopy -O srec"
100 while {[gets $file line] != -1 \
101 && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} {
108 if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then {
109 send_log "bad trailer\n"
110 fail "objcopy -O srec"
112 if {[gets $file line] != -1} then {
113 send_log "garbage at end\n"
116 fail "objcopy -O srec"
118 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
119 if ![regexp "file format srec" $got] then {
120 send_log "objdump failed\n"
121 fail "objcopy -O srec"
123 pass "objcopy -O srec"
132 # Test setting and adjusting the start address. We only test this
133 # while generating S records, because we may not be able to set the
134 # start address for other object file formats, and the S record case
135 # is the only useful one anyhow.
137 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/bintest.o"]
138 if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
139 perror "objdump can not recognize bintest.o"
142 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --set-start 0x7654"]
143 if ![string match "" $got] then {
144 fail "objcopy --set-start"
146 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
147 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
148 fail "objcopy --set-start"
150 if {$srecstart != 0x7654} then {
151 send_log "$srecstart != 0x7654\n"
152 fail "objcopy --set-start"
154 pass "objcopy --set-start"
159 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-start 0x123"]
160 if ![string match "" $got] then {
161 fail "objcopy --adjust-start"
163 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
164 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
165 fail "objcopy --adjust-start"
167 if {$srecstart != $origstart + 0x123} then {
168 send_log "$srecstart != $origstart + 0x123\n"
169 fail "objcopy --adjust-start"
171 pass "objcopy --adjust-start"
177 # Test adjusting the overall VMA, and adjusting the VMA of a
178 # particular section. We again only test this when generating S
184 set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/bintest.o"]
186 set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)"
189 while {[regexp $headers_regexp $got all name size vma rest]} {
193 if {$low == "" || $vma < $low} {
201 if {$low == "" || $origstart == ""} then {
202 perror "objdump can not recognize bintest.o"
204 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-vma 0x123"]
205 if ![string match "" $got] then {
206 fail "objcopy --adjust-vma"
208 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh tmpdir/copy.srec"]
209 set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
210 if ![regexp $want $got all start vma] then {
211 fail "objcopy --adjust-vma"
214 if {$vma != $low + 0x123} then {
215 send_log "$vma != $low + 0x123\n"
216 fail "objcopy --adjust-vma"
218 if {$start != $origstart + 0x123} then {
219 send_log "$start != $origstart + 0x123\n"
220 fail "objcopy --adjust-vma"
222 pass "objcopy --adjust-vma"
230 while {[regexp $headers_regexp $got all name size vma rest]} {
232 if {$vma == $low} then {
233 set arg "$arg --adjust-section-vma $name+4"
238 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $arg"]
239 if ![string match "" $got] then {
240 fail "objcopy --adjust-section-vma +"
242 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"]
243 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
244 if ![regexp $want $got all vma] then {
245 fail "objcopy --adjust-section-vma +"
248 if {$vma != $low + 4} then {
249 send_log "$vma != $low + 4\n"
250 fail "objcopy --adjust-section-vma +"
252 pass "objcopy --adjust-section-vma +"
257 regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
258 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $argeq"]
259 if ![string match "" $got] then {
260 fail "objcopy --adjust-section-vma ="
262 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"]
263 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
264 if ![regexp $want $got all vma] then {
265 fail "objcopy --adjust-section-vma ="
268 if {$vma != $low + 4} then {
269 send_log "$vma != $low + 4\n"
270 fail "objcopy --adjust-section-vma ="
272 pass "objcopy --adjust-section-vma ="
278 # Test stripping an object.
280 proc strip_test { } {
291 if { [which $CC] == 0 } {
296 if ![binutils_compile $CC "-g -c" $srcdir/$subdir/testprog.c tmpdir/testprog.o] {
301 set exec_output [binutils_run $STRIP "$STRIPFLAGS tmpdir/testprog.o"]
302 if ![string match "" $exec_output] {
307 set exec_output [binutils_run $NM "-a $NMFLAGS tmpdir/testprog.o"]
308 if ![string match "No symbols in *" $exec_output] {
318 # Build a final executable.
320 proc copy_setup { } {
329 if { [which $CC] == 0 } {
333 if ![binutils_compile $CC "-g" $srcdir/$subdir/testprog.c tmpdir/testprog] {
337 set exec_output [binutils_run tmpdir/testprog ""]
338 if ![string match "ok" $exec_output] {
345 # Test copying an executable.
347 proc copy_executable { prog flags test1 test2 } {
349 set exec_output [binutils_run $prog "$flags tmpdir/testprog tmpdir/copyprog"]
350 if ![string match "" $exec_output] {
356 set exec_output [binutils_run "cmp" "tmpdir/testprog tmpdir/copyprog"]
358 if [string match "" $exec_output] then {
361 send_log "$exec_output\n"
362 verbose "$exec_output"
363 # This will fail for many reasons. For example, it will most
364 # likely fail if the system linker is used. Therefore, we do
365 # not insist that it pass. If you are using an assembler and
366 # linker based on the same BFD as objcopy, it is worth
367 # investigating to see why this failure occurs.
372 set exec_output [binutils_run tmpdir/copyprog ""]
373 if ![string match "ok" $exec_output] {
380 # Test stripping an executable
382 proc strip_executable { prog flags test } {
384 set exec_output [binutils_run $prog "$flags tmpdir/copyprog"]
385 if ![string match "" $exec_output] {
390 set exec_output [binutils_run tmpdir/copyprog ""]
391 if ![string match "ok" $exec_output] {
398 set test1 "simple objcopy of executable"
399 set test2 "run objcopy of executable"
400 set test3 "run stripped executable"
402 switch [copy_setup] {
417 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2"
418 strip_executable "$STRIP" "$STRIPFLAGS" "$test3"