* binutils-all/objcopy.exp: Polish output about fail for objcopy
[deliverable/binutils-gdb.git] / binutils / testsuite / binutils-all / objcopy.exp
1 # Copyright (C) 1994, 95, 96, 97, 1998 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 ![is_remote host] {
23 if {[which $OBJCOPY] == 0} then {
24 perror "$OBJCOPY does not exist"
25 return
26 }
27 }
28
29 send_user "Version [binutil_version $OBJCOPY]"
30
31 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
32 perror "unresolved 1"
33 unresolved "objcopy (simple copy)"
34 return
35 }
36
37 if ![is_remote host] {
38 set tempfile tmpdir/bintest.o;
39 set copyfile tmpdir/copy;
40 } else {
41 set tempfile [remote_download host tmpdir/bintest.o]
42 set copyfile copy
43 }
44
45 # Test that objcopy does not modify a file when copying it.
46
47 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS $tempfile ${copyfile}.o"]
48
49 if ![string match "" $got] then {
50 fail "objcopy (simple copy)"
51 } else {
52 send_log "cmp $tempfile ${copyfile}.o\n"
53 verbose "cmp $tempfile ${copyfile}.o"
54 if [is_remote host] {
55 set src1 tmpdir/bintest.o
56 set src2 tmpdir/copy.o
57 remote_upload host $tempfile $src1;
58 remote_upload host ${copyfile}.o $src2;
59 } else {
60 set src1 ${tempfile}
61 set src2 ${copyfile}.o
62 }
63 set status [remote_exec build cmp "${src1} ${src2}"];
64 set exec_output [lindex $status 1];
65 set exec_output [prune_warnings $exec_output]
66
67 # On some systems the result of objcopy will not be identical.
68 # Usually this is just because gas isn't using bfd to write the files
69 # in the first place, and may order things a little differently.
70 # Those systems should use setup_xfail here.
71
72 setup_xfail "sh-*-coff" "sh-*-hms"
73 setup_xfail "m68*-*-hpux*" "m68*-*-sunos*" "m68*-*-coff" "m68*-*-vxworks*"
74 setup_xfail "m68*-ericsson-ose" "m68k*-motorola-sysv*"
75 setup_xfail "i*86-*-linuxaout*" "i*86-*-aout*"
76 setup_xfail "i*86-*-sysv3" "i*86-*-isc*" "i*86-*-sco*" "i*86-*-coff"
77 setup_xfail "i*86-*-aix*" "i*86-*-go32*"
78 setup_xfail "a29k-*-udi" "a29k-*-coff" "a29k-*-vxworks*"
79 setup_xfail "i960-*-coff"
80 setup_xfail "h8300-*-hms" "h8300-*-coff"
81 setup_xfail "h8500-*-hms" "h8500-*-coff"
82 setup_xfail "hppa*-*-*"
83 clear_xfail "hppa*-*-*elf*"
84 setup_xfail "m88*-*-coff" "m88*-motorola-sysv*"
85 setup_xfail "z8*-*-coff"
86
87 if [string match "" $exec_output] then {
88 pass "objcopy (simple copy)"
89 } else {
90 send_log "$exec_output\n"
91 verbose "$exec_output" 1
92
93 # On OSF/1, this succeeds with gas and fails with /bin/as.
94 setup_xfail "alpha*-*-osf*"
95
96 # This fails for COFF i960-vxworks targets.
97 setup_xfail "i960-*-vxworks*"
98
99 fail "objcopy (simple copy)"
100 }
101 }
102
103 # Test generating S records.
104
105 # We make the srec filename 8.3 compatible. Note that the header string
106 # matched against depends on the name of the file. Ugh.
107
108 if [is_remote host] {
109 set srecfile copy.sre
110 set header_string S00B0000636F70792E737265C1
111 } else {
112 set srecfile ${copyfile}.srec
113 set header_string S0130000746D706469722F636F70792E7372656397
114 }
115
116 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"]
117
118 if ![string match "" $got] then {
119 fail "objcopy -O srec"
120 } else {
121 if [is_remote host] {
122 remote_upload host ${srecfile} tmpdir/copy.srec;
123 set srecfile tmpdir/copy.srec;
124 }
125 set file [open ${srecfile} r]
126
127 # The first S record is fixed by the file name we are using.
128 gets $file line
129 send_log "$line\n"
130 verbose $line
131 if ![regexp "$header_string.*" $line] {
132 send_log "bad header\n"
133 fail "objcopy -O srec"
134 } else {
135 while {[gets $file line] != -1 \
136 && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} {
137 send_log "$line\n"
138 verbose $line
139 set line "**EOF**"
140 }
141 send_log "$line\n"
142 verbose $line
143 if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then {
144 send_log "bad trailer\n"
145 fail "objcopy -O srec"
146 } else {
147 if {[gets $file line] != -1} then {
148 send_log "garbage at end\n"
149 send_log "$line\n"
150 verbose $line
151 fail "objcopy -O srec"
152 } else {
153 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
154 if ![regexp "file format srec" $got] then {
155 send_log "objdump failed\n"
156 fail "objcopy -O srec"
157 } else {
158 pass "objcopy -O srec"
159 }
160 }
161 }
162 }
163
164 close $file
165 }
166
167 # Test setting and adjusting the start address. We only test this
168 # while generating S records, because we may not be able to set the
169 # start address for other object file formats, and the S record case
170 # is the only useful one anyhow.
171
172 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $tempfile"]
173 if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
174 perror "objdump can not recognize bintest.o"
175 set origstart ""
176 } else {
177 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec --set-start 0x7654"]
178 if ![string match "" $got] then {
179 fail "objcopy --set-start"
180 } else {
181 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
182 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
183 fail "objcopy --set-start"
184 } else {
185 if {$srecstart != 0x7654} then {
186 send_log "$srecstart != 0x7654\n"
187 fail "objcopy --set-start"
188 } else {
189 pass "objcopy --set-start"
190 }
191 }
192 }
193
194 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec --adjust-start 0x123"]
195 if ![string match "" $got] then {
196 fail "objcopy --adjust-start"
197 } else {
198 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
199 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
200 fail "objcopy --adjust-start"
201 } else {
202 if {$srecstart != $origstart + 0x123} then {
203 send_log "$srecstart != $origstart + 0x123\n"
204 fail "objcopy --adjust-start"
205 } else {
206 pass "objcopy --adjust-start"
207 }
208 }
209 }
210 }
211
212 # Test adjusting the overall VMA, and adjusting the VMA of a
213 # particular section. We again only test this when generating S
214 # records.
215
216 set low ""
217 set lowname ""
218
219 set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $tempfile"]
220
221 set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)"
222
223 set got $headers
224 while {[regexp $headers_regexp $got all name size vma rest]} {
225 set vma 0x$vma
226 set size 0x$size
227 if {$size != 0} {
228 if {$low == "" || $vma < $low} {
229 set low $vma
230 set lowname $name
231 }
232 }
233 set got $rest
234 }
235
236 if {$low == "" || $origstart == ""} then {
237 perror "objdump can not recognize bintest.o"
238 } else {
239 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec --adjust-vma 0x123"]
240 if ![string match "" $got] then {
241 fail "objcopy --adjust-vma"
242 } else {
243 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"]
244 set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
245 if ![regexp $want $got all start vma] then {
246 fail "objcopy --adjust-vma"
247 } else {
248 set vma 0x$vma
249 if {$vma != $low + 0x123} then {
250 send_log "$vma != $low + 0x123\n"
251 fail "objcopy --adjust-vma"
252 } else {
253 if {$start != $origstart + 0x123} then {
254 send_log "$start != $origstart + 0x123\n"
255 fail "objcopy --adjust-vma"
256 } else {
257 pass "objcopy --adjust-vma"
258 }
259 }
260 }
261 }
262
263 set arg ""
264 set got $headers
265 while {[regexp $headers_regexp $got all name size vma rest]} {
266 set vma 0x$vma
267 if {$vma == $low} then {
268 set arg "$arg --adjust-section-vma $name+4"
269 }
270 set got $rest
271 }
272
273 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec $arg"]
274 if ![string match "" $got] then {
275 fail "objcopy --adjust-section-vma +"
276 } else {
277 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
278 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
279 if ![regexp $want $got all vma] then {
280 fail "objcopy --adjust-section-vma +"
281 } else {
282 set vma 0x$vma
283 if {$vma != $low + 4} then {
284 send_log "$vma != $low + 4\n"
285 fail "objcopy --adjust-section-vma +"
286 } else {
287 pass "objcopy --adjust-section-vma +"
288 }
289 }
290 }
291
292 regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
293 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec $argeq"]
294 if ![string match "" $got] then {
295 fail "objcopy --adjust-section-vma ="
296 } else {
297 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
298 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
299 if ![regexp $want $got all vma] then {
300 fail "objcopy --adjust-section-vma ="
301 } else {
302 set vma 0x$vma
303 if {$vma != $low + 4} then {
304 send_log "$vma != $low + 4\n"
305 fail "objcopy --adjust-section-vma ="
306 } else {
307 pass "objcopy --adjust-section-vma ="
308 }
309 }
310 }
311 }
312
313 # Test stripping an object.
314
315 proc strip_test { } {
316 global CC
317 global STRIP
318 global STRIPFLAGS
319 global NM
320 global NMFLAGS
321 global srcdir
322 global subdir
323
324 set test "strip"
325
326 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
327 untested $test
328 return
329 }
330
331 if [is_remote host] {
332 set objfile [remote_download host tmpdir/testprog.o];
333 } else {
334 set objfile tmpdir/testprog.o
335 }
336
337 set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"]
338 if ![string match "" $exec_output] {
339 fail $test
340 return
341 }
342
343 set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"]
344 if ![string match "No symbols in *" $exec_output] {
345 fail $test
346 return
347 }
348
349 pass $test
350 }
351
352 strip_test
353
354 # Test stripping an object file with saving a symbol
355
356 proc strip_test_with_saving_a_symbol { } {
357 global CC
358 global STRIP
359 global STRIPFLAGS
360 global NM
361 global NMFLAGS
362 global srcdir
363 global subdir
364
365 set test "strip with saving a symbol"
366
367 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
368 untested $test
369 return
370 }
371
372 if [is_remote host] {
373 set objfile [remote_download host tmpdir/testprog.o];
374 } else {
375 set objfile tmpdir/testprog.o
376 }
377
378 set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main $objfile"]
379 if ![string match "" $exec_output] {
380 fail $test
381 return
382 }
383
384 set exec_output [binutils_run $NM "$NMFLAGS $objfile"]
385 if ![regexp {^([0-9a-fA-F]+)?[ ]+T main} $exec_output] {
386 fail $test
387 return
388 }
389
390 pass $test
391 }
392
393 strip_test_with_saving_a_symbol
394
395 # Build a final executable.
396
397 proc copy_setup { } {
398 global srcdir
399 global subdir
400
401 set res [build_wrapper testglue.o];
402 set flags { debug };
403
404 if { $res != "" } {
405 lappend flags "additional_flags=[lindex $res 1]";
406 set add_libs "testglue.o";
407 } else {
408 set add_libs "";
409 }
410
411 if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/testprog executable $flags] != "" } {
412 return 2
413 }
414
415 set result [remote_load target tmpdir/testprog];
416 set status [lindex $result 0];
417
418 if { $status != "pass" } {
419 perror "unresolved setup, status = $status"
420 return 3
421 }
422
423 return 0
424 }
425
426 # Test copying an executable.
427
428 proc copy_executable { prog flags test1 test2 } {
429
430 if [is_remote host] {
431 set testfile [remote_download host tmpdir/testprog];
432 set testcopy copyprog
433 } else {
434 set testfile tmpdir/testprog
435 set testcopy tmpdir/copyprog
436 }
437 remote_file host delete $testcopy;
438
439 set exec_output [binutils_run $prog "$flags $testfile $testcopy"]
440
441 if ![string match "" $exec_output] {
442 fail $test1
443 fail $test2
444 return
445 }
446
447 if [is_remote host] {
448 remote_upload host $testcopy tmpdir/copyprog
449 }
450
451 set status [remote_exec build "cmp" "tmpdir/testprog tmpdir/copyprog"]
452 set exec_output [lindex $status 1];
453
454 if [string match "" $exec_output] then {
455 pass $test1
456 } else {
457 send_log "$exec_output\n"
458 verbose "$exec_output"
459
460 # This will fail for many reasons. For example, it will most
461 # likely fail if a non-GNU linker is used. Therefore, we do
462 # not insist that it pass. If you are using an assembler and
463 # linker based on the same BFD as objcopy, it is worth
464 # investigating to see why this failure occurs. If we are
465 # cross compiling, we assume that a GNU linker is being used,
466 # and expect it to succeed.
467 if {[isnative]} then {
468 setup_xfail "*-*-*"
469 }
470
471 fail $test1
472 }
473
474 set output [remote_load target tmpdir/copyprog]
475 set status [lindex $output 0];
476 if { $status != "pass" } {
477 fail $test2
478 } else {
479 pass $test2
480 }
481 }
482
483 # Test stripping an executable
484
485 proc strip_executable { prog flags test } {
486 global NM
487 global NMFLAGS
488
489 remote_download build tmpdir/copyprog tmpdir/striprog
490 if [is_remote host] {
491 set copyfile [remote_download host tmpdir/striprog];
492 } else {
493 set copyfile tmpdir/striprog
494 }
495
496 set exec_output [binutils_run $prog "$flags ${copyfile}"]
497 if ![string match "" $exec_output] {
498 fail $test
499 return
500 }
501
502 if [is_remote host] {
503 remote_upload host ${copyfile} tmpdir/striprog;
504 }
505
506 set result [remote_load target tmpdir/striprog]
507 set status [lindex $result 0];
508 if { $status != "pass" } {
509 fail $test
510 return
511 }
512
513 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
514 if ![string match "$copyfile: no symbols*" $exec_output] {
515 fail $test
516 return
517 }
518 pass $test
519 }
520
521 # Test stripping an executable with saving a symbol
522
523 proc strip_executable_with_saving_a_symbol { prog flags test } {
524 global NM
525 global NMFLAGS
526
527 remote_download build tmpdir/copyprog tmpdir/striprog
528 if [is_remote host] {
529 set copyfile [remote_download host tmpdir/striprog];
530 } else {
531 set copyfile tmpdir/striprog
532 }
533
534 set exec_output [binutils_run $prog "$flags ${copyfile}"]
535 if ![string match "" $exec_output] {
536 fail $test
537 return
538 }
539
540 if [is_remote host] {
541 remote_upload host ${copyfile} tmpdir/striprog;
542 }
543
544 set result [remote_load target tmpdir/striprog]
545 set status [lindex $result 0];
546 if { $status != "pass" } {
547 fail $test
548 return
549 }
550
551 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
552 if ![regexp {^[0-9a-fA-F]+ T main} $exec_output] {
553 fail $test
554 return
555 }
556 pass $test
557 }
558
559 set test1 "simple objcopy of executable"
560 set test2 "run objcopy of executable"
561 set test3 "run stripped executable"
562 set test4 "run stripped executable with saving a symbol"
563
564 switch [copy_setup] {
565 "1" {
566 # do nothing
567 }
568 "2" {
569 untested $test1
570 untested $test2
571 untested $test3
572 untested $test4
573 }
574 "3" {
575 unresolved $test1
576 unresolved $test2
577 unresolved $test3
578 unresolved $test4
579 }
580 "0" {
581 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2"
582 strip_executable "$STRIP" "$STRIPFLAGS" "$test3"
583 strip_executable_with_saving_a_symbol "$STRIP" "-K main $STRIPFLAGS" "$test4"
584 }
585 }
This page took 0.044595 seconds and 5 git commands to generate.