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-*-vxworks*" "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 fail "objcopy (simple copy)"
77 # Test generating S records.
79 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec"]
81 if ![string match "" $got] then {
82 fail "objcopy -O srec"
84 set file [open tmpdir/copy.srec r]
86 # The first S record is fixed by the file name we are using.
90 if ![string match $line "S0130000746D706469722F636F70792E7372656397\r"] {
91 send_log "bad header\n"
92 fail "objcopy -O srec"
94 while {[gets $file line] != -1 \
95 && [regexp "^S\[123\]\[0-9a-fA-F\]+\r$" $line]} {
102 if ![regexp "^S\[789\]\[0-9a-fA-F\]+\r$" $line] then {
103 send_log "bad trailer\n"
104 fail "objcopy -O srec"
106 if {[gets $file line] != -1} then {
107 send_log "garbage at end\n"
110 fail "objcopy -O srec"
112 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
113 if ![regexp "file format srec" $got] then {
114 send_log "objdump failed\n"
115 fail "objcopy -O srec"
117 pass "objcopy -O srec"
126 # Test setting and adjusting the start address. We only test this
127 # while generating S records, because we may not be able to set the
128 # start address for other object file formats, and the S record case
129 # is the only useful one anyhow.
131 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/bintest.o"]
132 if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
133 perror "objdump can not recognize bintest.o"
136 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --set-start 0x7654"]
137 if ![string match "" $got] then {
138 fail "objcopy --set-start"
140 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
141 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
142 fail "objcopy --set-start"
144 if {$srecstart != 0x7654} then {
145 send_log "$srecstart != 0x7654\n"
146 fail "objcopy --set-start"
148 pass "objcopy --set-start"
153 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-start 0x123"]
154 if ![string match "" $got] then {
155 fail "objcopy --adjust-start"
157 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
158 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
159 fail "objcopy --adjust-start"
161 if {$srecstart != $origstart + 0x123} then {
162 send_log "$srecstart != $origstart + 0x123\n"
163 fail "objcopy --adjust-start"
165 pass "objcopy --adjust-start"
171 # Test adjusting the overall VMA, and adjusting the VMA of a
172 # particular section. We again only test this when generating S
178 set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/bintest.o"]
180 set headers_regexp "SECTION\[ 0-9\]+\\\[(\[^\]\]*)\\\]\[^\n\r\]*size\[ \]*(\[0-9a-fA-F\]+)\[0-9a-zA-Z \]*lma\[ \]*(\[0-9a-fA-F\]+)(.*)"
183 while {[regexp $headers_regexp $got all name size vma rest]} {
187 if {$low == "" || $vma < $low} {
195 if {$low == "" || $origstart == ""} then {
196 perror "objdump can not recognize bintest.o"
198 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-vma 0x123"]
199 if ![string match "" $got] then {
200 fail "objcopy --adjust-vma"
202 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh tmpdir/copy.srec"]
203 set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*vma\[ \]*(\[0-9a-fA-F\]+)"
204 if ![regexp $want $got all start vma] then {
205 fail "objcopy --adjust-vma"
208 if {$vma != $low + 0x123} then {
209 send_log "$vma != $low + 0x123\n"
210 fail "objcopy --adjust-vma"
212 if {$start != $origstart + 0x123} then {
213 send_log "$start != $origstart + 0x123\n"
214 fail "objcopy --adjust-vma"
216 pass "objcopy --adjust-vma"
224 while {[regexp $headers_regexp $got all name size vma rest]} {
226 if {$vma == $low} then {
227 set arg "$arg --adjust-section-vma $name+4"
232 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $arg"]
233 if ![string match "" $got] then {
234 fail "objcopy --adjust-section-vma +"
236 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"]
237 set want "file format srec.*SECTION\[ \]*0\[^\n\r\]*vma\[ \]*(\[0-9a-fA-F\]+)"
238 if ![regexp $want $got all vma] then {
239 fail "objcopy --adjust-section-vma +"
242 if {$vma != $low + 4} then {
243 send_log "$vma != $low + 4\n"
244 fail "objcopy --adjust-section-vma +"
246 pass "objcopy --adjust-section-vma +"
251 regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
252 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $argeq"]
253 if ![string match "" $got] then {
254 fail "objcopy --adjust-section-vma ="
256 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"]
257 set want "file format srec.*SECTION\[ \]*0\[^\n\r\]*vma\[ \]*(\[0-9a-fA-F\]+)"
258 if ![regexp $want $got all vma] then {
259 fail "objcopy --adjust-section-vma ="
262 if {$vma != $low + 4} then {
263 send_log "$vma != $low + 4\n"
264 fail "objcopy --adjust-section-vma ="
266 pass "objcopy --adjust-section-vma ="
272 # Test stripping an object.
274 proc strip_test { } {
285 if { [which $CC] == 0 } {
290 if ![binutils_compile $CC "-g -c" $srcdir/$subdir/testprog.c tmpdir/testprog.o] {
295 set exec_output [binutils_run $STRIP "$STRIPFLAGS tmpdir/testprog.o"]
296 if ![string match "" $exec_output] {
301 set exec_output [binutils_run $NM "-a $NMFLAGS tmpdir/testprog.o"]
302 if ![string match "No symbols in *" $exec_output] {
312 # Build a final executable.
314 proc copy_setup { } {
323 if { [which $CC] == 0 } {
327 if ![binutils_compile $CC "-g" $srcdir/$subdir/testprog.c tmpdir/testprog] {
331 set exec_output [binutils_run tmpdir/testprog ""]
332 if ![string match "ok" $exec_output] {
339 # Test copying an executable.
341 proc copy_executable { prog flags test1 test2 } {
343 set exec_output [binutils_run $prog "$flags tmpdir/testprog tmpdir/copyprog"]
344 if ![string match "" $exec_output] {
350 set exec_output [binutils_run "cmp" "tmpdir/testprog tmpdir/copyprog"]
352 if [string match "" $exec_output] then {
355 send_log "$exec_output\n"
356 verbose "$exec_output"
357 # This will fail for many reasons. For example, it will most
358 # likely fail if the system linker is used. Therefore, we do
359 # not insist that it pass. If you are using an assembler and
360 # linker based on the same BFD as objcopy, it is worth
361 # investigating to see why this failure occurs.
366 set exec_output [binutils_run tmpdir/copyprog ""]
367 if ![string match "ok" $exec_output] {
374 # Test stripping an executable
376 proc strip_executable { prog flags test } {
378 set exec_output [binutils_run $prog "$flags tmpdir/copyprog"]
379 if ![string match "" $exec_output] {
384 set exec_output [binutils_run tmpdir/copyprog ""]
385 if ![string match "ok" $exec_output] {
392 set test1 "simple objcopy of executable"
393 set test2 "run objcopy of executable"
394 set test3 "run stripped executable"
396 switch [copy_setup] {
411 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2"
412 strip_executable "$STRIP" "$STRIPFLAGS" "$test3"