Commit | Line | Data |
---|---|---|
aef6203b | 1 | # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
99ad8390 | 2 | # 2004, 2006 |
8c2bc687 | 3 | # Free Software Foundation, Inc. |
252b5132 RH |
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 2 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 | |
b43b5d5f | 17 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
252b5132 RH |
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 | ||
252b5132 | 33 | if ![is_remote host] { |
8d263650 BE |
34 | set tempfile tmpdir/bintest.o |
35 | set copyfile tmpdir/copy | |
252b5132 RH |
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 | ||
64bb95af L |
43 | proc objcopy_test {testname srcfile} { |
44 | global OBJCOPY | |
45 | global OBJCOPYFLAGS | |
46 | global srcdir | |
47 | global subdir | |
48 | global tempfile | |
49 | global copyfile | |
252b5132 | 50 | |
64bb95af L |
51 | if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then { |
52 | perror "unresolved $testname" | |
53 | unresolved "objcopy ($testname)" | |
54 | return | |
252b5132 | 55 | } |
252b5132 | 56 | |
64bb95af L |
57 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS $tempfile ${copyfile}.o"] |
58 | ||
59 | if ![string match "" $got] then { | |
60 | fail "objcopy ($testname)" | |
252b5132 | 61 | } else { |
64bb95af L |
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 | |
252b5132 | 102 | |
64bb95af L |
103 | # On OSF/1, this succeeds with gas and fails with /bin/as. |
104 | setup_xfail "alpha*-*-osf*" | |
252b5132 | 105 | |
64bb95af L |
106 | # This fails for COFF i960-vxworks targets. |
107 | setup_xfail "i960-*-vxworks*" | |
252b5132 | 108 | |
64bb95af L |
109 | fail "objcopy ($testname)" |
110 | } | |
252b5132 RH |
111 | } |
112 | } | |
113 | ||
64bb95af L |
114 | objcopy_test "simple copy" bintest.s |
115 | ||
252b5132 RH |
116 | # Test generating S records. |
117 | ||
118 | # We make the srec filename 8.3 compatible. Note that the header string | |
119 | # matched against depends on the name of the file. Ugh. | |
120 | ||
121 | if [is_remote host] { | |
122 | set srecfile copy.sre | |
123 | set header_string S00B0000636F70792E737265C1 | |
124 | } else { | |
125 | set srecfile ${copyfile}.srec | |
126 | set header_string S0130000746D706469722F636F70792E7372656397 | |
127 | } | |
128 | ||
129 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"] | |
130 | ||
131 | if ![string match "" $got] then { | |
132 | fail "objcopy -O srec" | |
133 | } else { | |
134 | if [is_remote host] { | |
8d263650 BE |
135 | remote_upload host ${srecfile} tmpdir/copy.srec |
136 | set srecfile tmpdir/copy.srec | |
252b5132 RH |
137 | } |
138 | set file [open ${srecfile} r] | |
139 | ||
140 | # The first S record is fixed by the file name we are using. | |
141 | gets $file line | |
142 | send_log "$line\n" | |
143 | verbose $line | |
144 | if ![regexp "$header_string.*" $line] { | |
145 | send_log "bad header\n" | |
146 | fail "objcopy -O srec" | |
147 | } else { | |
148 | while {[gets $file line] != -1 \ | |
149 | && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} { | |
150 | send_log "$line\n" | |
151 | verbose $line | |
152 | set line "**EOF**" | |
153 | } | |
154 | send_log "$line\n" | |
155 | verbose $line | |
156 | if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then { | |
157 | send_log "bad trailer\n" | |
158 | fail "objcopy -O srec" | |
159 | } else { | |
160 | if {[gets $file line] != -1} then { | |
161 | send_log "garbage at end\n" | |
162 | send_log "$line\n" | |
163 | verbose $line | |
164 | fail "objcopy -O srec" | |
165 | } else { | |
166 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] | |
167 | if ![regexp "file format srec" $got] then { | |
168 | send_log "objdump failed\n" | |
169 | fail "objcopy -O srec" | |
170 | } else { | |
171 | pass "objcopy -O srec" | |
172 | } | |
173 | } | |
174 | } | |
175 | } | |
176 | ||
177 | close $file | |
178 | } | |
179 | ||
180 | # Test setting and adjusting the start address. We only test this | |
181 | # while generating S records, because we may not be able to set the | |
182 | # start address for other object file formats, and the S record case | |
183 | # is the only useful one anyhow. | |
184 | ||
185 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $tempfile"] | |
186 | if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then { | |
187 | perror "objdump can not recognize bintest.o" | |
188 | set origstart "" | |
189 | } else { | |
627fe3fb | 190 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --set-start 0x7654 $tempfile ${copyfile}.srec"] |
252b5132 RH |
191 | if ![string match "" $got] then { |
192 | fail "objcopy --set-start" | |
193 | } else { | |
194 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] | |
195 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { | |
196 | fail "objcopy --set-start" | |
197 | } else { | |
198 | if {$srecstart != 0x7654} then { | |
199 | send_log "$srecstart != 0x7654\n" | |
200 | fail "objcopy --set-start" | |
201 | } else { | |
202 | pass "objcopy --set-start" | |
203 | } | |
204 | } | |
205 | } | |
206 | ||
627fe3fb | 207 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-start 0x123 $tempfile ${copyfile}.srec"] |
252b5132 RH |
208 | if ![string match "" $got] then { |
209 | fail "objcopy --adjust-start" | |
210 | } else { | |
211 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] | |
212 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { | |
213 | fail "objcopy --adjust-start" | |
214 | } else { | |
215 | if {$srecstart != $origstart + 0x123} then { | |
216 | send_log "$srecstart != $origstart + 0x123\n" | |
217 | fail "objcopy --adjust-start" | |
218 | } else { | |
219 | pass "objcopy --adjust-start" | |
220 | } | |
221 | } | |
222 | } | |
223 | } | |
224 | ||
225 | # Test adjusting the overall VMA, and adjusting the VMA of a | |
226 | # particular section. We again only test this when generating S | |
227 | # records. | |
228 | ||
229 | set low "" | |
230 | set lowname "" | |
231 | ||
232 | set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $tempfile"] | |
233 | ||
234 | set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)" | |
235 | ||
236 | set got $headers | |
237 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
238 | set vma 0x$vma | |
239 | set size 0x$size | |
240 | if {$size != 0} { | |
241 | if {$low == "" || $vma < $low} { | |
242 | set low $vma | |
243 | set lowname $name | |
244 | } | |
245 | } | |
246 | set got $rest | |
247 | } | |
248 | ||
249 | if {$low == "" || $origstart == ""} then { | |
250 | perror "objdump can not recognize bintest.o" | |
251 | } else { | |
627fe3fb | 252 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-vma 0x123 $tempfile ${copyfile}.srec"] |
252b5132 RH |
253 | if ![string match "" $got] then { |
254 | fail "objcopy --adjust-vma" | |
255 | } else { | |
256 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"] | |
257 | set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" | |
258 | if ![regexp $want $got all start vma] then { | |
259 | fail "objcopy --adjust-vma" | |
260 | } else { | |
261 | set vma 0x$vma | |
262 | if {$vma != $low + 0x123} then { | |
263 | send_log "$vma != $low + 0x123\n" | |
264 | fail "objcopy --adjust-vma" | |
265 | } else { | |
266 | if {$start != $origstart + 0x123} then { | |
267 | send_log "$start != $origstart + 0x123\n" | |
268 | fail "objcopy --adjust-vma" | |
269 | } else { | |
270 | pass "objcopy --adjust-vma" | |
271 | } | |
272 | } | |
273 | } | |
274 | } | |
275 | ||
276 | set arg "" | |
277 | set got $headers | |
278 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
279 | set vma 0x$vma | |
280 | if {$vma == $low} then { | |
281 | set arg "$arg --adjust-section-vma $name+4" | |
282 | } | |
283 | set got $rest | |
284 | } | |
285 | ||
627fe3fb | 286 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $arg $tempfile ${copyfile}.srec"] |
252b5132 RH |
287 | if ![string match "" $got] then { |
288 | fail "objcopy --adjust-section-vma +" | |
289 | } else { | |
290 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"] | |
291 | set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" | |
292 | if ![regexp $want $got all vma] then { | |
293 | fail "objcopy --adjust-section-vma +" | |
294 | } else { | |
295 | set vma 0x$vma | |
296 | if {$vma != $low + 4} then { | |
297 | send_log "$vma != $low + 4\n" | |
298 | fail "objcopy --adjust-section-vma +" | |
299 | } else { | |
300 | pass "objcopy --adjust-section-vma +" | |
301 | } | |
302 | } | |
303 | } | |
304 | ||
305 | regsub -all "\\+4" $arg "=[expr $low + 4]" argeq | |
627fe3fb | 306 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $argeq $tempfile ${copyfile}.srec"] |
252b5132 RH |
307 | if ![string match "" $got] then { |
308 | fail "objcopy --adjust-section-vma =" | |
309 | } else { | |
310 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"] | |
311 | set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" | |
312 | if ![regexp $want $got all vma] then { | |
313 | fail "objcopy --adjust-section-vma =" | |
314 | } else { | |
315 | set vma 0x$vma | |
316 | if {$vma != $low + 4} then { | |
317 | send_log "$vma != $low + 4\n" | |
318 | fail "objcopy --adjust-section-vma =" | |
319 | } else { | |
320 | pass "objcopy --adjust-section-vma =" | |
321 | } | |
322 | } | |
323 | } | |
324 | } | |
325 | ||
326 | # Test stripping an object. | |
327 | ||
328 | proc strip_test { } { | |
1983fbac | 329 | global AR |
252b5132 RH |
330 | global CC |
331 | global STRIP | |
332 | global STRIPFLAGS | |
333 | global NM | |
334 | global NMFLAGS | |
335 | global srcdir | |
336 | global subdir | |
337 | ||
338 | set test "strip" | |
339 | ||
340 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { | |
341 | untested $test | |
342 | return | |
343 | } | |
344 | ||
345 | if [is_remote host] { | |
1983fbac | 346 | set archive libstrip.a |
8d263650 | 347 | set objfile [remote_download host tmpdir/testprog.o] |
1983fbac L |
348 | remote_file host delete $archive |
349 | } else { | |
350 | set archive tmpdir/libstrip.a | |
351 | set objfile tmpdir/testprog.o | |
352 | } | |
353 | ||
354 | remote_file build delete tmpdir/libstrip.a | |
355 | ||
356 | set exec_output [binutils_run $AR "rc $archive ${objfile}"] | |
357 | if ![string match "" $exec_output] { | |
358 | fail $test | |
359 | return | |
360 | } | |
361 | ||
8648f88f L |
362 | set exec_output [binutils_run $STRIP "-g $archive"] |
363 | if ![string match "" $exec_output] { | |
364 | fail $test | |
365 | return | |
366 | } | |
367 | ||
1983fbac L |
368 | set exec_output [binutils_run $STRIP "$STRIPFLAGS $archive"] |
369 | if ![string match "" $exec_output] { | |
370 | fail $test | |
371 | return | |
372 | } | |
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] { | |
8d263650 | 380 | set objfile [remote_download host tmpdir/testprog.o] |
252b5132 RH |
381 | } else { |
382 | set objfile tmpdir/testprog.o | |
383 | } | |
384 | ||
385 | set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"] | |
386 | if ![string match "" $exec_output] { | |
387 | fail $test | |
388 | return | |
389 | } | |
390 | ||
391 | set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"] | |
68a4c073 | 392 | if ![string match "*: no symbols*" $exec_output] { |
252b5132 RH |
393 | fail $test |
394 | return | |
395 | } | |
396 | ||
397 | pass $test | |
398 | } | |
399 | ||
400 | strip_test | |
401 | ||
402 | # Test stripping an object file with saving a symbol | |
403 | ||
404 | proc strip_test_with_saving_a_symbol { } { | |
405 | global CC | |
406 | global STRIP | |
407 | global STRIPFLAGS | |
408 | global NM | |
409 | global NMFLAGS | |
410 | global srcdir | |
411 | global subdir | |
412 | ||
413 | set test "strip with saving a symbol" | |
414 | ||
415 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { | |
416 | untested $test | |
417 | return | |
418 | } | |
419 | ||
420 | if [is_remote host] { | |
8d263650 | 421 | set objfile [remote_download host tmpdir/testprog.o] |
252b5132 RH |
422 | } else { |
423 | set objfile tmpdir/testprog.o | |
424 | } | |
425 | ||
426 | set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main -K _main $objfile"] | |
427 | if ![string match "" $exec_output] { | |
428 | fail $test | |
429 | return | |
430 | } | |
431 | ||
432 | set exec_output [binutils_run $NM "$NMFLAGS $objfile"] | |
195fe636 | 433 | if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \ |
252b5132 RH |
434 | && ![regexp {^([0-9a-fA-F]+)?[ ]+T _main} $exec_output]} { |
435 | fail $test | |
436 | return | |
437 | } | |
438 | ||
439 | pass $test | |
440 | } | |
441 | ||
442 | strip_test_with_saving_a_symbol | |
443 | ||
444 | # Build a final executable. | |
445 | ||
99ad8390 | 446 | if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } { |
f8a7038a NC |
447 | set test_prog "testprog.exe" |
448 | } else { | |
449 | set test_prog "testprog" | |
450 | } | |
451 | ||
252b5132 RH |
452 | proc copy_setup { } { |
453 | global srcdir | |
454 | global subdir | |
9a580d9a | 455 | global gcc_gas_flag |
f8a7038a | 456 | global test_prog |
252b5132 | 457 | |
8d263650 BE |
458 | set res [build_wrapper testglue.o] |
459 | set flags { debug } | |
252b5132 | 460 | |
903b1f5b NS |
461 | if { [istarget *-*-uclinux*] } { |
462 | return 1 | |
463 | } | |
464 | ||
252b5132 | 465 | if { $res != "" } { |
8d263650 BE |
466 | lappend flags "additional_flags=[lindex $res 1]" |
467 | set add_libs "testglue.o" | |
252b5132 | 468 | } else { |
8d263650 | 469 | set add_libs "" |
252b5132 RH |
470 | } |
471 | ||
9a580d9a L |
472 | if { [istarget *-*-linux*] } { |
473 | foreach i $gcc_gas_flag { | |
474 | set flags "additional_flags=$i $flags" | |
475 | } | |
476 | } | |
f8a7038a | 477 | if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/$test_prog executable $flags] != "" } { |
252b5132 RH |
478 | return 2 |
479 | } | |
480 | ||
8d263650 BE |
481 | set result [remote_load target tmpdir/$test_prog] |
482 | set status [lindex $result 0] | |
252b5132 RH |
483 | |
484 | if { $status != "pass" } { | |
485 | perror "unresolved setup, status = $status" | |
486 | return 3 | |
487 | } | |
488 | ||
489 | return 0 | |
490 | } | |
491 | ||
492 | # Test copying an executable. | |
493 | ||
494 | proc copy_executable { prog flags test1 test2 } { | |
f8a7038a | 495 | global test_prog |
252b5132 RH |
496 | |
497 | if [is_remote host] { | |
8d263650 | 498 | set testfile [remote_download host tmpdir/$test_prog] |
252b5132 RH |
499 | set testcopy copyprog |
500 | } else { | |
f8a7038a | 501 | set testfile tmpdir/$test_prog |
252b5132 RH |
502 | set testcopy tmpdir/copyprog |
503 | } | |
8d263650 | 504 | remote_file host delete $testcopy |
252b5132 RH |
505 | |
506 | set exec_output [binutils_run $prog "$flags $testfile $testcopy"] | |
507 | ||
508 | if ![string match "" $exec_output] { | |
509 | fail $test1 | |
510 | fail $test2 | |
511 | return | |
512 | } | |
513 | ||
514 | if [is_remote host] { | |
515 | remote_upload host $testcopy tmpdir/copyprog | |
516 | } | |
517 | ||
f8a7038a | 518 | set status [remote_exec build "cmp" "tmpdir/$test_prog tmpdir/copyprog"] |
8d263650 | 519 | set exec_output [lindex $status 1] |
252b5132 RH |
520 | |
521 | if [string match "" $exec_output] then { | |
522 | pass $test1 | |
523 | } else { | |
524 | send_log "$exec_output\n" | |
525 | verbose "$exec_output" | |
526 | ||
527 | # This will fail for many reasons. For example, it will most | |
528 | # likely fail if a non-GNU linker is used. Therefore, we do | |
529 | # not insist that it pass. If you are using an assembler and | |
530 | # linker based on the same BFD as objcopy, it is worth | |
531 | # investigating to see why this failure occurs. If we are | |
532 | # cross compiling, we assume that a GNU linker is being used, | |
533 | # and expect it to succeed. | |
534 | if {[isnative]} then { | |
535 | setup_xfail "*-*-*" | |
536 | } | |
537 | ||
538 | # This also fails for mips*-*-elf targets. See elf32-mips.c | |
539 | # mips_elf_sym_is_global. | |
540 | setup_xfail "mips*-*-elf" | |
541 | ||
9da7f49f | 542 | setup_xfail "*arm*-*-coff" |
70bbfa26 | 543 | setup_xfail "xscale-*-coff" |
11d47adc | 544 | setup_xfail "arm*-*-pe" |
c58c5ee7 NC |
545 | setup_xfail "thumb*-*-coff" |
546 | setup_xfail "thumb*-*-pe" | |
11d47adc | 547 | |
252b5132 RH |
548 | fail $test1 |
549 | } | |
550 | ||
551 | set output [remote_load target tmpdir/copyprog] | |
8d263650 | 552 | set status [lindex $output 0] |
252b5132 RH |
553 | if { $status != "pass" } { |
554 | fail $test2 | |
555 | } else { | |
556 | pass $test2 | |
557 | } | |
558 | } | |
559 | ||
560 | # Test stripping an executable | |
561 | ||
562 | proc strip_executable { prog flags test } { | |
563 | global NM | |
564 | global NMFLAGS | |
565 | ||
566 | remote_download build tmpdir/copyprog tmpdir/striprog | |
567 | if [is_remote host] { | |
8d263650 | 568 | set copyfile [remote_download host tmpdir/striprog] |
252b5132 RH |
569 | } else { |
570 | set copyfile tmpdir/striprog | |
571 | } | |
572 | ||
573 | set exec_output [binutils_run $prog "$flags ${copyfile}"] | |
574 | if ![string match "" $exec_output] { | |
575 | fail $test | |
576 | return | |
577 | } | |
578 | ||
579 | if [is_remote host] { | |
8d263650 | 580 | remote_upload host ${copyfile} tmpdir/striprog |
252b5132 RH |
581 | } |
582 | ||
583 | set result [remote_load target tmpdir/striprog] | |
8d263650 | 584 | set status [lindex $result 0] |
252b5132 RH |
585 | if { $status != "pass" } { |
586 | fail $test | |
587 | return | |
588 | } | |
589 | ||
590 | set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] | |
68a4c073 | 591 | if ![string match "*: no symbols*" $exec_output] { |
252b5132 RH |
592 | fail $test |
593 | return | |
594 | } | |
595 | pass $test | |
596 | } | |
597 | ||
598 | # Test stripping an executable with saving a symbol | |
599 | ||
600 | proc strip_executable_with_saving_a_symbol { prog flags test } { | |
601 | global NM | |
602 | global NMFLAGS | |
603 | ||
604 | remote_download build tmpdir/copyprog tmpdir/striprog | |
605 | if [is_remote host] { | |
8d263650 | 606 | set copyfile [remote_download host tmpdir/striprog] |
252b5132 RH |
607 | } else { |
608 | set copyfile tmpdir/striprog | |
609 | } | |
610 | ||
611 | set exec_output [binutils_run $prog "$flags ${copyfile}"] | |
612 | if ![string match "" $exec_output] { | |
613 | fail $test | |
614 | return | |
615 | } | |
616 | ||
617 | if [is_remote host] { | |
8d263650 | 618 | remote_upload host ${copyfile} tmpdir/striprog |
252b5132 RH |
619 | } |
620 | ||
621 | set result [remote_load target tmpdir/striprog] | |
8d263650 | 622 | set status [lindex $result 0] |
252b5132 RH |
623 | if { $status != "pass" } { |
624 | fail $test | |
625 | return | |
626 | } | |
627 | ||
628 | set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] | |
edc45ab9 HPN |
629 | if { [istarget mmix-knuth-mmixware] } { |
630 | # Whenever there's a symbol in the mmo format, there's the symbol | |
631 | # Main, so remove it manually from the expected output for sake of | |
632 | # this test. | |
633 | ||
634 | # Using "" not {} to get the \n and \r translated. | |
635 | regsub "^\[0-9a-fA-F\]+\[ \]+T Main\[\n\r\]+" $exec_output "" exec_output | |
636 | } | |
637 | ||
adacfc81 JJ |
638 | if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \ |
639 | && ![regexp {^([0-9a-fA-F]+)?[ ]+[TD] _main} $exec_output]} { | |
252b5132 RH |
640 | fail $test |
641 | return | |
642 | } | |
643 | pass $test | |
644 | } | |
645 | ||
646 | set test1 "simple objcopy of executable" | |
647 | set test2 "run objcopy of executable" | |
648 | set test3 "run stripped executable" | |
649 | set test4 "run stripped executable with saving a symbol" | |
650 | ||
651 | switch [copy_setup] { | |
652 | "1" { | |
653 | # do nothing | |
654 | } | |
655 | "2" { | |
656 | untested $test1 | |
657 | untested $test2 | |
658 | untested $test3 | |
659 | untested $test4 | |
660 | } | |
661 | "3" { | |
662 | unresolved $test1 | |
663 | unresolved $test2 | |
664 | unresolved $test3 | |
665 | unresolved $test4 | |
666 | } | |
667 | "0" { | |
668 | copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2" | |
669 | strip_executable "$STRIP" "$STRIPFLAGS" "$test3" | |
670 | strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test4" | |
671 | } | |
672 | } | |
ad2fb2cd | 673 | |
6a0d0afd L |
674 | proc objcopy_test_readelf {testname srcfile} { |
675 | global OBJCOPY | |
676 | global OBJCOPYFLAGS | |
677 | global READELF | |
678 | global srcdir | |
679 | global subdir | |
680 | ||
681 | if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then { | |
682 | unresolved "objcopy ($testname)" | |
683 | return | |
684 | } | |
685 | ||
686 | verbose -log "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o" | |
687 | catch "exec $OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o" exec_output | |
688 | if ![string match "" $exec_output] then { | |
689 | fail "objcopy ($testname)" | |
004314cc | 690 | return |
6a0d0afd L |
691 | } |
692 | ||
693 | verbose -log "$READELF -a tmpdir/bintest.o > tmpdir/bintest.o.out" | |
694 | catch "exec $READELF -a tmpdir/bintest.o > tmpdir/bintest.o.out" exec_output | |
695 | set exec_output [prune_warnings $exec_output] | |
696 | if ![string match "" $exec_output] then { | |
697 | unresolved "objcopy ($testname)" | |
698 | return | |
699 | } | |
700 | ||
701 | verbose -log "$READELF -a tmpdir/copy.o > tmpdir/copy.o.out" | |
702 | catch "exec $READELF -a tmpdir/copy.o > tmpdir/copy.o.out" exec_output | |
703 | set exec_output [prune_warnings $exec_output] | |
704 | if ![string match "" $exec_output] then { | |
705 | unresolved "objcopy ($testname)" | |
706 | return | |
707 | } | |
708 | ||
709 | verbose -log "diff tmpdir/bintest.o.out tmpdir/copy.o.out" | |
710 | catch "exec diff tmpdir/bintest.o.out tmpdir/copy.o.out" exec_output | |
711 | set exec_output [prune_warnings $exec_output] | |
712 | ||
713 | if [string match "" $exec_output] then { | |
714 | pass "objcopy ($testname)" | |
715 | } else { | |
716 | fail "objcopy ($testname)" | |
717 | } | |
718 | } | |
719 | ||
ad2fb2cd L |
720 | # ia64 specific tests |
721 | if { ([istarget "ia64-*-elf*"] | |
722 | || [istarget "ia64-*-linux*"]) } { | |
64bb95af L |
723 | objcopy_test "ia64 link order" link-order.s |
724 | } | |
ad2fb2cd | 725 | |
64bb95af L |
726 | # ELF specific tests |
727 | if [is_elf_format] { | |
728 | objcopy_test "ELF unknown section type" unknown.s | |
6a0d0afd | 729 | objcopy_test_readelf "ELF group" group.s |
85d7f0b9 | 730 | run_dump_test "copy-1" |
ad2fb2cd | 731 | } |
af3c5dea | 732 | |
af3c5dea | 733 | run_dump_test "copy-2" |
81fc501a | 734 | run_dump_test "copy-3" |
d58c2e3a RS |
735 | |
736 | if [is_elf_format] { | |
737 | run_dump_test "localize-hidden-1" | |
748fc5e9 L |
738 | run_dump_test "strip-1" |
739 | run_dump_test "strip-2" | |
1aa9ef63 | 740 | run_dump_test "strip-3" |
d58c2e3a RS |
741 | } |
742 | run_dump_test "localize-hidden-2" |