Major revision to testsuites for cross-testing and DOS testing support.
[deliverable/binutils-gdb.git] / binutils / testsuite / binutils-all / objcopy.exp
1 # Copyright (C) 1994, 1995, 1996 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
22 if {[which $OBJCOPY] == 0} then {
23 perror "$OBJCOPY does not exist"
24 return
25 }
26
27 send_user "Version [binutil_version $OBJCOPY]"
28
29 if {![binutils_assemble $AS $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
30 unresolved "objcopy (simple copy)"
31 return
32 }
33
34 # Test that objcopy does not modify a file when copying it.
35
36 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"]
37
38 if ![string match "" $got] then {
39 fail "objcopy (simple copy)"
40 } else {
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]
45
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.
50
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"
66
67 if [string match "" $exec_output] then {
68 pass "objcopy (simple copy)"
69 } else {
70 send_log "$exec_output\n"
71 verbose "$exec_output" 1
72
73 # On OSF/1, this succeeds with gas and fails with /bin/as.
74 setup_xfail "alpha*-*-osf*"
75
76 # This fails for COFF i960-vxworks targets.
77 setup_xfail "i960-*-vxworks*"
78
79 fail "objcopy (simple copy)"
80 }
81 }
82
83 # Test generating S records.
84
85 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec"]
86
87 if ![string match "" $got] then {
88 fail "objcopy -O srec"
89 } else {
90 set file [open tmpdir/copy.srec r]
91
92 # The first S record is fixed by the file name we are using.
93 gets $file line
94 send_log "$line\n"
95 verbose $line
96 if ![string match "S0130000746D706469722F636F70792E7372656397*" $line] {
97 send_log "bad header\n"
98 fail "objcopy -O srec"
99 } else {
100 while {[gets $file line] != -1 \
101 && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} {
102 send_log "$line\n"
103 verbose $line
104 set line "**EOF**"
105 }
106 send_log "$line\n"
107 verbose $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"
111 } else {
112 if {[gets $file line] != -1} then {
113 send_log "garbage at end\n"
114 send_log "$line\n"
115 verbose $line
116 fail "objcopy -O srec"
117 } else {
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"
122 } else {
123 pass "objcopy -O srec"
124 }
125 }
126 }
127 }
128
129 close $file
130 }
131
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.
136
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"
140 set origstart ""
141 } else {
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"
145 } else {
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"
149 } else {
150 if {$srecstart != 0x7654} then {
151 send_log "$srecstart != 0x7654\n"
152 fail "objcopy --set-start"
153 } else {
154 pass "objcopy --set-start"
155 }
156 }
157 }
158
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"
162 } else {
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"
166 } else {
167 if {$srecstart != $origstart + 0x123} then {
168 send_log "$srecstart != $origstart + 0x123\n"
169 fail "objcopy --adjust-start"
170 } else {
171 pass "objcopy --adjust-start"
172 }
173 }
174 }
175 }
176
177 # Test adjusting the overall VMA, and adjusting the VMA of a
178 # particular section. We again only test this when generating S
179 # records.
180
181 set low ""
182 set lowname ""
183
184 set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/bintest.o"]
185
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\]+(.*)"
187
188 set got $headers
189 while {[regexp $headers_regexp $got all name size vma rest]} {
190 set vma 0x$vma
191 set size 0x$size
192 if {$size != 0} {
193 if {$low == "" || $vma < $low} {
194 set low $vma
195 set lowname $name
196 }
197 }
198 set got $rest
199 }
200
201 if {$low == "" || $origstart == ""} then {
202 perror "objdump can not recognize bintest.o"
203 } else {
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"
207 } else {
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"
212 } else {
213 set vma 0x$vma
214 if {$vma != $low + 0x123} then {
215 send_log "$vma != $low + 0x123\n"
216 fail "objcopy --adjust-vma"
217 } else {
218 if {$start != $origstart + 0x123} then {
219 send_log "$start != $origstart + 0x123\n"
220 fail "objcopy --adjust-vma"
221 } else {
222 pass "objcopy --adjust-vma"
223 }
224 }
225 }
226 }
227
228 set arg ""
229 set got $headers
230 while {[regexp $headers_regexp $got all name size vma rest]} {
231 set vma 0x$vma
232 if {$vma == $low} then {
233 set arg "$arg --adjust-section-vma $name+4"
234 }
235 set got $rest
236 }
237
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 +"
241 } else {
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 +"
246 } else {
247 set vma 0x$vma
248 if {$vma != $low + 4} then {
249 send_log "$vma != $low + 4\n"
250 fail "objcopy --adjust-section-vma +"
251 } else {
252 pass "objcopy --adjust-section-vma +"
253 }
254 }
255 }
256
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 ="
261 } else {
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 ="
266 } else {
267 set vma 0x$vma
268 if {$vma != $low + 4} then {
269 send_log "$vma != $low + 4\n"
270 fail "objcopy --adjust-section-vma ="
271 } else {
272 pass "objcopy --adjust-section-vma ="
273 }
274 }
275 }
276 }
277
278 # Test stripping an object.
279
280 proc strip_test { } {
281 global CC
282 global STRIP
283 global STRIPFLAGS
284 global NM
285 global NMFLAGS
286 global srcdir
287 global subdir
288
289 set test "strip"
290
291 if { [which $CC] == 0 } {
292 untested $test
293 return
294 }
295
296 if ![binutils_compile $CC "-g -c" $srcdir/$subdir/testprog.c tmpdir/testprog.o] {
297 unresolved $test
298 return
299 }
300
301 set exec_output [binutils_run $STRIP "$STRIPFLAGS tmpdir/testprog.o"]
302 if ![string match "" $exec_output] {
303 fail $test
304 return
305 }
306
307 set exec_output [binutils_run $NM "-a $NMFLAGS tmpdir/testprog.o"]
308 if ![string match "No symbols in *" $exec_output] {
309 fail $test
310 return
311 }
312
313 pass $test
314 }
315
316 strip_test
317
318 # Build a final executable.
319
320 proc copy_setup { } {
321 global CC
322 global srcdir
323 global subdir
324
325 if ![isnative] {
326 return 1
327 }
328
329 if { [which $CC] == 0 } {
330 return 2
331 }
332
333 if ![binutils_compile $CC "-g" $srcdir/$subdir/testprog.c tmpdir/testprog] {
334 return 3
335 }
336
337 set exec_output [binutils_run tmpdir/testprog ""]
338 if ![string match "ok" $exec_output] {
339 return 3
340 }
341
342 return 0
343 }
344
345 # Test copying an executable.
346
347 proc copy_executable { prog flags test1 test2 } {
348
349 set exec_output [binutils_run $prog "$flags tmpdir/testprog tmpdir/copyprog"]
350 if ![string match "" $exec_output] {
351 fail $test1
352 fail $test2
353 return
354 }
355
356 set exec_output [binutils_run "cmp" "tmpdir/testprog tmpdir/copyprog"]
357
358 if [string match "" $exec_output] then {
359 pass $test1
360 } else {
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.
368 setup_xfail "*-*-*"
369 fail $test1
370 }
371
372 set exec_output [binutils_run tmpdir/copyprog ""]
373 if ![string match "ok" $exec_output] {
374 fail $test2
375 } else {
376 pass $test2
377 }
378 }
379
380 # Test stripping an executable
381
382 proc strip_executable { prog flags test } {
383
384 set exec_output [binutils_run $prog "$flags tmpdir/copyprog"]
385 if ![string match "" $exec_output] {
386 fail $test
387 return
388 }
389
390 set exec_output [binutils_run tmpdir/copyprog ""]
391 if ![string match "ok" $exec_output] {
392 fail $test
393 } else {
394 pass $test
395 }
396 }
397
398 set test1 "simple objcopy of executable"
399 set test2 "run objcopy of executable"
400 set test3 "run stripped executable"
401
402 switch [copy_setup] {
403 "1" {
404 # do nothing
405 }
406 "2" {
407 untested $test1
408 untested $test2
409 untested $test3
410 }
411 "3" {
412 unresolved $test1
413 unresolved $test2
414 unresolved $test3
415 }
416 "0" {
417 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2"
418 strip_executable "$STRIP" "$STRIPFLAGS" "$test3"
419 }
420 }
This page took 0.043215 seconds and 5 git commands to generate.