Commit | Line | Data |
---|---|---|
219d1afa | 1 | # Copyright (C) 1994-2018 Free Software Foundation, Inc. |
252b5132 RH |
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 | |
32866df7 | 5 | # the Free Software Foundation; either version 3 of the License, or |
252b5132 | 6 | # (at your option) any later version. |
21c40443 | 7 | # |
252b5132 RH |
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. | |
21c40443 | 12 | # |
252b5132 RH |
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 | |
b43b5d5f | 15 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
252b5132 RH |
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 | ||
252b5132 | 31 | if ![is_remote host] { |
8d263650 BE |
32 | set tempfile tmpdir/bintest.o |
33 | set copyfile tmpdir/copy | |
252b5132 RH |
34 | } else { |
35 | set tempfile [remote_download host tmpdir/bintest.o] | |
36 | set copyfile copy | |
37 | } | |
38 | ||
39 | # Test that objcopy does not modify a file when copying it. | |
40 | ||
64bb95af L |
41 | proc objcopy_test {testname srcfile} { |
42 | global OBJCOPY | |
43 | global OBJCOPYFLAGS | |
44 | global srcdir | |
45 | global subdir | |
46 | global tempfile | |
47 | global copyfile | |
252b5132 | 48 | |
96037eb0 | 49 | if {![binutils_assemble $srcdir/$subdir/${srcfile} $tempfile]} then { |
64bb95af | 50 | unresolved "objcopy ($testname)" |
96037eb0 | 51 | remote_file host delete $tempfile |
64bb95af | 52 | return |
252b5132 | 53 | } |
252b5132 | 54 | |
64bb95af L |
55 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS $tempfile ${copyfile}.o"] |
56 | ||
21c40443 | 57 | if ![string equal "" $got] then { |
64bb95af | 58 | fail "objcopy ($testname)" |
252b5132 | 59 | } else { |
64bb95af L |
60 | send_log "cmp $tempfile ${copyfile}.o\n" |
61 | verbose "cmp $tempfile ${copyfile}.o" | |
62 | if [is_remote host] { | |
63 | set src1 tmpdir/bintest.o | |
64 | set src2 tmpdir/copy.o | |
65 | remote_upload host $tempfile $src1 | |
66 | remote_upload host ${copyfile}.o $src2 | |
67 | } else { | |
68 | set src1 ${tempfile} | |
69 | set src2 ${copyfile}.o | |
70 | } | |
71 | set status [remote_exec build cmp "${src1} ${src2}"] | |
72 | set exec_output [lindex $status 1] | |
73 | set exec_output [prune_warnings $exec_output] | |
74 | ||
75 | # On some systems the result of objcopy will not be identical. | |
76 | # Usually this is just because gas isn't using bfd to write the | |
77 | # files in the first place, and may order things a little | |
78 | # differently. Those systems should use setup_xfail here. | |
79 | ||
64bb95af L |
80 | setup_xfail "h8500-*-rtems*" "h8500-*-coff" |
81 | setup_xfail "hppa*-*-*" | |
64bb95af L |
82 | setup_xfail "m68*-*-*coff" "m68*-*-hpux*" "m68*-*-lynxos*" |
83 | setup_xfail "m68*-*-sysv*" "m68*-apple-aux*" | |
84 | setup_xfail "m8*-*" | |
b0a0c50a AM |
85 | setup_xfail "sh-*-coff*" |
86 | setup_xfail "tic80-*-*" "w65-*" | |
64bb95af L |
87 | |
88 | clear_xfail "hppa*64*-*-hpux*" "hppa*-*-linux*" "hppa*-*-lites*" | |
89 | clear_xfail "hppa*-*-*n*bsd*" "hppa*-*-rtems*" "*-*-*elf*" | |
90 | clear_xfail "m68*-*-sysv4*" | |
91 | ||
21c40443 | 92 | if [string equal "" $exec_output] then { |
64bb95af L |
93 | pass "objcopy ($testname)" |
94 | } else { | |
95 | send_log "$exec_output\n" | |
96 | verbose "$exec_output" 1 | |
252b5132 | 97 | |
64bb95af L |
98 | # On OSF/1, this succeeds with gas and fails with /bin/as. |
99 | setup_xfail "alpha*-*-osf*" | |
252b5132 | 100 | |
64bb95af L |
101 | fail "objcopy ($testname)" |
102 | } | |
252b5132 RH |
103 | } |
104 | } | |
105 | ||
64bb95af L |
106 | objcopy_test "simple copy" bintest.s |
107 | ||
96037eb0 NC |
108 | if { [file exists $tempfile] } { |
109 | # Test reversing bytes in a section. | |
9e48b4c6 | 110 | |
96037eb0 NC |
111 | set reversed ${tempfile}-reversed |
112 | set sect_names [get_standard_section_names] | |
113 | if { $sect_names != "" } { | |
114 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -j [lindex $sect_names 1] --reverse-bytes=4 $tempfile $reversed"] | |
115 | } else { | |
116 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -j .data --reverse-bytes=4 $tempfile $reversed"] | |
9e48b4c6 NC |
117 | } |
118 | ||
96037eb0 NC |
119 | if ![string equal "" $got] then { |
120 | fail "objcopy --reverse-bytes" | |
121 | } else { | |
122 | if [is_remote host] { | |
123 | remote_upload host ${reversed} tmpdir/copy-reversed.o | |
124 | set reversed tmpdir/copy-reversed.o | |
125 | } | |
9e48b4c6 | 126 | |
96037eb0 NC |
127 | set origdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $tempfile"] |
128 | set revdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $reversed"] | |
9e48b4c6 | 129 | |
96037eb0 NC |
130 | set want "^ \[0-9\]+ (\[0-9\]+)" |
131 | set found_orig [regexp -lineanchor $want $origdata -> origdata] | |
132 | set found_rev [regexp -lineanchor $want $revdata -> revdata] | |
8941d5e8 | 133 | |
96037eb0 NC |
134 | if {$found_orig == 0 || $found_rev == 0} then { |
135 | # som doesn't have a .data section | |
136 | setup_xfail "hppa*-*-hpux*" | |
137 | clear_xfail "hppa*64*-*-hpux*" | |
9e48b4c6 | 138 | |
96037eb0 NC |
139 | fail "objcopy --reverse-bytes" |
140 | } else { | |
141 | scan $origdata "%2x%2x%2x%2x" b1 b2 b3 b4 | |
142 | scan $revdata "%2x%2x%2x%2x" c4 c3 c2 c1 | |
143 | ||
144 | if {$b1 == $c1 && $b2 == $c2 && $b3 == $c3 && $b4 == $c4} then { | |
145 | pass "objcopy --reverse-bytes" | |
146 | } else { | |
147 | fail "objcopy --reverse-bytes" | |
148 | } | |
149 | } | |
9e48b4c6 NC |
150 | } |
151 | } | |
152 | ||
b7dd81f7 NC |
153 | # Test interleaved copy of multiple byte width |
154 | ||
155 | set sequence_file sequence_file | |
156 | set file [open ${sequence_file} w] | |
157 | puts ${file} "12345678" | |
158 | close ${file} | |
159 | ||
160 | if [is_remote host] { | |
161 | remote_upload host ${sequence_file} tmpdir/sequence_file | |
162 | set sequence_file tmpdir/sequence_file | |
163 | } | |
164 | ||
165 | set got [binutils_run $OBJCOPY "-I binary -i 4 -b 0 --interleave-width 2 ${sequence_file} ${copyfile}"] | |
166 | ||
21c40443 | 167 | if ![string equal "" $got] then { |
b7dd81f7 NC |
168 | fail "objcopy -i --interleave-width" |
169 | } else { | |
170 | if [is_remote host] { | |
171 | remote_upload host ${copyfile} tmpdir/interleave_output | |
172 | set interleave_output tmpdir/interleave_output | |
173 | } else { | |
174 | set interleave_output ${copyfile} | |
175 | } | |
176 | ||
177 | set file [open ${interleave_output} r] | |
178 | gets $file line | |
179 | send_log "$line\n" | |
180 | verbose $line | |
181 | ||
21c40443 | 182 | if ![string equal "1256" $line] then { |
b7dd81f7 NC |
183 | fail "objcopy -i --interleave-width" |
184 | } | |
185 | pass "objcopy -i --interleave-width" | |
186 | ||
187 | close $file | |
188 | } | |
189 | ||
252b5132 RH |
190 | # Test generating S records. |
191 | ||
96037eb0 NC |
192 | if { [file exists $tempfile] } { |
193 | # We make the srec filename 8.3 compatible. Note that the header string | |
194 | # matched against depends on the name of the file. Ugh. | |
252b5132 | 195 | |
252b5132 | 196 | if [is_remote host] { |
96037eb0 NC |
197 | set srecfile copy.sre |
198 | set header_string S00B0000636F70792E737265C1 | |
199 | } else { | |
200 | set srecfile ${copyfile}.srec | |
201 | set header_string S0130000746D706469722F636F70792E7372656397 | |
252b5132 | 202 | } |
252b5132 | 203 | |
96037eb0 NC |
204 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"] |
205 | ||
206 | if ![string equal "" $got] then { | |
252b5132 RH |
207 | fail "objcopy -O srec" |
208 | } else { | |
96037eb0 NC |
209 | if [is_remote host] { |
210 | remote_upload host ${srecfile} tmpdir/copy.srec | |
211 | set srecfile tmpdir/copy.srec | |
252b5132 | 212 | } |
96037eb0 NC |
213 | set file [open ${srecfile} r] |
214 | ||
215 | # The first S record is fixed by the file name we are using. | |
216 | gets $file line | |
252b5132 RH |
217 | send_log "$line\n" |
218 | verbose $line | |
96037eb0 NC |
219 | if ![regexp "$header_string.*" $line] { |
220 | send_log "bad header\n" | |
252b5132 RH |
221 | fail "objcopy -O srec" |
222 | } else { | |
96037eb0 NC |
223 | while {[gets $file line] != -1 \ |
224 | && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} { | |
252b5132 RH |
225 | send_log "$line\n" |
226 | verbose $line | |
96037eb0 NC |
227 | set line "**EOF**" |
228 | } | |
229 | send_log "$line\n" | |
230 | verbose $line | |
231 | if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then { | |
232 | send_log "bad trailer\n" | |
252b5132 RH |
233 | fail "objcopy -O srec" |
234 | } else { | |
96037eb0 NC |
235 | if {[gets $file line] != -1} then { |
236 | send_log "garbage at end\n" | |
237 | send_log "$line\n" | |
238 | verbose $line | |
252b5132 RH |
239 | fail "objcopy -O srec" |
240 | } else { | |
96037eb0 NC |
241 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${srecfile}"] |
242 | if ![regexp "file format srec" $got] then { | |
243 | send_log "objdump failed\n" | |
244 | fail "objcopy -O srec" | |
245 | } else { | |
246 | pass "objcopy -O srec" | |
247 | } | |
252b5132 RH |
248 | } |
249 | } | |
250 | } | |
252b5132 | 251 | |
96037eb0 NC |
252 | close $file |
253 | } | |
252b5132 RH |
254 | } |
255 | ||
256 | # Test setting and adjusting the start address. We only test this | |
257 | # while generating S records, because we may not be able to set the | |
258 | # start address for other object file formats, and the S record case | |
259 | # is the only useful one anyhow. | |
260 | ||
261 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $tempfile"] | |
262 | if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then { | |
263 | perror "objdump can not recognize bintest.o" | |
264 | set origstart "" | |
265 | } else { | |
627fe3fb | 266 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --set-start 0x7654 $tempfile ${copyfile}.srec"] |
21c40443 | 267 | if ![string equal "" $got] then { |
252b5132 RH |
268 | fail "objcopy --set-start" |
269 | } else { | |
270 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] | |
271 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { | |
272 | fail "objcopy --set-start" | |
273 | } else { | |
274 | if {$srecstart != 0x7654} then { | |
275 | send_log "$srecstart != 0x7654\n" | |
276 | fail "objcopy --set-start" | |
277 | } else { | |
278 | pass "objcopy --set-start" | |
279 | } | |
280 | } | |
281 | } | |
282 | ||
627fe3fb | 283 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-start 0x123 $tempfile ${copyfile}.srec"] |
21c40443 | 284 | if ![string equal "" $got] then { |
252b5132 RH |
285 | fail "objcopy --adjust-start" |
286 | } else { | |
287 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] | |
288 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { | |
289 | fail "objcopy --adjust-start" | |
290 | } else { | |
291 | if {$srecstart != $origstart + 0x123} then { | |
292 | send_log "$srecstart != $origstart + 0x123\n" | |
293 | fail "objcopy --adjust-start" | |
294 | } else { | |
295 | pass "objcopy --adjust-start" | |
296 | } | |
297 | } | |
298 | } | |
299 | } | |
300 | ||
301 | # Test adjusting the overall VMA, and adjusting the VMA of a | |
302 | # particular section. We again only test this when generating S | |
303 | # records. | |
304 | ||
305 | set low "" | |
306 | set lowname "" | |
307 | ||
308 | set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $tempfile"] | |
309 | ||
310 | set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)" | |
311 | ||
312 | set got $headers | |
313 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
314 | set vma 0x$vma | |
315 | set size 0x$size | |
316 | if {$size != 0} { | |
317 | if {$low == "" || $vma < $low} { | |
318 | set low $vma | |
319 | set lowname $name | |
320 | } | |
321 | } | |
322 | set got $rest | |
323 | } | |
324 | ||
325 | if {$low == "" || $origstart == ""} then { | |
326 | perror "objdump can not recognize bintest.o" | |
327 | } else { | |
627fe3fb | 328 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-vma 0x123 $tempfile ${copyfile}.srec"] |
21c40443 | 329 | if ![string equal "" $got] then { |
252b5132 RH |
330 | fail "objcopy --adjust-vma" |
331 | } else { | |
332 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"] | |
333 | set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" | |
334 | if ![regexp $want $got all start vma] then { | |
335 | fail "objcopy --adjust-vma" | |
336 | } else { | |
337 | set vma 0x$vma | |
338 | if {$vma != $low + 0x123} then { | |
339 | send_log "$vma != $low + 0x123\n" | |
340 | fail "objcopy --adjust-vma" | |
341 | } else { | |
342 | if {$start != $origstart + 0x123} then { | |
343 | send_log "$start != $origstart + 0x123\n" | |
344 | fail "objcopy --adjust-vma" | |
345 | } else { | |
346 | pass "objcopy --adjust-vma" | |
347 | } | |
348 | } | |
349 | } | |
350 | } | |
351 | ||
352 | set arg "" | |
353 | set got $headers | |
354 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
355 | set vma 0x$vma | |
356 | if {$vma == $low} then { | |
357 | set arg "$arg --adjust-section-vma $name+4" | |
358 | } | |
359 | set got $rest | |
360 | } | |
361 | ||
627fe3fb | 362 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $arg $tempfile ${copyfile}.srec"] |
21c40443 | 363 | if ![string equal "" $got] then { |
252b5132 RH |
364 | fail "objcopy --adjust-section-vma +" |
365 | } else { | |
366 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"] | |
367 | set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" | |
368 | if ![regexp $want $got all vma] then { | |
369 | fail "objcopy --adjust-section-vma +" | |
370 | } else { | |
371 | set vma 0x$vma | |
372 | if {$vma != $low + 4} then { | |
373 | send_log "$vma != $low + 4\n" | |
374 | fail "objcopy --adjust-section-vma +" | |
375 | } else { | |
376 | pass "objcopy --adjust-section-vma +" | |
377 | } | |
378 | } | |
379 | } | |
380 | ||
381 | regsub -all "\\+4" $arg "=[expr $low + 4]" argeq | |
627fe3fb | 382 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $argeq $tempfile ${copyfile}.srec"] |
21c40443 | 383 | if ![string equal "" $got] then { |
252b5132 RH |
384 | fail "objcopy --adjust-section-vma =" |
385 | } else { | |
386 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"] | |
387 | set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" | |
388 | if ![regexp $want $got all vma] then { | |
389 | fail "objcopy --adjust-section-vma =" | |
390 | } else { | |
391 | set vma 0x$vma | |
392 | if {$vma != $low + 4} then { | |
393 | send_log "$vma != $low + 4\n" | |
394 | fail "objcopy --adjust-section-vma =" | |
395 | } else { | |
396 | pass "objcopy --adjust-section-vma =" | |
397 | } | |
398 | } | |
399 | } | |
400 | } | |
401 | ||
402 | # Test stripping an object. | |
403 | ||
404 | proc strip_test { } { | |
1983fbac | 405 | global AR |
252b5132 RH |
406 | global CC |
407 | global STRIP | |
408 | global STRIPFLAGS | |
409 | global NM | |
410 | global NMFLAGS | |
411 | global srcdir | |
412 | global subdir | |
28902555 | 413 | global READELF |
252b5132 RH |
414 | |
415 | set test "strip" | |
416 | ||
417 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { | |
418 | untested $test | |
419 | return | |
420 | } | |
421 | ||
28902555 BS |
422 | set osabi_fail "false" |
423 | if [is_elf_format] { | |
424 | verbose -log "$READELF -a tmpdir/testprog.o > tmpdir/osabi.in" | |
425 | set exec_output [remote_exec host "$READELF -h tmpdir/testprog.o" "" "/dev/null" "tmpdir/osabi.in"] | |
426 | if { [lindex $exec_output 0] != 0 } then { | |
21c40443 | 427 | unresolved "$test preserving OS/ABI" |
28902555 BS |
428 | set osabi_fail "true" |
429 | } else { | |
430 | verbose -log "grep OS/ABI tmpdir/osabi.in" | |
431 | catch "exec grep OS/ABI tmpdir/osabi.in" osabi_in | |
432 | } | |
433 | } | |
434 | ||
252b5132 | 435 | if [is_remote host] { |
1983fbac | 436 | set archive libstrip.a |
8d263650 | 437 | set objfile [remote_download host tmpdir/testprog.o] |
1983fbac L |
438 | remote_file host delete $archive |
439 | } else { | |
440 | set archive tmpdir/libstrip.a | |
441 | set objfile tmpdir/testprog.o | |
442 | } | |
443 | ||
444 | remote_file build delete tmpdir/libstrip.a | |
445 | ||
446 | set exec_output [binutils_run $AR "rc $archive ${objfile}"] | |
21c40443 | 447 | if ![string equal "" $exec_output] { |
1983fbac | 448 | fail $test |
21c40443 | 449 | unresolved "$test preserving OS/ABI" |
1983fbac L |
450 | return |
451 | } | |
452 | ||
8648f88f | 453 | set exec_output [binutils_run $STRIP "-g $archive"] |
21c40443 | 454 | if ![string equal "" $exec_output] { |
8648f88f | 455 | fail $test |
21c40443 | 456 | unresolved "$test preserving OS/ABI" |
8648f88f L |
457 | return |
458 | } | |
459 | ||
1983fbac | 460 | set exec_output [binutils_run $STRIP "$STRIPFLAGS $archive"] |
21c40443 | 461 | if ![string equal "" $exec_output] { |
1983fbac | 462 | fail $test |
21c40443 | 463 | unresolved "$test preserving OS/ABI" |
1983fbac L |
464 | return |
465 | } | |
466 | ||
28902555 BS |
467 | if { $osabi_fail != "true" && [is_elf_format] } { |
468 | verbose -log "$READELF -a tmpdir/testprog.o > tmpdir/osabi.out" | |
469 | set exec_output [remote_exec host "$READELF -h tmpdir/testprog.o" "" "/dev/null" "tmpdir/osabi.out"] | |
470 | if { [lindex $exec_output 0] != 0 } then { | |
21c40443 | 471 | unresolved "$test preserving OS/ABI" |
28902555 BS |
472 | } else { |
473 | verbose -log "grep OS/ABI tmpdir/osabi.out" | |
474 | catch "exec grep OS/ABI tmpdir/osabi.out" osabi_out | |
475 | if { "$osabi_in" == "$osabi_out" } { | |
476 | pass "$test preserving OS/ABI" | |
477 | } else { | |
478 | fail "$test preserving OS/ABI" | |
479 | } | |
480 | } | |
481 | } | |
482 | ||
1983fbac L |
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] { | |
8d263650 | 489 | set objfile [remote_download host tmpdir/testprog.o] |
252b5132 RH |
490 | } else { |
491 | set objfile tmpdir/testprog.o | |
492 | } | |
493 | ||
494 | set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"] | |
21c40443 | 495 | if ![string equal "" $exec_output] { |
252b5132 RH |
496 | fail $test |
497 | return | |
498 | } | |
499 | ||
500 | set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"] | |
68a4c073 | 501 | if ![string match "*: no symbols*" $exec_output] { |
252b5132 RH |
502 | fail $test |
503 | return | |
504 | } | |
505 | ||
506 | pass $test | |
507 | } | |
508 | ||
509 | strip_test | |
510 | ||
511 | # Test stripping an object file with saving a symbol | |
512 | ||
513 | proc strip_test_with_saving_a_symbol { } { | |
514 | global CC | |
515 | global STRIP | |
516 | global STRIPFLAGS | |
517 | global NM | |
518 | global NMFLAGS | |
519 | global srcdir | |
520 | global subdir | |
521 | ||
522 | set test "strip with saving a symbol" | |
523 | ||
524 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { | |
525 | untested $test | |
526 | return | |
527 | } | |
528 | ||
529 | if [is_remote host] { | |
8d263650 | 530 | set objfile [remote_download host tmpdir/testprog.o] |
252b5132 RH |
531 | } else { |
532 | set objfile tmpdir/testprog.o | |
533 | } | |
534 | ||
535 | set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main -K _main $objfile"] | |
21c40443 | 536 | if ![string equal "" $exec_output] { |
252b5132 RH |
537 | fail $test |
538 | return | |
539 | } | |
540 | ||
541 | set exec_output [binutils_run $NM "$NMFLAGS $objfile"] | |
195fe636 | 542 | if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \ |
252b5132 RH |
543 | && ![regexp {^([0-9a-fA-F]+)?[ ]+T _main} $exec_output]} { |
544 | fail $test | |
545 | return | |
546 | } | |
547 | ||
548 | pass $test | |
549 | } | |
550 | ||
551 | strip_test_with_saving_a_symbol | |
552 | ||
553 | # Build a final executable. | |
554 | ||
99ad8390 | 555 | if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } { |
f8a7038a NC |
556 | set test_prog "testprog.exe" |
557 | } else { | |
558 | set test_prog "testprog" | |
559 | } | |
560 | ||
252b5132 RH |
561 | proc copy_setup { } { |
562 | global srcdir | |
563 | global subdir | |
9a580d9a | 564 | global gcc_gas_flag |
f8a7038a | 565 | global test_prog |
72d4c02f | 566 | global host_triplet |
21c40443 | 567 | |
8d263650 BE |
568 | set res [build_wrapper testglue.o] |
569 | set flags { debug } | |
21c40443 | 570 | |
28902555 | 571 | if { [istarget *-*-uclinux*] && ![istarget tic6x-*-*] } { |
903b1f5b NS |
572 | return 1 |
573 | } | |
21c40443 | 574 | |
252b5132 | 575 | if { $res != "" } { |
8d263650 BE |
576 | lappend flags "additional_flags=[lindex $res 1]" |
577 | set add_libs "testglue.o" | |
252b5132 | 578 | } else { |
8d263650 | 579 | set add_libs "" |
252b5132 RH |
580 | } |
581 | ||
5940a93c TS |
582 | if { [istarget *-*-linux*] |
583 | || [istarget *-*-gnu*] } { | |
9a580d9a L |
584 | foreach i $gcc_gas_flag { |
585 | set flags "additional_flags=$i $flags" | |
586 | } | |
587 | } | |
f8a7038a | 588 | if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/$test_prog executable $flags] != "" } { |
252b5132 RH |
589 | return 2 |
590 | } | |
591 | ||
8d263650 BE |
592 | set result [remote_load target tmpdir/$test_prog] |
593 | set status [lindex $result 0] | |
252b5132 RH |
594 | |
595 | if { $status != "pass" } { | |
72d4c02f | 596 | send_log "cannot run executable, status = ${status} on ${host_triplet}\n" |
21c40443 | 597 | return 3 |
252b5132 RH |
598 | } |
599 | ||
600 | return 0 | |
601 | } | |
602 | ||
603 | # Test copying an executable. | |
604 | ||
605 | proc copy_executable { prog flags test1 test2 } { | |
f8a7038a | 606 | global test_prog |
252b5132 RH |
607 | |
608 | if [is_remote host] { | |
8d263650 | 609 | set testfile [remote_download host tmpdir/$test_prog] |
252b5132 RH |
610 | set testcopy copyprog |
611 | } else { | |
f8a7038a | 612 | set testfile tmpdir/$test_prog |
252b5132 RH |
613 | set testcopy tmpdir/copyprog |
614 | } | |
8d263650 | 615 | remote_file host delete $testcopy |
252b5132 RH |
616 | |
617 | set exec_output [binutils_run $prog "$flags $testfile $testcopy"] | |
618 | ||
21c40443 | 619 | if ![string equal "" $exec_output] { |
252b5132 | 620 | fail $test1 |
21c40443 | 621 | if [string equal "" $test2] { |
0d063f63 AM |
622 | return |
623 | } | |
252b5132 RH |
624 | fail $test2 |
625 | return | |
626 | } | |
627 | ||
628 | if [is_remote host] { | |
629 | remote_upload host $testcopy tmpdir/copyprog | |
630 | } | |
631 | ||
f8a7038a | 632 | set status [remote_exec build "cmp" "tmpdir/$test_prog tmpdir/copyprog"] |
8d263650 | 633 | set exec_output [lindex $status 1] |
252b5132 | 634 | |
21c40443 | 635 | if [string equal "" $exec_output] then { |
252b5132 RH |
636 | pass $test1 |
637 | } else { | |
638 | send_log "$exec_output\n" | |
639 | verbose "$exec_output" | |
640 | ||
641 | # This will fail for many reasons. For example, it will most | |
642 | # likely fail if a non-GNU linker is used. Therefore, we do | |
643 | # not insist that it pass. If you are using an assembler and | |
644 | # linker based on the same BFD as objcopy, it is worth | |
645 | # investigating to see why this failure occurs. If we are | |
646 | # cross compiling, we assume that a GNU linker is being used, | |
647 | # and expect it to succeed. | |
648 | if {[isnative]} then { | |
649 | setup_xfail "*-*-*" | |
650 | } | |
651 | ||
9cc0123f | 652 | # This also fails for some mips targets. See elf32-mips.c |
252b5132 | 653 | # mips_elf_sym_is_global. |
9cc0123f AM |
654 | if { [is_bad_symtab] } then { |
655 | setup_xfail "*-*-*" | |
656 | } | |
252b5132 | 657 | |
8c5fc800 | 658 | setup_xfail "arm*-*-coff" |
11d47adc | 659 | setup_xfail "arm*-*-pe" |
88f14853 | 660 | setup_xfail "*-*-mingw*" |
899396fe | 661 | setup_xfail "*-*-cygwin*" |
21c40443 | 662 | |
252b5132 RH |
663 | fail $test1 |
664 | } | |
665 | ||
21c40443 | 666 | if [string equal "" $test2] { |
0d063f63 AM |
667 | return |
668 | } | |
669 | ||
252b5132 | 670 | set output [remote_load target tmpdir/copyprog] |
8d263650 | 671 | set status [lindex $output 0] |
252b5132 RH |
672 | if { $status != "pass" } { |
673 | fail $test2 | |
674 | } else { | |
675 | pass $test2 | |
676 | } | |
677 | } | |
678 | ||
679 | # Test stripping an executable | |
680 | ||
21c40443 | 681 | proc strip_executable { prog flags test1 test2 } { |
252b5132 RH |
682 | global NM |
683 | global NMFLAGS | |
28902555 | 684 | global READELF |
252b5132 | 685 | |
0fcc17f8 | 686 | remote_file build delete tmpdir/striprog |
252b5132 RH |
687 | remote_download build tmpdir/copyprog tmpdir/striprog |
688 | if [is_remote host] { | |
8d263650 | 689 | set copyfile [remote_download host tmpdir/striprog] |
252b5132 RH |
690 | } else { |
691 | set copyfile tmpdir/striprog | |
692 | } | |
693 | ||
28902555 BS |
694 | set osabi_fail "false" |
695 | if [is_elf_format] { | |
696 | verbose -log "$READELF -a ${copyfile} > tmpdir/osabi.in" | |
697 | set exec_output [remote_exec host "$READELF -h ${copyfile}" "" "/dev/null" "tmpdir/osabi.in"] | |
698 | if { [lindex $exec_output 0] != 0 } then { | |
21c40443 | 699 | unresolved "$test1 preserving OS/ABI" |
28902555 BS |
700 | set osabi_fail "true" |
701 | } else { | |
702 | verbose -log "grep OS/ABI tmpdir/osabi.in" | |
703 | catch "exec grep OS/ABI tmpdir/osabi.in" osabi_in | |
704 | } | |
705 | } | |
706 | ||
252b5132 | 707 | set exec_output [binutils_run $prog "$flags ${copyfile}"] |
21c40443 AM |
708 | if ![string equal "" $exec_output] { |
709 | fail $test1 | |
710 | if [string equal "" $test2] { | |
711 | return | |
712 | } | |
713 | fail $test2 | |
252b5132 RH |
714 | return |
715 | } | |
716 | ||
717 | if [is_remote host] { | |
8d263650 | 718 | remote_upload host ${copyfile} tmpdir/striprog |
252b5132 RH |
719 | } |
720 | ||
28902555 BS |
721 | if { $osabi_fail != "true" && [is_elf_format] } { |
722 | verbose -log "$READELF -a ${copyfile} > tmpdir/osabi.out" | |
723 | set exec_output [remote_exec host "$READELF -h ${copyfile}" "" "/dev/null" "tmpdir/osabi.out"] | |
724 | if { [lindex $exec_output 0] != 0 } then { | |
21c40443 | 725 | unresolved "$test1 preserving OS/ABI" |
28902555 BS |
726 | } else { |
727 | verbose -log "grep OS/ABI tmpdir/osabi.out" | |
728 | catch "exec grep OS/ABI tmpdir/osabi.out" osabi_out | |
729 | if { "$osabi_in" == "$osabi_out" } { | |
21c40443 | 730 | pass "$test1 preserving OS/ABI" |
28902555 | 731 | } else { |
21c40443 | 732 | fail "$test1 preserving OS/ABI" |
28902555 BS |
733 | } |
734 | } | |
735 | } | |
736 | ||
252b5132 | 737 | set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] |
68a4c073 | 738 | if ![string match "*: no symbols*" $exec_output] { |
21c40443 | 739 | fail $test1 |
252b5132 RH |
740 | return |
741 | } | |
21c40443 AM |
742 | |
743 | if [string equal "" $test2] { | |
744 | return | |
745 | } | |
746 | ||
747 | set result [remote_load target tmpdir/striprog] | |
748 | set status [lindex $result 0] | |
749 | if { $status != "pass" } { | |
750 | fail $test2 | |
751 | return | |
752 | } | |
753 | ||
754 | pass $test2 | |
252b5132 RH |
755 | } |
756 | ||
757 | # Test stripping an executable with saving a symbol | |
758 | ||
21c40443 | 759 | proc strip_executable_with_saving_a_symbol { prog flags test1 test2 } { |
252b5132 RH |
760 | global NM |
761 | global NMFLAGS | |
762 | ||
0fcc17f8 | 763 | remote_file build delete tmpdir/striprog |
252b5132 RH |
764 | remote_download build tmpdir/copyprog tmpdir/striprog |
765 | if [is_remote host] { | |
8d263650 | 766 | set copyfile [remote_download host tmpdir/striprog] |
252b5132 RH |
767 | } else { |
768 | set copyfile tmpdir/striprog | |
769 | } | |
770 | ||
771 | set exec_output [binutils_run $prog "$flags ${copyfile}"] | |
21c40443 AM |
772 | if ![string equal "" $exec_output] { |
773 | fail $test1 | |
774 | if [string equal "" $test2] { | |
775 | return | |
776 | } | |
777 | fail $test2 | |
252b5132 RH |
778 | return |
779 | } | |
780 | ||
252b5132 | 781 | set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] |
edc45ab9 HPN |
782 | if { [istarget mmix-knuth-mmixware] } { |
783 | # Whenever there's a symbol in the mmo format, there's the symbol | |
784 | # Main, so remove it manually from the expected output for sake of | |
785 | # this test. | |
786 | ||
787 | # Using "" not {} to get the \n and \r translated. | |
788 | regsub "^\[0-9a-fA-F\]+\[ \]+T Main\[\n\r\]+" $exec_output "" exec_output | |
789 | } | |
790 | ||
adacfc81 JJ |
791 | if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \ |
792 | && ![regexp {^([0-9a-fA-F]+)?[ ]+[TD] _main} $exec_output]} { | |
21c40443 | 793 | fail $test1 |
252b5132 RH |
794 | return |
795 | } | |
21c40443 AM |
796 | |
797 | if [string equal "" $test2] { | |
798 | return | |
799 | } | |
800 | ||
801 | if [is_remote host] { | |
802 | remote_upload host ${copyfile} tmpdir/striprog | |
803 | } | |
804 | ||
805 | set result [remote_load target tmpdir/striprog] | |
806 | set status [lindex $result 0] | |
807 | if { $status != "pass" } { | |
808 | fail $test2 | |
809 | return | |
810 | } | |
811 | ||
812 | pass $test2 | |
252b5132 RH |
813 | } |
814 | ||
11701589 JK |
815 | # Test keeping only debug symbols of an executable |
816 | ||
817 | proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } { | |
0fcc17f8 | 818 | remote_file build delete tmpdir/striprog |
11701589 JK |
819 | remote_download build tmpdir/copyprog tmpdir/striprog |
820 | if [is_remote host] { | |
821 | set copyfile [remote_download host tmpdir/striprog] | |
822 | } else { | |
823 | set copyfile tmpdir/striprog | |
824 | } | |
825 | ||
826 | set exec_output [binutils_run $prog1 "$flags1 ${copyfile}"] | |
21c40443 | 827 | if ![string equal "" $exec_output] { |
11701589 JK |
828 | fail $test1 |
829 | return | |
830 | } | |
831 | pass $test1 | |
832 | ||
833 | set exec_output [binutils_run $prog2 "$flags2 ${copyfile}"] | |
21c40443 | 834 | if ![string equal "" $exec_output] { |
11701589 JK |
835 | fail $test2 |
836 | return | |
837 | } | |
838 | pass $test2 | |
839 | } | |
840 | ||
63b9bbb7 | 841 | # Tests that in a debug only copy of a file the sections |
de194d85 | 842 | # headers whose types have been changed to NOBITS still |
63b9bbb7 NC |
843 | # retain their sh_link fields. |
844 | ||
845 | proc keep_debug_symbols_and_check_links { prog flags test } { | |
846 | global READELF | |
847 | ||
848 | remote_file build delete tmpdir/striprog | |
849 | remote_download build tmpdir/copyprog tmpdir/striprog | |
850 | if [is_remote host] { | |
851 | set copyfile [remote_download host tmpdir/striprog] | |
852 | } else { | |
853 | set copyfile tmpdir/striprog | |
854 | } | |
855 | ||
856 | set exec_output [binutils_run $prog "$flags ${copyfile}"] | |
21c40443 | 857 | if ![string equal "" $exec_output] { |
63b9bbb7 NC |
858 | fail $test |
859 | return | |
860 | } | |
861 | ||
862 | set got [binutils_run $READELF "-S --wide ${copyfile}"] | |
863 | ||
864 | set fails 0 | |
865 | # Regexp to match a section with NOBITS type and extract its name and sh_link fields | |
866 | while {[regexp \ | |
867 | {[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ ]+NOBITS[ ]+[0-9a-fA-F]+ [0-9a-fA-F]+ [0-9a-fA-F]+ [0-9]+[ A]+([0-9]+)(.*)} \ | |
868 | $got all name link rest]} { | |
869 | set sh_link 0x$link | |
870 | if {$sh_link == 0} { | |
871 | # Only some NOBITS sections should have a non-zero sh_link field. | |
872 | # Look for them by name. | |
873 | verbose "NOBITS section .$name has a 0 sh_link field\n" | |
874 | switch $name { | |
875 | "rela.*" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
876 | "rel.*" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
877 | "hash" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
878 | "gnu_version" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
879 | "dynsym" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
880 | "gnu.version_r" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
881 | "dynamic" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
882 | "symtab" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } | |
883 | } | |
884 | } | |
885 | set got $rest | |
886 | } | |
887 | ||
888 | if {$fails == 0} { | |
889 | pass $test | |
890 | } else { | |
891 | fail $test | |
892 | } | |
893 | } | |
894 | ||
895 | ||
252b5132 | 896 | set test1 "simple objcopy of executable" |
21c40443 AM |
897 | set test1r "run objcopy of executable" |
898 | set test2 "strip executable" | |
899 | set test2r "run stripped executable" | |
900 | set test3 "strip executable with saving a symbol" | |
901 | set test3r "run stripped executable with saving a symbol" | |
902 | set test4 "keep only debug data" | |
903 | set test5 "simple objcopy of debug data" | |
63b9bbb7 | 904 | if [is_elf_format] { |
21c40443 | 905 | set test6 "NOBITS sections retain sh_link field" |
63b9bbb7 | 906 | } |
252b5132 RH |
907 | |
908 | switch [copy_setup] { | |
909 | "1" { | |
910 | # do nothing | |
911 | } | |
912 | "2" { | |
913 | untested $test1 | |
21c40443 | 914 | untested $test1r |
252b5132 | 915 | untested $test2 |
21c40443 | 916 | untested $test2r |
252b5132 | 917 | untested $test3 |
21c40443 | 918 | untested $test3r |
252b5132 | 919 | untested $test4 |
11701589 | 920 | untested $test5 |
63b9bbb7 | 921 | if [is_elf_format] { |
21c40443 | 922 | untested $test6 |
63b9bbb7 | 923 | } |
252b5132 RH |
924 | } |
925 | "3" { | |
0d063f63 | 926 | copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "" |
21c40443 AM |
927 | unsupported $test1r |
928 | strip_executable "$STRIP" "$STRIPFLAGS" "$test2" "" | |
929 | unsupported $test2r | |
930 | strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test3" "" | |
931 | unsupported $test3r | |
932 | keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test4" \ | |
933 | "$OBJCOPY" "$OBJCOPYFLAGS" "$test5" | |
63b9bbb7 | 934 | if [is_elf_format] { |
21c40443 | 935 | keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6" |
63b9bbb7 | 936 | } |
252b5132 RH |
937 | } |
938 | "0" { | |
21c40443 AM |
939 | copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test1r" |
940 | strip_executable "$STRIP" "$STRIPFLAGS" "$test2" "$test2r" | |
941 | strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test3" "$test3r" | |
942 | keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test4" \ | |
943 | "$OBJCOPY" "$OBJCOPYFLAGS" "$test5" | |
63b9bbb7 | 944 | if [is_elf_format] { |
21c40443 | 945 | keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6" |
63b9bbb7 | 946 | } |
252b5132 RH |
947 | } |
948 | } | |
ad2fb2cd | 949 | |
6a0d0afd L |
950 | proc objcopy_test_readelf {testname srcfile} { |
951 | global OBJCOPY | |
952 | global OBJCOPYFLAGS | |
953 | global READELF | |
954 | global srcdir | |
955 | global subdir | |
956 | ||
957 | if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then { | |
958 | unresolved "objcopy ($testname)" | |
959 | return | |
960 | } | |
961 | ||
962 | verbose -log "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o" | |
7f6a71ff JM |
963 | set exec_output [remote_exec host "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"] |
964 | if { [lindex $exec_output 0] != 0 | |
21c40443 | 965 | || ![string equal "" [lindex $exec_output 1]] } then { |
6a0d0afd | 966 | fail "objcopy ($testname)" |
004314cc | 967 | return |
6a0d0afd L |
968 | } |
969 | ||
970 | verbose -log "$READELF -a tmpdir/bintest.o > tmpdir/bintest.o.out" | |
7f6a71ff JM |
971 | set exec_output [remote_exec host "$READELF -a tmpdir/bintest.o" "" "/dev/null" "tmpdir/bintest.o.out"] |
972 | if { [lindex $exec_output 0] != 0 } then { | |
973 | unresolved "objcopy ($testname)" | |
974 | return | |
975 | } | |
976 | set exec_output [prune_warnings [lindex $exec_output 1]] | |
21c40443 | 977 | if ![string equal "" $exec_output] then { |
6a0d0afd L |
978 | unresolved "objcopy ($testname)" |
979 | return | |
980 | } | |
981 | ||
982 | verbose -log "$READELF -a tmpdir/copy.o > tmpdir/copy.o.out" | |
7f6a71ff JM |
983 | set exec_output [remote_exec host "$READELF -a tmpdir/copy.o" "" "/dev/null" "tmpdir/copy.o.out"] |
984 | if { [lindex $exec_output 0] != 0 } then { | |
985 | unresolved "objcopy ($testname)" | |
986 | return | |
987 | } | |
988 | set exec_output [prune_warnings [lindex $exec_output 1]] | |
21c40443 | 989 | if ![string equal "" $exec_output] then { |
6a0d0afd L |
990 | unresolved "objcopy ($testname)" |
991 | return | |
992 | } | |
993 | ||
994 | verbose -log "diff tmpdir/bintest.o.out tmpdir/copy.o.out" | |
995 | catch "exec diff tmpdir/bintest.o.out tmpdir/copy.o.out" exec_output | |
996 | set exec_output [prune_warnings $exec_output] | |
997 | ||
21c40443 | 998 | if [string equal "" $exec_output] then { |
6a0d0afd L |
999 | pass "objcopy ($testname)" |
1000 | } else { | |
1001 | fail "objcopy ($testname)" | |
1002 | } | |
1003 | } | |
1004 | ||
0b45135e AB |
1005 | proc objcopy_test_symbol_manipulation {} { |
1006 | global srcdir | |
1007 | global subdir | |
1008 | ||
1009 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/symbols-*.d]] | |
1010 | foreach t $test_list { | |
1011 | # We need to strip the ".d", but can leave the dirname. | |
1012 | verbose [file rootname $t] | |
1013 | run_dump_test [file rootname $t] | |
1014 | } | |
1015 | } | |
1016 | ||
b8871f35 L |
1017 | proc objcopy_test_elf_common_symbols {} { |
1018 | global srcdir | |
1019 | global subdir | |
1020 | ||
1021 | # hpux has a non-standard common directive. | |
1022 | if { [istarget "*-*-hpux*"] } then { | |
1023 | return | |
1024 | } | |
1025 | ||
1026 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/common-*.d]] | |
1027 | foreach t $test_list { | |
1028 | # We need to strip the ".d", but can leave the dirname. | |
1029 | verbose [file rootname $t] | |
1030 | run_dump_test [file rootname $t] | |
1031 | } | |
1032 | } | |
1033 | ||
ad2fb2cd L |
1034 | # ia64 specific tests |
1035 | if { ([istarget "ia64-*-elf*"] | |
1036 | || [istarget "ia64-*-linux*"]) } { | |
64bb95af L |
1037 | objcopy_test "ia64 link order" link-order.s |
1038 | } | |
ad2fb2cd | 1039 | |
64bb95af L |
1040 | # ELF specific tests |
1041 | if [is_elf_format] { | |
0b45135e | 1042 | objcopy_test_symbol_manipulation |
b8871f35 | 1043 | objcopy_test_elf_common_symbols |
64bb95af | 1044 | objcopy_test "ELF unknown section type" unknown.s |
6a0d0afd | 1045 | objcopy_test_readelf "ELF group" group.s |
eb3980ce | 1046 | objcopy_test_readelf "ELF group" group-2.s |
f206e905 | 1047 | objcopy_test_readelf "ELF group" group-3.s |
e1e87d1e | 1048 | objcopy_test_readelf "ELF group" group-4.s |
a91e1603 | 1049 | objcopy_test_readelf "GNU_MBIND section" mbind1.s |
b2fc24d4 | 1050 | run_dump_test "group-5" |
4c8e8a7e | 1051 | run_dump_test "group-6" |
6e5e9d58 AM |
1052 | run_dump_test "group-7a" |
1053 | run_dump_test "group-7b" | |
1054 | run_dump_test "group-7c" | |
85d7f0b9 | 1055 | run_dump_test "copy-1" |
0930eddd | 1056 | run_dump_test "note-1" |
9ef920e9 NC |
1057 | if [is_elf64 tmpdir/bintest.o] { |
1058 | run_dump_test "note-2-64" | |
714da62f | 1059 | run_dump_test "note-3-64" |
6f156d7a | 1060 | run_dump_test "note-4-64" |
9ef920e9 NC |
1061 | } else { |
1062 | run_dump_test "note-2-32" | |
714da62f | 1063 | run_dump_test "note-3-32" |
6f156d7a | 1064 | run_dump_test "note-4-32" |
9ef920e9 | 1065 | } |
ad2fb2cd | 1066 | } |
af3c5dea | 1067 | |
af3c5dea | 1068 | run_dump_test "copy-2" |
81fc501a | 1069 | run_dump_test "copy-3" |
0691f7af | 1070 | run_dump_test "copy-4" |
cbd44e24 L |
1071 | run_dump_test "pr19020a" |
1072 | run_dump_test "pr19020b" | |
d58c2e3a RS |
1073 | |
1074 | if [is_elf_format] { | |
748fc5e9 L |
1075 | run_dump_test "strip-1" |
1076 | run_dump_test "strip-2" | |
1aa9ef63 | 1077 | run_dump_test "strip-3" |
eb3980ce L |
1078 | run_dump_test "strip-4" |
1079 | run_dump_test "strip-5" | |
f206e905 L |
1080 | run_dump_test "strip-6" |
1081 | run_dump_test "strip-7" | |
e1e87d1e L |
1082 | run_dump_test "strip-8" |
1083 | run_dump_test "strip-9" | |
d4ac1f87 | 1084 | run_dump_test "strip-12" |
2f8ceb38 MR |
1085 | |
1086 | if { [istarget "mips64*-*-openbsd*"] } { | |
1087 | set reloc_format mips64 | |
1088 | } elseif { [istarget "arm-*"] \ | |
1089 | || [istarget "d10v-*"] \ | |
1090 | || [istarget "dlx-*"] \ | |
1091 | || [istarget "i*86-*"] \ | |
2f8ceb38 MR |
1092 | || [istarget "m681*-*"] \ |
1093 | || [istarget "m68hc1*-*"] \ | |
1094 | || ([istarget "mips*-*"] \ | |
1095 | && ![istarget "mips64*-ps2-elf*"] \ | |
1096 | && ![istarget "*-*-irix6*"] \ | |
1097 | && ![istarget "mips64*-*-freebsd*"] \ | |
1098 | && ![istarget "mips64*-*-kfreebsd*-gnu"] \ | |
1099 | && ![istarget "mips64*-*-linux*"]) \ | |
1100 | || [istarget "score*-*"] \ | |
1101 | || [istarget "xgate-*"] } { | |
1102 | set reloc_format rel | |
1103 | } else { | |
1104 | set reloc_format rela | |
1105 | } | |
1106 | run_dump_test "strip-13" [list [list source strip-13${reloc_format}.s]] | |
3f97ba9f MR |
1107 | # Select a relocation number that corresponds to one actually |
1108 | # supported by the target and ABI being tested. | |
1109 | if { [istarget "aarch64*-*"] } { | |
1110 | set reloc 259 | |
1111 | } elseif { [istarget "ia64*-*"] \ | |
1112 | || [istarget "m32r*-*"] \ | |
d4ae1932 | 1113 | || [istarget "nds32*-*"] \ |
3f97ba9f MR |
1114 | || [istarget "v850*-*"] } { |
1115 | set reloc 50 | |
d4ae1932 AM |
1116 | } elseif { [istarget "pru-*"] } { |
1117 | set reloc 11 | |
3f97ba9f MR |
1118 | } else { |
1119 | set reloc 1 | |
1120 | } | |
1121 | run_dump_test "strip-14" [list \ | |
1122 | [list source strip-14${reloc_format}.s] \ | |
1123 | [list as "--defsym RELOC=${reloc}"] \ | |
1124 | [list as [expr {[is_elf64 tmpdir/bintest.o] \ | |
1125 | ? "--defsym ELF64=1" : ""}]]] | |
d52e3d06 MR |
1126 | run_dump_test "strip-15" [list \ |
1127 | [list source strip-15${reloc_format}.s] \ | |
1128 | [list as "--defsym RELOC=${reloc}"] \ | |
1129 | [list as [expr {[is_elf64 tmpdir/bintest.o] \ | |
1130 | ? "--defsym ELF64=1" : ""}]]] | |
f3185997 | 1131 | |
a43942db MR |
1132 | # This requires STB_GNU_UNIQUE support with OSABI set to GNU. |
1133 | if { [supports_gnu_unique] } { | |
4cd28456 AM |
1134 | run_dump_test "strip-10" |
1135 | } | |
0abb10c8 AM |
1136 | set extra_strip11 "" |
1137 | if { [istarget "sh64*-*"] } { | |
1138 | # pr17755 testcase | |
1139 | set extra_strip11 { { "as" "--isa=SHmedia --abi=64" } } | |
1140 | } | |
1141 | run_dump_test "strip-11" $extra_strip11 | |
312aaa3c | 1142 | |
b8b6abe0 AM |
1143 | if { [istarget "i*86-*"] || [istarget "x86_64-*-*"] } { |
1144 | # Check to make sure we don't strip a symbol named in relocations. | |
1145 | set test "objcopy keeps symbols needed by relocs" | |
312aaa3c | 1146 | |
b8b6abe0 | 1147 | set srcfile $srcdir/$subdir/needed-by-reloc.s |
312aaa3c | 1148 | |
b8b6abe0 AM |
1149 | if {![binutils_assemble $srcfile tmpdir/bintest.o]} then { |
1150 | unresolved $test | |
1151 | } else { | |
1152 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS --strip-symbol=foo tmpdir/bintest.o ${copyfile}.o"] | |
312aaa3c | 1153 | |
b8b6abe0 AM |
1154 | if [regexp "not stripping symbol `foo' because it is named in a relocation" $got] { |
1155 | pass $test | |
1156 | } else { | |
1157 | fail $test | |
1158 | } | |
1159 | } | |
312aaa3c | 1160 | } |
b8b6abe0 | 1161 | |
8560e02a HPN |
1162 | # The symbol table for some MIPS targets is sorted differently than |
1163 | # the ELF canonical order, so the regexps in localize-hidden-1.d fail | |
9cc0123f AM |
1164 | # to match. |
1165 | if { [is_bad_symtab] } then { | |
1166 | setup_xfail "*-*-*" | |
8560e02a | 1167 | } |
b8b6abe0 | 1168 | run_dump_test "localize-hidden-1" |
afeb3d7f L |
1169 | run_dump_test "testranges" |
1170 | run_dump_test "testranges-ia64" | |
500ee42e ILT |
1171 | |
1172 | run_dump_test "add-section" | |
2b35fb28 | 1173 | run_dump_test "add-symbol" |
500ee42e | 1174 | run_dump_test "add-empty-section" |
18ae9cc1 L |
1175 | |
1176 | run_dump_test "exclude-1a" | |
1177 | run_dump_test "exclude-1b" | |
e511c9b1 AB |
1178 | |
1179 | run_dump_test "only-section-01" | |
1180 | run_dump_test "remove-section-01" | |
d3e5f6c8 AB |
1181 | |
1182 | # Test the remove relocation functionality | |
1183 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/remove-relocs-*.d]] | |
1184 | foreach t $test_list { | |
1185 | # We need to strip the ".d", but can leave the dirname. | |
1186 | verbose [file rootname $t] | |
1187 | run_dump_test [file rootname $t] | |
1188 | } | |
312aaa3c | 1189 | } |
b8b6abe0 | 1190 | run_dump_test "localize-hidden-2" |
14f2c699 L |
1191 | |
1192 | # Test objcopying an object file without global symbol | |
1193 | ||
1194 | proc objcopy_test_without_global_symbol { } { | |
1195 | global OBJCOPY | |
1196 | global OBJCOPYFLAGS | |
1197 | global OBJDUMP | |
1198 | global OBJDUMPFLAGS | |
1199 | global srcdir | |
1200 | global subdir | |
1201 | ||
1202 | set test "strip without global symbol " | |
1203 | ||
1204 | if { [target_compile $srcdir/$subdir/pr19547.c tmpdir/pr19547.o object debug] != "" } { | |
1205 | untested $test | |
1206 | return | |
1207 | } | |
1208 | ||
1209 | if [is_remote host] { | |
1210 | set objfile [remote_download host tmpdir/pr19547.o] | |
1211 | } else { | |
1212 | set objfile tmpdir/pr19547.o | |
1213 | } | |
1214 | ||
1215 | set exec_output [binutils_run $OBJCOPY "$OBJCOPYFLAGS --strip-unneeded $objfile"] | |
1216 | if ![string equal "" $exec_output] { | |
1217 | fail $test | |
1218 | return | |
1219 | } | |
1220 | ||
1221 | set exec_output [binutils_run $OBJDUMP "$OBJDUMPFLAGS -t $objfile"] | |
1222 | if {![regexp "no symbols" $exec_output]} { | |
1223 | fail $test | |
1224 | return | |
1225 | } | |
1226 | ||
1227 | pass $test | |
1228 | } | |
1229 | ||
41699fa4 NC |
1230 | # The AArch64 and ARM targets preserve mapping symbols |
1231 | # in object files, so they will fail this test. | |
1232 | setup_xfail aarch64*-*-* arm*-*-* | |
1233 | ||
14f2c699 | 1234 | objcopy_test_without_global_symbol |