Change sources over to using GPLv3
[deliverable/binutils-gdb.git] / binutils / testsuite / binutils-all / objcopy.exp
1 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2 # 2004, 2006, 2007
3 # Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
18
19 # Please email any bugs, comments, and/or additions to this file to:
20 # bug-dejagnu@prep.ai.mit.edu
21
22 # Written by Ian Lance Taylor <ian@cygnus.com>
23
24 if ![is_remote host] {
25 if {[which $OBJCOPY] == 0} then {
26 perror "$OBJCOPY does not exist"
27 return
28 }
29 }
30
31 send_user "Version [binutil_version $OBJCOPY]"
32
33 if ![is_remote host] {
34 set tempfile tmpdir/bintest.o
35 set copyfile tmpdir/copy
36 } else {
37 set tempfile [remote_download host tmpdir/bintest.o]
38 set copyfile copy
39 }
40
41 # Test that objcopy does not modify a file when copying it.
42
43 proc objcopy_test {testname srcfile} {
44 global OBJCOPY
45 global OBJCOPYFLAGS
46 global srcdir
47 global subdir
48 global tempfile
49 global copyfile
50
51 if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then {
52 perror "unresolved $testname"
53 unresolved "objcopy ($testname)"
54 return
55 }
56
57 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS $tempfile ${copyfile}.o"]
58
59 if ![string match "" $got] then {
60 fail "objcopy ($testname)"
61 } else {
62 send_log "cmp $tempfile ${copyfile}.o\n"
63 verbose "cmp $tempfile ${copyfile}.o"
64 if [is_remote host] {
65 set src1 tmpdir/bintest.o
66 set src2 tmpdir/copy.o
67 remote_upload host $tempfile $src1
68 remote_upload host ${copyfile}.o $src2
69 } else {
70 set src1 ${tempfile}
71 set src2 ${copyfile}.o
72 }
73 set status [remote_exec build cmp "${src1} ${src2}"]
74 set exec_output [lindex $status 1]
75 set exec_output [prune_warnings $exec_output]
76
77 # On some systems the result of objcopy will not be identical.
78 # Usually this is just because gas isn't using bfd to write the
79 # files in the first place, and may order things a little
80 # differently. Those systems should use setup_xfail here.
81
82 setup_xfail "h8300-*-rtems*" "h8300-*-coff"
83 setup_xfail "h8500-*-rtems*" "h8500-*-coff"
84 setup_xfail "hppa*-*-*"
85 setup_xfail "i960-*"
86 setup_xfail "m68*-*-*coff" "m68*-*-hpux*" "m68*-*-lynxos*"
87 setup_xfail "m68*-*-sysv*" "m68*-apple-aux*"
88 setup_xfail "m8*-*"
89 setup_xfail "or32-*-rtems*" "or32-*-coff"
90 setup_xfail "sh-*-coff*" "sh-*-rtems*"
91 setup_xfail "tic4x-*-*" "tic80-*-*" "w65-*"
92
93 clear_xfail "hppa*64*-*-hpux*" "hppa*-*-linux*" "hppa*-*-lites*"
94 clear_xfail "hppa*-*-*n*bsd*" "hppa*-*-rtems*" "*-*-*elf*"
95 clear_xfail "m68*-*-sysv4*"
96
97 if [string match "" $exec_output] then {
98 pass "objcopy ($testname)"
99 } else {
100 send_log "$exec_output\n"
101 verbose "$exec_output" 1
102
103 # On OSF/1, this succeeds with gas and fails with /bin/as.
104 setup_xfail "alpha*-*-osf*"
105
106 # This fails for COFF i960-vxworks targets.
107 setup_xfail "i960-*-vxworks*"
108
109 fail "objcopy ($testname)"
110 }
111 }
112 }
113
114 objcopy_test "simple copy" bintest.s
115
116 # Test reversing bytes in a section.
117
118 set reversed ${tempfile}-reversed
119 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -j .data --reverse-bytes=4 $tempfile $reversed"]
120
121 if ![string match "" $got] then {
122 fail "objcopy --reverse-bytes"
123 } else {
124 if [is_remote host] {
125 remote_upload host ${reversed} tmpdir/copy-reversed.o
126 set reversed tmpdir/copy-reversed.o
127 }
128
129 set origdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $tempfile"]
130 set revdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $reversed"]
131
132 set want "^ \[0-9\]+ (\[0-9\]+)"
133 set found_orig [regexp -lineanchor $want $origdata -> origdata]
134 set found_rev [regexp -lineanchor $want $revdata -> revdata]
135
136 if {$found_orig == 0 || $found_rev == 0} then {
137 fail "objcopy --reverse-bytes"
138 } else {
139 scan $origdata "%2x%2x%2x%2x" b1 b2 b3 b4
140 scan $revdata "%2x%2x%2x%2x" c4 c3 c2 c1
141
142 if {$b1 == $c1 && $b2 == $c2 && $b3 == $c3 && $b4 == $c4} then {
143 pass "objcopy --reverse-bytes"
144 } else {
145 fail "objcopy --reverse-bytes"
146 }
147 }
148 }
149
150 # Test generating S records.
151
152 # We make the srec filename 8.3 compatible. Note that the header string
153 # matched against depends on the name of the file. Ugh.
154
155 if [is_remote host] {
156 set srecfile copy.sre
157 set header_string S00B0000636F70792E737265C1
158 } else {
159 set srecfile ${copyfile}.srec
160 set header_string S0130000746D706469722F636F70792E7372656397
161 }
162
163 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"]
164
165 if ![string match "" $got] then {
166 fail "objcopy -O srec"
167 } else {
168 if [is_remote host] {
169 remote_upload host ${srecfile} tmpdir/copy.srec
170 set srecfile tmpdir/copy.srec
171 }
172 set file [open ${srecfile} r]
173
174 # The first S record is fixed by the file name we are using.
175 gets $file line
176 send_log "$line\n"
177 verbose $line
178 if ![regexp "$header_string.*" $line] {
179 send_log "bad header\n"
180 fail "objcopy -O srec"
181 } else {
182 while {[gets $file line] != -1 \
183 && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} {
184 send_log "$line\n"
185 verbose $line
186 set line "**EOF**"
187 }
188 send_log "$line\n"
189 verbose $line
190 if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then {
191 send_log "bad trailer\n"
192 fail "objcopy -O srec"
193 } else {
194 if {[gets $file line] != -1} then {
195 send_log "garbage at end\n"
196 send_log "$line\n"
197 verbose $line
198 fail "objcopy -O srec"
199 } else {
200 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
201 if ![regexp "file format srec" $got] then {
202 send_log "objdump failed\n"
203 fail "objcopy -O srec"
204 } else {
205 pass "objcopy -O srec"
206 }
207 }
208 }
209 }
210
211 close $file
212 }
213
214 # Test setting and adjusting the start address. We only test this
215 # while generating S records, because we may not be able to set the
216 # start address for other object file formats, and the S record case
217 # is the only useful one anyhow.
218
219 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $tempfile"]
220 if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
221 perror "objdump can not recognize bintest.o"
222 set origstart ""
223 } else {
224 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --set-start 0x7654 $tempfile ${copyfile}.srec"]
225 if ![string match "" $got] then {
226 fail "objcopy --set-start"
227 } else {
228 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
229 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
230 fail "objcopy --set-start"
231 } else {
232 if {$srecstart != 0x7654} then {
233 send_log "$srecstart != 0x7654\n"
234 fail "objcopy --set-start"
235 } else {
236 pass "objcopy --set-start"
237 }
238 }
239 }
240
241 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-start 0x123 $tempfile ${copyfile}.srec"]
242 if ![string match "" $got] then {
243 fail "objcopy --adjust-start"
244 } else {
245 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
246 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
247 fail "objcopy --adjust-start"
248 } else {
249 if {$srecstart != $origstart + 0x123} then {
250 send_log "$srecstart != $origstart + 0x123\n"
251 fail "objcopy --adjust-start"
252 } else {
253 pass "objcopy --adjust-start"
254 }
255 }
256 }
257 }
258
259 # Test adjusting the overall VMA, and adjusting the VMA of a
260 # particular section. We again only test this when generating S
261 # records.
262
263 set low ""
264 set lowname ""
265
266 set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $tempfile"]
267
268 set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)"
269
270 set got $headers
271 while {[regexp $headers_regexp $got all name size vma rest]} {
272 set vma 0x$vma
273 set size 0x$size
274 if {$size != 0} {
275 if {$low == "" || $vma < $low} {
276 set low $vma
277 set lowname $name
278 }
279 }
280 set got $rest
281 }
282
283 if {$low == "" || $origstart == ""} then {
284 perror "objdump can not recognize bintest.o"
285 } else {
286 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-vma 0x123 $tempfile ${copyfile}.srec"]
287 if ![string match "" $got] then {
288 fail "objcopy --adjust-vma"
289 } else {
290 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"]
291 set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
292 if ![regexp $want $got all start vma] then {
293 fail "objcopy --adjust-vma"
294 } else {
295 set vma 0x$vma
296 if {$vma != $low + 0x123} then {
297 send_log "$vma != $low + 0x123\n"
298 fail "objcopy --adjust-vma"
299 } else {
300 if {$start != $origstart + 0x123} then {
301 send_log "$start != $origstart + 0x123\n"
302 fail "objcopy --adjust-vma"
303 } else {
304 pass "objcopy --adjust-vma"
305 }
306 }
307 }
308 }
309
310 set arg ""
311 set got $headers
312 while {[regexp $headers_regexp $got all name size vma rest]} {
313 set vma 0x$vma
314 if {$vma == $low} then {
315 set arg "$arg --adjust-section-vma $name+4"
316 }
317 set got $rest
318 }
319
320 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $arg $tempfile ${copyfile}.srec"]
321 if ![string match "" $got] then {
322 fail "objcopy --adjust-section-vma +"
323 } else {
324 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
325 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
326 if ![regexp $want $got all vma] then {
327 fail "objcopy --adjust-section-vma +"
328 } else {
329 set vma 0x$vma
330 if {$vma != $low + 4} then {
331 send_log "$vma != $low + 4\n"
332 fail "objcopy --adjust-section-vma +"
333 } else {
334 pass "objcopy --adjust-section-vma +"
335 }
336 }
337 }
338
339 regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
340 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $argeq $tempfile ${copyfile}.srec"]
341 if ![string match "" $got] then {
342 fail "objcopy --adjust-section-vma ="
343 } else {
344 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
345 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
346 if ![regexp $want $got all vma] then {
347 fail "objcopy --adjust-section-vma ="
348 } else {
349 set vma 0x$vma
350 if {$vma != $low + 4} then {
351 send_log "$vma != $low + 4\n"
352 fail "objcopy --adjust-section-vma ="
353 } else {
354 pass "objcopy --adjust-section-vma ="
355 }
356 }
357 }
358 }
359
360 # Test stripping an object.
361
362 proc strip_test { } {
363 global AR
364 global CC
365 global STRIP
366 global STRIPFLAGS
367 global NM
368 global NMFLAGS
369 global srcdir
370 global subdir
371
372 set test "strip"
373
374 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
375 untested $test
376 return
377 }
378
379 if [is_remote host] {
380 set archive libstrip.a
381 set objfile [remote_download host tmpdir/testprog.o]
382 remote_file host delete $archive
383 } else {
384 set archive tmpdir/libstrip.a
385 set objfile tmpdir/testprog.o
386 }
387
388 remote_file build delete tmpdir/libstrip.a
389
390 set exec_output [binutils_run $AR "rc $archive ${objfile}"]
391 if ![string match "" $exec_output] {
392 fail $test
393 return
394 }
395
396 set exec_output [binutils_run $STRIP "-g $archive"]
397 if ![string match "" $exec_output] {
398 fail $test
399 return
400 }
401
402 set exec_output [binutils_run $STRIP "$STRIPFLAGS $archive"]
403 if ![string match "" $exec_output] {
404 fail $test
405 return
406 }
407
408 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
409 untested $test
410 return
411 }
412
413 if [is_remote host] {
414 set objfile [remote_download host tmpdir/testprog.o]
415 } else {
416 set objfile tmpdir/testprog.o
417 }
418
419 set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"]
420 if ![string match "" $exec_output] {
421 fail $test
422 return
423 }
424
425 set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"]
426 if ![string match "*: no symbols*" $exec_output] {
427 fail $test
428 return
429 }
430
431 pass $test
432 }
433
434 strip_test
435
436 # Test stripping an object file with saving a symbol
437
438 proc strip_test_with_saving_a_symbol { } {
439 global CC
440 global STRIP
441 global STRIPFLAGS
442 global NM
443 global NMFLAGS
444 global srcdir
445 global subdir
446
447 set test "strip with saving a symbol"
448
449 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
450 untested $test
451 return
452 }
453
454 if [is_remote host] {
455 set objfile [remote_download host tmpdir/testprog.o]
456 } else {
457 set objfile tmpdir/testprog.o
458 }
459
460 set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main -K _main $objfile"]
461 if ![string match "" $exec_output] {
462 fail $test
463 return
464 }
465
466 set exec_output [binutils_run $NM "$NMFLAGS $objfile"]
467 if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \
468 && ![regexp {^([0-9a-fA-F]+)?[ ]+T _main} $exec_output]} {
469 fail $test
470 return
471 }
472
473 pass $test
474 }
475
476 strip_test_with_saving_a_symbol
477
478 # Build a final executable.
479
480 if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } {
481 set test_prog "testprog.exe"
482 } else {
483 set test_prog "testprog"
484 }
485
486 proc copy_setup { } {
487 global srcdir
488 global subdir
489 global gcc_gas_flag
490 global test_prog
491
492 set res [build_wrapper testglue.o]
493 set flags { debug }
494
495 if { [istarget *-*-uclinux*] } {
496 return 1
497 }
498
499 if { $res != "" } {
500 lappend flags "additional_flags=[lindex $res 1]"
501 set add_libs "testglue.o"
502 } else {
503 set add_libs ""
504 }
505
506 if { [istarget *-*-linux*] } {
507 foreach i $gcc_gas_flag {
508 set flags "additional_flags=$i $flags"
509 }
510 }
511 if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/$test_prog executable $flags] != "" } {
512 return 2
513 }
514
515 set result [remote_load target tmpdir/$test_prog]
516 set status [lindex $result 0]
517
518 if { $status != "pass" } {
519 send_log "cannot run executable, status = ${status}\n"
520 return 3
521 }
522
523 return 0
524 }
525
526 # Test copying an executable.
527
528 proc copy_executable { prog flags test1 test2 } {
529 global test_prog
530
531 if [is_remote host] {
532 set testfile [remote_download host tmpdir/$test_prog]
533 set testcopy copyprog
534 } else {
535 set testfile tmpdir/$test_prog
536 set testcopy tmpdir/copyprog
537 }
538 remote_file host delete $testcopy
539
540 set exec_output [binutils_run $prog "$flags $testfile $testcopy"]
541
542 if ![string match "" $exec_output] {
543 fail $test1
544 if [string match "" $test2] {
545 return
546 }
547 fail $test2
548 return
549 }
550
551 if [is_remote host] {
552 remote_upload host $testcopy tmpdir/copyprog
553 }
554
555 set status [remote_exec build "cmp" "tmpdir/$test_prog tmpdir/copyprog"]
556 set exec_output [lindex $status 1]
557
558 if [string match "" $exec_output] then {
559 pass $test1
560 } else {
561 send_log "$exec_output\n"
562 verbose "$exec_output"
563
564 # This will fail for many reasons. For example, it will most
565 # likely fail if a non-GNU linker is used. Therefore, we do
566 # not insist that it pass. If you are using an assembler and
567 # linker based on the same BFD as objcopy, it is worth
568 # investigating to see why this failure occurs. If we are
569 # cross compiling, we assume that a GNU linker is being used,
570 # and expect it to succeed.
571 if {[isnative]} then {
572 setup_xfail "*-*-*"
573 }
574
575 # This also fails for mips*-*-elf targets. See elf32-mips.c
576 # mips_elf_sym_is_global.
577 setup_xfail "mips*-*-elf"
578
579 setup_xfail "*arm*-*-coff"
580 setup_xfail "xscale-*-coff"
581 setup_xfail "arm*-*-pe"
582 setup_xfail "thumb*-*-coff"
583 setup_xfail "thumb*-*-pe"
584
585 fail $test1
586 }
587
588 if [string match "" $test2] {
589 return
590 }
591
592 set output [remote_load target tmpdir/copyprog]
593 set status [lindex $output 0]
594 if { $status != "pass" } {
595 fail $test2
596 } else {
597 pass $test2
598 }
599 }
600
601 # Test stripping an executable
602
603 proc strip_executable { prog flags test } {
604 global NM
605 global NMFLAGS
606
607 remote_download build tmpdir/copyprog tmpdir/striprog
608 if [is_remote host] {
609 set copyfile [remote_download host tmpdir/striprog]
610 } else {
611 set copyfile tmpdir/striprog
612 }
613
614 set exec_output [binutils_run $prog "$flags ${copyfile}"]
615 if ![string match "" $exec_output] {
616 fail $test
617 return
618 }
619
620 if [is_remote host] {
621 remote_upload host ${copyfile} tmpdir/striprog
622 }
623
624 set result [remote_load target tmpdir/striprog]
625 set status [lindex $result 0]
626 if { $status != "pass" } {
627 fail $test
628 return
629 }
630
631 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
632 if ![string match "*: no symbols*" $exec_output] {
633 fail $test
634 return
635 }
636 pass $test
637 }
638
639 # Test stripping an executable with saving a symbol
640
641 proc strip_executable_with_saving_a_symbol { prog flags test } {
642 global NM
643 global NMFLAGS
644
645 remote_download build tmpdir/copyprog tmpdir/striprog
646 if [is_remote host] {
647 set copyfile [remote_download host tmpdir/striprog]
648 } else {
649 set copyfile tmpdir/striprog
650 }
651
652 set exec_output [binutils_run $prog "$flags ${copyfile}"]
653 if ![string match "" $exec_output] {
654 fail $test
655 return
656 }
657
658 if [is_remote host] {
659 remote_upload host ${copyfile} tmpdir/striprog
660 }
661
662 set result [remote_load target tmpdir/striprog]
663 set status [lindex $result 0]
664 if { $status != "pass" } {
665 fail $test
666 return
667 }
668
669 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
670 if { [istarget mmix-knuth-mmixware] } {
671 # Whenever there's a symbol in the mmo format, there's the symbol
672 # Main, so remove it manually from the expected output for sake of
673 # this test.
674
675 # Using "" not {} to get the \n and \r translated.
676 regsub "^\[0-9a-fA-F\]+\[ \]+T Main\[\n\r\]+" $exec_output "" exec_output
677 }
678
679 if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \
680 && ![regexp {^([0-9a-fA-F]+)?[ ]+[TD] _main} $exec_output]} {
681 fail $test
682 return
683 }
684 pass $test
685 }
686
687 set test1 "simple objcopy of executable"
688 set test2 "run objcopy of executable"
689 set test3 "run stripped executable"
690 set test4 "run stripped executable with saving a symbol"
691
692 switch [copy_setup] {
693 "1" {
694 # do nothing
695 }
696 "2" {
697 untested $test1
698 untested $test2
699 untested $test3
700 untested $test4
701 }
702 "3" {
703 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" ""
704 unsupported $test2
705 unsupported $test3
706 unsupported $test4
707 }
708 "0" {
709 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2"
710 strip_executable "$STRIP" "$STRIPFLAGS" "$test3"
711 strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test4"
712 }
713 }
714
715 proc objcopy_test_readelf {testname srcfile} {
716 global OBJCOPY
717 global OBJCOPYFLAGS
718 global READELF
719 global srcdir
720 global subdir
721
722 if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then {
723 unresolved "objcopy ($testname)"
724 return
725 }
726
727 verbose -log "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"
728 catch "exec $OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o" exec_output
729 if ![string match "" $exec_output] then {
730 fail "objcopy ($testname)"
731 return
732 }
733
734 verbose -log "$READELF -a tmpdir/bintest.o > tmpdir/bintest.o.out"
735 catch "exec $READELF -a tmpdir/bintest.o > tmpdir/bintest.o.out" exec_output
736 set exec_output [prune_warnings $exec_output]
737 if ![string match "" $exec_output] then {
738 unresolved "objcopy ($testname)"
739 return
740 }
741
742 verbose -log "$READELF -a tmpdir/copy.o > tmpdir/copy.o.out"
743 catch "exec $READELF -a tmpdir/copy.o > tmpdir/copy.o.out" exec_output
744 set exec_output [prune_warnings $exec_output]
745 if ![string match "" $exec_output] then {
746 unresolved "objcopy ($testname)"
747 return
748 }
749
750 verbose -log "diff tmpdir/bintest.o.out tmpdir/copy.o.out"
751 catch "exec diff tmpdir/bintest.o.out tmpdir/copy.o.out" exec_output
752 set exec_output [prune_warnings $exec_output]
753
754 if [string match "" $exec_output] then {
755 pass "objcopy ($testname)"
756 } else {
757 fail "objcopy ($testname)"
758 }
759 }
760
761 # ia64 specific tests
762 if { ([istarget "ia64-*-elf*"]
763 || [istarget "ia64-*-linux*"]) } {
764 objcopy_test "ia64 link order" link-order.s
765 }
766
767 # ELF specific tests
768 if [is_elf_format] {
769 objcopy_test "ELF unknown section type" unknown.s
770 objcopy_test_readelf "ELF group" group.s
771 run_dump_test "copy-1"
772 }
773
774 run_dump_test "copy-2"
775 run_dump_test "copy-3"
776
777 if [is_elf_format] {
778 run_dump_test "strip-1"
779 run_dump_test "strip-2"
780 run_dump_test "strip-3"
781
782 if { [istarget "i*86-*"] || [istarget "x86_64-*-*"] } {
783 # Check to make sure we don't strip a symbol named in relocations.
784 set test "objcopy keeps symbols needed by relocs"
785
786 set srcfile $srcdir/$subdir/needed-by-reloc.s
787
788 if {![binutils_assemble $srcfile tmpdir/bintest.o]} then {
789 unresolved $test
790 } else {
791 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS --strip-symbol=foo tmpdir/bintest.o ${copyfile}.o"]
792
793 if [regexp "not stripping symbol `foo' because it is named in a relocation" $got] {
794 pass $test
795 } else {
796 fail $test
797 }
798 }
799 }
800
801 run_dump_test "localize-hidden-1"
802 }
803 run_dump_test "localize-hidden-2"
This page took 0.070837 seconds and 5 git commands to generate.