1 # Copyright (C) 1994 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., 675 Mass Ave, Cambridge, MA 02139, 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 [istarget hppa*-*-*] then {
30 # bintest.s doesn't assemble, and we don't have any other tests
34 if {![binutils_assemble $AS $srcdir$subdir/bintest.s tmpdir/bintest.o]} then {
38 # Test that objcopy does not modify a file when copying it.
40 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"]
42 if ![string match "" $got] then {
43 fail "objcopy (simple copy)"
45 send_log "cmp tmpdir/bintest.o tmpdir/copy.o\n"
46 verbose "cmp tmpdir/bintest.o tmpdir/copy.o"
47 catch "exec cmp tmpdir/bintest.o tmpdir/copy.o" exec_output
49 # On some systems the result of objcopy will not be identical.
50 # Those systems should use setup_xfail here.
52 setup_xfail "sh-*-coff" "m68*-*-hpux*"
54 if [string match "" $exec_output] then {
55 pass "objcopy (simple copy)"
57 send_log "$exec_output\n"
58 verbose "$exec_output" 1
60 fail "objcopy (simple copy)"
64 # Test generating S records.
66 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec"]
68 if ![string match "" $got] then {
69 fail "objcopy -O srec"
71 set file [open tmpdir/copy.srec r]
73 # The first S record is fixed by the file name we are using.
77 if ![string match $line "S0130000746D706469722F636F70792E7372656397\r"] {
78 fail "objcopy -O srec (bad header)"
80 while {[gets $file line] != -1 \
81 && [regexp "^S\[123\]\[0-9a-fA-F\]+\r$" $line]} {
88 if ![regexp "^S\[789\]\[0-9a-fA-F\]+\r$" $line] then {
89 fail "objcopy -O srec (bad trailer)"
91 if {[gets $file line] != -1} then {
94 fail "objcopy -O srec (garbage at end)"
96 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
97 if ![regexp "file format srec" $got] then {
98 fail "objcopy -O srec (objdump failed)"
100 pass "objcopy -O srec"
109 # Test setting and adjusting the start address. We only test this
110 # while generating S records, because we may not be able to set the
111 # start address for other object file formats, and the S record case
112 # is the only useful one anyhow.
114 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/bintest.o"]
115 if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
116 perror "objdump can not recognize bintest.o"
119 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --set-start 0x7654"]
120 if ![string match "" $got] then {
121 fail "objcopy --set-start"
123 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
124 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
125 fail "objcopy --set-start"
127 if {$srecstart != 0x7654} then {
128 fail "objcopy --set-start ($srecstart != 0x7654)"
130 pass "objcopy --set-start"
135 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-start 0x123"]
136 if ![string match "" $got] then {
137 fail "objcopy --adjust-start"
139 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
140 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
141 fail "objcopy --adjust-start"
143 if {$srecstart != $origstart + 0x123} then {
144 fail "objcopy --adjust-start ($srecstart != $origstart + 0x123)"
146 pass "objcopy --adjust-start"
152 # Test adjusting the overall VMA, and adjusting the VMA of a
153 # particular section. We again only test this when # generating S
159 set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/bintest.o"]
161 set headers_regexp "SECTION\[ 0-9\]+\\\[(\[^\]\]*)\\\]\[^\n\r\]*size\[ \]*(\[0-9a-fA-F\]+)\[ \]*vma\[ \]*(\[0-9a-fA-F\]+)(.*)"
164 while {[regexp $headers_regexp $got all name size vma rest]} {
166 if {$low == "" || $vma < $low} then {
173 if {$low == "" || $origstart == ""} then {
174 perror "objdump can not recognize bintest.o"
176 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-vma 0x123"]
177 if ![string match "" $got] then {
178 fail "objcopy --adjust-vma"
180 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh tmpdir/copy.srec"]
181 set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*vma\[ \]*(\[0-9a-fA-F\]+)"
182 if ![regexp $want $got all start vma] then {
183 fail "objcopy --adjust-vma"
186 if {$vma != $low + 0x123} then {
187 fail "objcopy --adjust-vma ($vma != $low + 0x123)"
189 if {$start != $origstart + 0x123} then {
190 fail "objcopy --adjust-vma ($start != $origstart + 0x123)"
192 pass "objcopy --adjust-vma"
200 while {[regexp $headers_regexp $got all name size vma rest]} {
202 if {$vma == $low} then {
203 set arg "$arg --adjust-section-vma $name+4"
208 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $arg"]
209 if ![string match "" $got] then {
210 fail "objcopy --adjust-section-vma +"
212 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"]
213 set want "file format srec.*SECTION\[ \]*0\[^\n\r\]*vma\[ \]*(\[0-9a-fA-F\]+)"
214 if ![regexp $want $got all vma] then {
215 fail "objcopy --adjust-section-vma +"
218 if {$vma != $low + 4} then {
219 fail "objcopy --adjust-section-vma + ($vma != $low + 4)"
221 pass "objcopy --adjust-section-vma +"
226 regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
227 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $argeq"]
228 if ![string match "" $got] then {
229 fail "objcopy --adjust-section-vma ="
231 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"]
232 set want "file format srec.*SECTION\[ \]*0\[^\n\r\]*vma\[ \]*(\[0-9a-fA-F\]+)"
233 if ![regexp $want $got all vma] then {
234 fail "objcopy --adjust-section-vma ="
237 if {$vma != $low + 4} then {
238 fail "objcopy --adjust-section-vma = ($vma != $low + 4)"
240 pass "objcopy --adjust-section-vma ="