* binutils-all/ar.exp: Don't run unique_symbol on msp or hpux.
[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, 2009, 2010
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-*-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 fail "objcopy ($testname)"
107 }
108 }
109 }
110
111 objcopy_test "simple copy" bintest.s
112
113 # Test reversing bytes in a section.
114
115 set reversed ${tempfile}-reversed
116 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -j .data --reverse-bytes=4 $tempfile $reversed"]
117
118 if ![string match "" $got] then {
119 fail "objcopy --reverse-bytes"
120 } else {
121 if [is_remote host] {
122 remote_upload host ${reversed} tmpdir/copy-reversed.o
123 set reversed tmpdir/copy-reversed.o
124 }
125
126 set origdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $tempfile"]
127 set revdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $reversed"]
128
129 set want "^ \[0-9\]+ (\[0-9\]+)"
130 set found_orig [regexp -lineanchor $want $origdata -> origdata]
131 set found_rev [regexp -lineanchor $want $revdata -> revdata]
132
133 if {$found_orig == 0 || $found_rev == 0} then {
134 fail "objcopy --reverse-bytes"
135 } else {
136 scan $origdata "%2x%2x%2x%2x" b1 b2 b3 b4
137 scan $revdata "%2x%2x%2x%2x" c4 c3 c2 c1
138
139 if {$b1 == $c1 && $b2 == $c2 && $b3 == $c3 && $b4 == $c4} then {
140 pass "objcopy --reverse-bytes"
141 } else {
142 fail "objcopy --reverse-bytes"
143 }
144 }
145 }
146
147 # Test interleaved copy of multiple byte width
148
149 set sequence_file sequence_file
150 set file [open ${sequence_file} w]
151 puts ${file} "12345678"
152 close ${file}
153
154 if [is_remote host] {
155 remote_upload host ${sequence_file} tmpdir/sequence_file
156 set sequence_file tmpdir/sequence_file
157 }
158
159 set got [binutils_run $OBJCOPY "-I binary -i 4 -b 0 --interleave-width 2 ${sequence_file} ${copyfile}"]
160
161 if ![string match "" $got] then {
162 fail "objcopy -i --interleave-width"
163 } else {
164 if [is_remote host] {
165 remote_upload host ${copyfile} tmpdir/interleave_output
166 set interleave_output tmpdir/interleave_output
167 } else {
168 set interleave_output ${copyfile}
169 }
170
171 set file [open ${interleave_output} r]
172 gets $file line
173 send_log "$line\n"
174 verbose $line
175
176 if ![string match "1256" $line] then {
177 fail "objcopy -i --interleave-width"
178 }
179 pass "objcopy -i --interleave-width"
180
181 close $file
182 }
183
184 # Test generating S records.
185
186 # We make the srec filename 8.3 compatible. Note that the header string
187 # matched against depends on the name of the file. Ugh.
188
189 if [is_remote host] {
190 set srecfile copy.sre
191 set header_string S00B0000636F70792E737265C1
192 } else {
193 set srecfile ${copyfile}.srec
194 set header_string S0130000746D706469722F636F70792E7372656397
195 }
196
197 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"]
198
199 if ![string match "" $got] then {
200 fail "objcopy -O srec"
201 } else {
202 if [is_remote host] {
203 remote_upload host ${srecfile} tmpdir/copy.srec
204 set srecfile tmpdir/copy.srec
205 }
206 set file [open ${srecfile} r]
207
208 # The first S record is fixed by the file name we are using.
209 gets $file line
210 send_log "$line\n"
211 verbose $line
212 if ![regexp "$header_string.*" $line] {
213 send_log "bad header\n"
214 fail "objcopy -O srec"
215 } else {
216 while {[gets $file line] != -1 \
217 && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} {
218 send_log "$line\n"
219 verbose $line
220 set line "**EOF**"
221 }
222 send_log "$line\n"
223 verbose $line
224 if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then {
225 send_log "bad trailer\n"
226 fail "objcopy -O srec"
227 } else {
228 if {[gets $file line] != -1} then {
229 send_log "garbage at end\n"
230 send_log "$line\n"
231 verbose $line
232 fail "objcopy -O srec"
233 } else {
234 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${srecfile}"]
235 if ![regexp "file format srec" $got] then {
236 send_log "objdump failed\n"
237 fail "objcopy -O srec"
238 } else {
239 pass "objcopy -O srec"
240 }
241 }
242 }
243 }
244
245 close $file
246 }
247
248 # Test setting and adjusting the start address. We only test this
249 # while generating S records, because we may not be able to set the
250 # start address for other object file formats, and the S record case
251 # is the only useful one anyhow.
252
253 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $tempfile"]
254 if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
255 perror "objdump can not recognize bintest.o"
256 set origstart ""
257 } else {
258 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --set-start 0x7654 $tempfile ${copyfile}.srec"]
259 if ![string match "" $got] then {
260 fail "objcopy --set-start"
261 } else {
262 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
263 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
264 fail "objcopy --set-start"
265 } else {
266 if {$srecstart != 0x7654} then {
267 send_log "$srecstart != 0x7654\n"
268 fail "objcopy --set-start"
269 } else {
270 pass "objcopy --set-start"
271 }
272 }
273 }
274
275 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-start 0x123 $tempfile ${copyfile}.srec"]
276 if ![string match "" $got] then {
277 fail "objcopy --adjust-start"
278 } else {
279 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
280 if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
281 fail "objcopy --adjust-start"
282 } else {
283 if {$srecstart != $origstart + 0x123} then {
284 send_log "$srecstart != $origstart + 0x123\n"
285 fail "objcopy --adjust-start"
286 } else {
287 pass "objcopy --adjust-start"
288 }
289 }
290 }
291 }
292
293 # Test adjusting the overall VMA, and adjusting the VMA of a
294 # particular section. We again only test this when generating S
295 # records.
296
297 set low ""
298 set lowname ""
299
300 set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $tempfile"]
301
302 set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)"
303
304 set got $headers
305 while {[regexp $headers_regexp $got all name size vma rest]} {
306 set vma 0x$vma
307 set size 0x$size
308 if {$size != 0} {
309 if {$low == "" || $vma < $low} {
310 set low $vma
311 set lowname $name
312 }
313 }
314 set got $rest
315 }
316
317 if {$low == "" || $origstart == ""} then {
318 perror "objdump can not recognize bintest.o"
319 } else {
320 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-vma 0x123 $tempfile ${copyfile}.srec"]
321 if ![string match "" $got] then {
322 fail "objcopy --adjust-vma"
323 } else {
324 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"]
325 set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
326 if ![regexp $want $got all start vma] then {
327 fail "objcopy --adjust-vma"
328 } else {
329 set vma 0x$vma
330 if {$vma != $low + 0x123} then {
331 send_log "$vma != $low + 0x123\n"
332 fail "objcopy --adjust-vma"
333 } else {
334 if {$start != $origstart + 0x123} then {
335 send_log "$start != $origstart + 0x123\n"
336 fail "objcopy --adjust-vma"
337 } else {
338 pass "objcopy --adjust-vma"
339 }
340 }
341 }
342 }
343
344 set arg ""
345 set got $headers
346 while {[regexp $headers_regexp $got all name size vma rest]} {
347 set vma 0x$vma
348 if {$vma == $low} then {
349 set arg "$arg --adjust-section-vma $name+4"
350 }
351 set got $rest
352 }
353
354 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $arg $tempfile ${copyfile}.srec"]
355 if ![string match "" $got] then {
356 fail "objcopy --adjust-section-vma +"
357 } else {
358 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
359 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
360 if ![regexp $want $got all vma] then {
361 fail "objcopy --adjust-section-vma +"
362 } else {
363 set vma 0x$vma
364 if {$vma != $low + 4} then {
365 send_log "$vma != $low + 4\n"
366 fail "objcopy --adjust-section-vma +"
367 } else {
368 pass "objcopy --adjust-section-vma +"
369 }
370 }
371 }
372
373 regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
374 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $argeq $tempfile ${copyfile}.srec"]
375 if ![string match "" $got] then {
376 fail "objcopy --adjust-section-vma ="
377 } else {
378 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
379 set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
380 if ![regexp $want $got all vma] then {
381 fail "objcopy --adjust-section-vma ="
382 } else {
383 set vma 0x$vma
384 if {$vma != $low + 4} then {
385 send_log "$vma != $low + 4\n"
386 fail "objcopy --adjust-section-vma ="
387 } else {
388 pass "objcopy --adjust-section-vma ="
389 }
390 }
391 }
392 }
393
394 # Test stripping an object.
395
396 proc strip_test { } {
397 global AR
398 global CC
399 global STRIP
400 global STRIPFLAGS
401 global NM
402 global NMFLAGS
403 global srcdir
404 global subdir
405
406 set test "strip"
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 archive libstrip.a
415 set objfile [remote_download host tmpdir/testprog.o]
416 remote_file host delete $archive
417 } else {
418 set archive tmpdir/libstrip.a
419 set objfile tmpdir/testprog.o
420 }
421
422 remote_file build delete tmpdir/libstrip.a
423
424 set exec_output [binutils_run $AR "rc $archive ${objfile}"]
425 if ![string match "" $exec_output] {
426 fail $test
427 return
428 }
429
430 set exec_output [binutils_run $STRIP "-g $archive"]
431 if ![string match "" $exec_output] {
432 fail $test
433 return
434 }
435
436 set exec_output [binutils_run $STRIP "$STRIPFLAGS $archive"]
437 if ![string match "" $exec_output] {
438 fail $test
439 return
440 }
441
442 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
443 untested $test
444 return
445 }
446
447 if [is_remote host] {
448 set objfile [remote_download host tmpdir/testprog.o]
449 } else {
450 set objfile tmpdir/testprog.o
451 }
452
453 set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"]
454 if ![string match "" $exec_output] {
455 fail $test
456 return
457 }
458
459 set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"]
460 if ![string match "*: no symbols*" $exec_output] {
461 fail $test
462 return
463 }
464
465 pass $test
466 }
467
468 strip_test
469
470 # Test stripping an object file with saving a symbol
471
472 proc strip_test_with_saving_a_symbol { } {
473 global CC
474 global STRIP
475 global STRIPFLAGS
476 global NM
477 global NMFLAGS
478 global srcdir
479 global subdir
480
481 set test "strip with saving a symbol"
482
483 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
484 untested $test
485 return
486 }
487
488 if [is_remote host] {
489 set objfile [remote_download host tmpdir/testprog.o]
490 } else {
491 set objfile tmpdir/testprog.o
492 }
493
494 set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main -K _main $objfile"]
495 if ![string match "" $exec_output] {
496 fail $test
497 return
498 }
499
500 set exec_output [binutils_run $NM "$NMFLAGS $objfile"]
501 if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \
502 && ![regexp {^([0-9a-fA-F]+)?[ ]+T _main} $exec_output]} {
503 fail $test
504 return
505 }
506
507 pass $test
508 }
509
510 strip_test_with_saving_a_symbol
511
512 # Build a final executable.
513
514 if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } {
515 set test_prog "testprog.exe"
516 } else {
517 set test_prog "testprog"
518 }
519
520 proc copy_setup { } {
521 global srcdir
522 global subdir
523 global gcc_gas_flag
524 global test_prog
525 global host_triplet
526
527 set res [build_wrapper testglue.o]
528 set flags { debug }
529
530 if { [istarget *-*-uclinux*] } {
531 return 1
532 }
533
534 if { $res != "" } {
535 lappend flags "additional_flags=[lindex $res 1]"
536 set add_libs "testglue.o"
537 } else {
538 set add_libs ""
539 }
540
541 if { [istarget *-*-linux*] } {
542 foreach i $gcc_gas_flag {
543 set flags "additional_flags=$i $flags"
544 }
545 }
546 if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/$test_prog executable $flags] != "" } {
547 return 2
548 }
549
550 set result [remote_load target tmpdir/$test_prog]
551 set status [lindex $result 0]
552
553 if { $status != "pass" } {
554 send_log "cannot run executable, status = ${status} on ${host_triplet}\n"
555 if { [istarget $host_triplet] } {
556 return 3
557 }
558 set status "pass"
559 }
560
561 return 0
562 }
563
564 # Test copying an executable.
565
566 proc copy_executable { prog flags test1 test2 } {
567 global test_prog
568 global host_triplet
569
570 if [is_remote host] {
571 set testfile [remote_download host tmpdir/$test_prog]
572 set testcopy copyprog
573 } else {
574 set testfile tmpdir/$test_prog
575 set testcopy tmpdir/copyprog
576 }
577 remote_file host delete $testcopy
578
579 set exec_output [binutils_run $prog "$flags $testfile $testcopy"]
580
581 if ![string match "" $exec_output] {
582 fail $test1
583 if [string match "" $test2] {
584 return
585 }
586 fail $test2
587 return
588 }
589
590 if [is_remote host] {
591 remote_upload host $testcopy tmpdir/copyprog
592 }
593
594 set status [remote_exec build "cmp" "tmpdir/$test_prog tmpdir/copyprog"]
595 set exec_output [lindex $status 1]
596
597 if [string match "" $exec_output] then {
598 pass $test1
599 } else {
600 send_log "$exec_output\n"
601 verbose "$exec_output"
602
603 # This will fail for many reasons. For example, it will most
604 # likely fail if a non-GNU linker is used. Therefore, we do
605 # not insist that it pass. If you are using an assembler and
606 # linker based on the same BFD as objcopy, it is worth
607 # investigating to see why this failure occurs. If we are
608 # cross compiling, we assume that a GNU linker is being used,
609 # and expect it to succeed.
610 if {[isnative]} then {
611 setup_xfail "*-*-*"
612 }
613
614 # This also fails for mips*-*-elf targets. See elf32-mips.c
615 # mips_elf_sym_is_global.
616 setup_xfail "mips*-*-elf"
617
618 setup_xfail "*arm*-*-coff"
619 setup_xfail "xscale-*-coff"
620 setup_xfail "arm*-*-pe"
621 setup_xfail "thumb*-*-coff"
622 setup_xfail "thumb*-*-pe"
623 setup_xfail "*-*-mingw*"
624 setup_xfail "*-*-cygwin*"
625
626 fail $test1
627 }
628
629 if [string match "" $test2] {
630 return
631 }
632
633 set output [remote_load target tmpdir/copyprog]
634 set status [lindex $output 0]
635 if { ![istarget $host_triplet] } {
636 set status "pass"
637 }
638 if { $status != "pass" } {
639 fail $test2
640 } else {
641 pass $test2
642 }
643 }
644
645 # Test stripping an executable
646
647 proc strip_executable { prog flags test } {
648 global NM
649 global NMFLAGS
650 global host_triplet
651
652 remote_file build delete tmpdir/striprog
653 remote_download build tmpdir/copyprog tmpdir/striprog
654 if [is_remote host] {
655 set copyfile [remote_download host tmpdir/striprog]
656 } else {
657 set copyfile tmpdir/striprog
658 }
659
660 set exec_output [binutils_run $prog "$flags ${copyfile}"]
661 if ![string match "" $exec_output] {
662 fail $test
663 return
664 }
665
666 if [is_remote host] {
667 remote_upload host ${copyfile} tmpdir/striprog
668 }
669
670 set result [remote_load target tmpdir/striprog]
671 set status [lindex $result 0]
672 if { ![istarget $host_triplet] } {
673 set status "pass"
674 }
675 if { $status != "pass" } {
676 fail $test
677 return
678 }
679
680 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
681 if ![string match "*: no symbols*" $exec_output] {
682 fail $test
683 return
684 }
685 pass $test
686 }
687
688 # Test stripping an executable with saving a symbol
689
690 proc strip_executable_with_saving_a_symbol { prog flags test } {
691 global NM
692 global NMFLAGS
693 global host_triplet
694
695 remote_file build delete tmpdir/striprog
696 remote_download build tmpdir/copyprog tmpdir/striprog
697 if [is_remote host] {
698 set copyfile [remote_download host tmpdir/striprog]
699 } else {
700 set copyfile tmpdir/striprog
701 }
702
703 set exec_output [binutils_run $prog "$flags ${copyfile}"]
704 if ![string match "" $exec_output] {
705 fail $test
706 return
707 }
708
709 if [is_remote host] {
710 remote_upload host ${copyfile} tmpdir/striprog
711 }
712
713 set result [remote_load target tmpdir/striprog]
714 set status [lindex $result 0]
715 if { ![istarget $host_triplet] } {
716 set status "pass"
717 }
718 if { $status != "pass" } {
719 fail $test
720 return
721 }
722
723 set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
724 if { [istarget mmix-knuth-mmixware] } {
725 # Whenever there's a symbol in the mmo format, there's the symbol
726 # Main, so remove it manually from the expected output for sake of
727 # this test.
728
729 # Using "" not {} to get the \n and \r translated.
730 regsub "^\[0-9a-fA-F\]+\[ \]+T Main\[\n\r\]+" $exec_output "" exec_output
731 }
732
733 if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \
734 && ![regexp {^([0-9a-fA-F]+)?[ ]+[TD] _main} $exec_output]} {
735 fail $test
736 return
737 }
738 pass $test
739 }
740
741 # Test keeping only debug symbols of an executable
742
743 proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } {
744 global NM
745 global NMFLAGS
746
747 remote_file build delete tmpdir/striprog
748 remote_download build tmpdir/copyprog tmpdir/striprog
749 if [is_remote host] {
750 set copyfile [remote_download host tmpdir/striprog]
751 } else {
752 set copyfile tmpdir/striprog
753 }
754
755 set exec_output [binutils_run $prog1 "$flags1 ${copyfile}"]
756 if ![string match "" $exec_output] {
757 fail $test1
758 return
759 }
760 pass $test1
761
762 set exec_output [binutils_run $prog2 "$flags2 ${copyfile}"]
763 if ![string match "" $exec_output] {
764 fail $test2
765 return
766 }
767 pass $test2
768 }
769
770 set test1 "simple objcopy of executable"
771 set test2 "run objcopy of executable"
772 set test3 "run stripped executable"
773 set test4 "run stripped executable with saving a symbol"
774 set test5 "keep only debug data"
775 set test6 "simple objcopy of debug data"
776
777 switch [copy_setup] {
778 "1" {
779 # do nothing
780 }
781 "2" {
782 untested $test1
783 untested $test2
784 untested $test3
785 untested $test4
786 untested $test5
787 untested $test6
788 }
789 "3" {
790 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" ""
791 unsupported $test2
792 unsupported $test3
793 unsupported $test4
794 unsupported $test5
795 unsupported $test6
796 }
797 "0" {
798 copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2"
799 strip_executable "$STRIP" "$STRIPFLAGS" "$test3"
800 strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test4"
801 keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test5" \
802 "$OBJCOPY" "$OBJCOPYFLAGS" "$test6"
803 }
804 }
805
806 proc objcopy_test_readelf {testname srcfile} {
807 global OBJCOPY
808 global OBJCOPYFLAGS
809 global READELF
810 global srcdir
811 global subdir
812
813 if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then {
814 unresolved "objcopy ($testname)"
815 return
816 }
817
818 verbose -log "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"
819 set exec_output [remote_exec host "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"]
820 if { [lindex $exec_output 0] != 0
821 || ![string match "" [lindex $exec_output 1]] } then {
822 fail "objcopy ($testname)"
823 return
824 }
825
826 verbose -log "$READELF -a tmpdir/bintest.o > tmpdir/bintest.o.out"
827 set exec_output [remote_exec host "$READELF -a tmpdir/bintest.o" "" "/dev/null" "tmpdir/bintest.o.out"]
828 if { [lindex $exec_output 0] != 0 } then {
829 unresolved "objcopy ($testname)"
830 return
831 }
832 set exec_output [prune_warnings [lindex $exec_output 1]]
833 if ![string match "" $exec_output] then {
834 unresolved "objcopy ($testname)"
835 return
836 }
837
838 verbose -log "$READELF -a tmpdir/copy.o > tmpdir/copy.o.out"
839 set exec_output [remote_exec host "$READELF -a tmpdir/copy.o" "" "/dev/null" "tmpdir/copy.o.out"]
840 if { [lindex $exec_output 0] != 0 } then {
841 unresolved "objcopy ($testname)"
842 return
843 }
844 set exec_output [prune_warnings [lindex $exec_output 1]]
845 if ![string match "" $exec_output] then {
846 unresolved "objcopy ($testname)"
847 return
848 }
849
850 verbose -log "diff tmpdir/bintest.o.out tmpdir/copy.o.out"
851 catch "exec diff tmpdir/bintest.o.out tmpdir/copy.o.out" exec_output
852 set exec_output [prune_warnings $exec_output]
853
854 if [string match "" $exec_output] then {
855 pass "objcopy ($testname)"
856 } else {
857 fail "objcopy ($testname)"
858 }
859 }
860
861 # ia64 specific tests
862 if { ([istarget "ia64-*-elf*"]
863 || [istarget "ia64-*-linux*"]) } {
864 objcopy_test "ia64 link order" link-order.s
865 }
866
867 # ELF specific tests
868 if [is_elf_format] {
869 objcopy_test "ELF unknown section type" unknown.s
870 objcopy_test_readelf "ELF group" group.s
871 objcopy_test_readelf "ELF group" group-2.s
872 objcopy_test_readelf "ELF group" group-3.s
873 objcopy_test_readelf "ELF group" group-4.s
874 run_dump_test "group-5"
875 run_dump_test "copy-1"
876 run_dump_test "note-1"
877 }
878
879 run_dump_test "copy-2"
880 run_dump_test "copy-3"
881 run_dump_test "copy-4"
882
883 if [is_elf_format] {
884 run_dump_test "strip-1"
885 run_dump_test "strip-2"
886 run_dump_test "strip-3"
887 run_dump_test "strip-4"
888 run_dump_test "strip-5"
889 run_dump_test "strip-6"
890 run_dump_test "strip-7"
891 run_dump_test "strip-8"
892 run_dump_test "strip-9"
893 if { ![istarget "*-*-hpux*"]
894 && ![istarget "msp*-*-*"] } {
895 run_dump_test "strip-10"
896 }
897
898 if { [istarget "i*86-*"] || [istarget "x86_64-*-*"] } {
899 # Check to make sure we don't strip a symbol named in relocations.
900 set test "objcopy keeps symbols needed by relocs"
901
902 set srcfile $srcdir/$subdir/needed-by-reloc.s
903
904 if {![binutils_assemble $srcfile tmpdir/bintest.o]} then {
905 unresolved $test
906 } else {
907 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS --strip-symbol=foo tmpdir/bintest.o ${copyfile}.o"]
908
909 if [regexp "not stripping symbol `foo' because it is named in a relocation" $got] {
910 pass $test
911 } else {
912 fail $test
913 }
914 }
915 }
916
917 run_dump_test "localize-hidden-1"
918 run_dump_test "testranges"
919 run_dump_test "testranges-ia64"
920
921 run_dump_test "add-section"
922 run_dump_test "add-empty-section"
923
924 run_dump_test "exclude-1a"
925 run_dump_test "exclude-1b"
926 }
927 run_dump_test "localize-hidden-2"
This page took 0.0761 seconds and 5 git commands to generate.