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