* binutils-all/objdump.exp (cpus_expected): New variable, taken from objdump -i
[deliverable/binutils-gdb.git] / binutils / testsuite / binutils-all / objcopy.exp
CommitLineData
09250cfe
ILT
1# Copyright (C) 1994 Free Software Foundation, Inc.
2
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.
7#
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.
12#
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. */
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-dejagnu@prep.ai.mit.edu
19
20# Written by Ian Lance Taylor <ian@cygnus.com>
21
22if {[which $OBJCOPY] == 0} then {
23 perror "$OBJCOPY does not exist"
24 return
25}
26
27send_user "Version [binutil_version $OBJCOPY]"
28
29if {![binutils_assemble $AS $srcdir$subdir/bintest.s tmpdir/bintest.o]} then {
30 return
31}
32
33# Test that objcopy does not modify a file when copying it.
34
ef1ad8ab
KR
35# Since some versions of the assembler don't use BFD to generate the
36# object file, we shouldn't assume that the version written by BFD will
37# be bit-for-bit identical. It need merely be functionally identical.
38setup_xfail "sh-*-coff"
39
09250cfe
ILT
40set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"]
41
42if ![string match "" $got] then {
43 fail "objcopy (simple copy)"
44} else {
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
48
49 # On some systems the result of objcopy will not be identical.
50 # Those systems should use setup_xfail here.
51
52 if [string match "" $exec_output] then {
53 pass "objcopy (simple copy)"
54 } else {
55 send_log "$exec_output\n"
56 verbose "$exec_output" 1
57
58 fail "objcopy (simple copy)"
59 }
60}
61
62# Test generating S records.
63
64set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec"]
65
66if ![string match "" $got] then {
67 fail "objcopy -O srec"
68} else {
69 set file [open tmpdir/copy.srec r]
70
71 # The first S record is fixed by the file name we are using.
72 gets $file line
73 send_log "$line\n"
74 verbose $line
75 if ![string match $line "S0130000746D706469722F636F70792E7372656397\r"] {
76 fail "objcopy -O srec (bad header)"
77 } else {
78 while {[gets $file line] != -1 \
79 && [regexp "^S\[123\]\[0-9a-fA-F\]+\r$" $line]} {
80 send_log "$line\n"
81 verbose $line
82 set line "**EOF**"
83 }
84 send_log "$line\n"
85 verbose $line
86 if ![regexp "^S\[789\]\[0-9a-fA-F\]+\r$" $line] then {
87 fail "objcopy -O srec (bad trailer)"
88 } else {
89 if {[gets $file line] != -1} then {
90 send_log "$line\n"
91 verbose $line
92 fail "objcopy -O srec (garbage at end)"
93 } else {
94 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
95 if ![regexp "file format srec" $got] then {
96 fail "objcopy -O srec (objdump failed)"
97 } else {
98 pass "objcopy -O srec"
99 }
100 }
101 }
102 }
103
104 close $file
105}
106
107# Test setting and adjusting the start address. We only test this
108# while generating S records, because we may not be able to set the
109# start address for other object file formats, and the S record case
110# is the only useful one anyhow.
111
112set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/bintest.o"]
113if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
114 perror "objdump can not recognize bintest.o"
115 set origstart ""
116} else {
117 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --set-start 0x7654"]
118 if ![string match "" $got] then {
119 fail "objcopy --set-start"
120 } else {
121 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
122 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
123 fail "objcopy --set-start"
124 } else {
125 if {$srecstart != 0x7654} then {
126 fail "objcopy --set-start ($srecstart != 0x7654)"
127 } else {
128 pass "objcopy --set-start"
129 }
130 }
131 }
132
133 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-start 0x123"]
134 if ![string match "" $got] then {
135 fail "objcopy --adjust-start"
136 } else {
137 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
138 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
139 fail "objcopy --adjust-start"
140 } else {
141 if {$srecstart != $origstart + 0x123} then {
142 fail "objcopy --adjust-start ($srecstart != $origstart + 0x123)"
143 } else {
144 pass "objcopy --adjust-start"
145 }
146 }
147 }
148}
149
150# Test adjusting the overall VMA, and adjusting the VMA of a
151# particular section. We again only test this when # generating S
152# records.
153
154set low ""
155set lowname ""
156
157set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/bintest.o"]
158
159set headers_regexp "SECTION\[ 0-9\]+\\\[(\[^\]\]*)\\\]\[^\n\r\]*size\[ \]*(\[0-9a-fA-F\]+)\[ \]*vma\[ \]*(\[0-9a-fA-F\]+)(.*)"
160
161set got $headers
162while {[regexp $headers_regexp $got all name size vma rest]} {
163 set vma 0x$vma
164 if {$low == "" || $vma < $low} then {
165 set low $vma
166 set lowname $name
167 }
168 set got $rest
169}
170
171if {$low == "" || $origstart == ""} then {
172 perror "objdump can not recognize bintest.o"
173} else {
174 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-vma 0x123"]
175 if ![string match "" $got] then {
176 fail "objcopy --adjust-vma"
177 } else {
178 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh tmpdir/copy.srec"]
179 set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*vma\[ \]*(\[0-9a-fA-F\]+)"
180 if ![regexp $want $got all start vma] then {
181 fail "objcopy --adjust-vma"
182 } else {
183 set vma 0x$vma
184 if {$vma != $low + 0x123} then {
185 fail "objcopy --adjust-vma ($vma != $low + 0x123)"
186 } else {
187 if {$start != $origstart + 0x123} then {
188 fail "objcopy --adjust-vma ($start != $origstart + 0x123)"
189 } else {
190 pass "objcopy --adjust-vma"
191 }
192 }
193 }
194 }
195
196 set arg ""
197 set got $headers
198 while {[regexp $headers_regexp $got all name size vma rest]} {
199 set vma 0x$vma
200 if {$vma == $low} then {
201 set arg "$arg --adjust-section-vma $name+4"
202 }
203 set got $rest
204 }
205
206 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $arg"]
207 if ![string match "" $got] then {
208 fail "objcopy --adjust-section-vma +"
209 } else {
210 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"]
ef1ad8ab 211 set want "file format srec.*SECTION\[ \]*0\[^\n\r\]*vma\[ \]*(\[0-9a-fA-F\]+)"
09250cfe
ILT
212 if ![regexp $want $got all vma] then {
213 fail "objcopy --adjust-section-vma +"
214 } else {
215 set vma 0x$vma
216 if {$vma != $low + 4} then {
217 fail "objcopy --adjust-section-vma + ($vma != $low + 4)"
218 } else {
219 pass "objcopy --adjust-section-vma +"
220 }
221 }
222 }
223
224 regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
225 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $argeq"]
226 if ![string match "" $got] then {
227 fail "objcopy --adjust-section-vma ="
228 } else {
229 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"]
ef1ad8ab 230 set want "file format srec.*SECTION\[ \]*0\[^\n\r\]*vma\[ \]*(\[0-9a-fA-F\]+)"
09250cfe
ILT
231 if ![regexp $want $got all vma] then {
232 fail "objcopy --adjust-section-vma ="
233 } else {
234 set vma 0x$vma
235 if {$vma != $low + 4} then {
236 fail "objcopy --adjust-section-vma = ($vma != $low + 4)"
237 } else {
238 pass "objcopy --adjust-section-vma ="
239 }
240 }
241 }
242}
This page took 0.039288 seconds and 4 git commands to generate.