Commit | Line | Data |
---|---|---|
862a5313 | 1 | # Copyright (C) 1994, 95, 96, 97, 1998 Free Software Foundation, Inc. |
09250cfe ILT |
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 | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
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. | |
12 | # | |
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 | |
6a4549e7 | 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
09250cfe ILT |
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 | ||
862a5313 VM |
22 | if ![is_remote host] { |
23 | if {[which $OBJCOPY] == 0} then { | |
24 | perror "$OBJCOPY does not exist" | |
25 | return | |
26 | } | |
09250cfe ILT |
27 | } |
28 | ||
29 | send_user "Version [binutil_version $OBJCOPY]" | |
30 | ||
862a5313 VM |
31 | if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then { |
32 | perror "unresolved 1" | |
febc1fc3 | 33 | unresolved "objcopy (simple copy)" |
09250cfe ILT |
34 | return |
35 | } | |
36 | ||
862a5313 VM |
37 | if ![is_remote host] { |
38 | set tempfile tmpdir/bintest.o; | |
39 | set copyfile tmpdir/copy; | |
40 | } else { | |
41 | set tempfile [remote_download host tmpdir/bintest.o] | |
42 | set copyfile copy | |
43 | } | |
44 | ||
09250cfe ILT |
45 | # Test that objcopy does not modify a file when copying it. |
46 | ||
862a5313 | 47 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS $tempfile ${copyfile}.o"] |
09250cfe ILT |
48 | |
49 | if ![string match "" $got] then { | |
50 | fail "objcopy (simple copy)" | |
51 | } else { | |
862a5313 VM |
52 | send_log "cmp $tempfile ${copyfile}.o\n" |
53 | verbose "cmp $tempfile ${copyfile}.o" | |
54 | if [is_remote host] { | |
55 | set src1 tmpdir/bintest.o | |
56 | set src2 tmpdir/copy.o | |
57 | remote_upload host $tempfile $src1; | |
58 | remote_upload host ${copyfile}.o $src2; | |
59 | } else { | |
60 | set src1 ${tempfile} | |
61 | set src2 ${copyfile}.o | |
62 | } | |
63 | set status [remote_exec build cmp "${src1} ${src2}"]; | |
64 | set exec_output [lindex $status 1]; | |
65 | set exec_output [prune_warnings $exec_output] | |
09250cfe ILT |
66 | |
67 | # On some systems the result of objcopy will not be identical. | |
8b550686 ILT |
68 | # Usually this is just because gas isn't using bfd to write the files |
69 | # in the first place, and may order things a little differently. | |
09250cfe ILT |
70 | # Those systems should use setup_xfail here. |
71 | ||
6f2d3212 | 72 | setup_xfail "sh-*-coff" "sh-*-hms" |
8b550686 | 73 | setup_xfail "m68*-*-hpux*" "m68*-*-sunos*" "m68*-*-coff" "m68*-*-vxworks*" |
febc1fc3 | 74 | setup_xfail "m68*-ericsson-ose" "m68k*-motorola-sysv*" |
faa53df9 | 75 | setup_xfail "i*86-*-linuxaout*" "i*86-*-aout*" |
854efa68 | 76 | setup_xfail "i*86-*-sysv3" "i*86-*-isc*" "i*86-*-sco*" "i*86-*-coff" |
e75c301b | 77 | setup_xfail "i*86-*-aix*" "i*86-*-go32*" |
28796982 | 78 | setup_xfail "a29k-*-udi" "a29k-*-coff" "a29k-*-vxworks*" |
787f6220 | 79 | setup_xfail "i960-*-coff" |
8b550686 | 80 | setup_xfail "h8300-*-hms" "h8300-*-coff" |
6f2d3212 | 81 | setup_xfail "h8500-*-hms" "h8500-*-coff" |
8b550686 | 82 | setup_xfail "hppa*-*-*" |
6f2d3212 | 83 | clear_xfail "hppa*-*-*elf*" |
febc1fc3 | 84 | setup_xfail "m88*-*-coff" "m88*-motorola-sysv*" |
28796982 | 85 | setup_xfail "z8*-*-coff" |
6273f92d | 86 | |
09250cfe ILT |
87 | if [string match "" $exec_output] then { |
88 | pass "objcopy (simple copy)" | |
89 | } else { | |
90 | send_log "$exec_output\n" | |
91 | verbose "$exec_output" 1 | |
92 | ||
787f6220 BM |
93 | # On OSF/1, this succeeds with gas and fails with /bin/as. |
94 | setup_xfail "alpha*-*-osf*" | |
95 | ||
96 | # This fails for COFF i960-vxworks targets. | |
97 | setup_xfail "i960-*-vxworks*" | |
98 | ||
09250cfe ILT |
99 | fail "objcopy (simple copy)" |
100 | } | |
101 | } | |
102 | ||
103 | # Test generating S records. | |
104 | ||
862a5313 VM |
105 | # We make the srec filename 8.3 compatible. Note that the header string |
106 | # matched against depends on the name of the file. Ugh. | |
107 | ||
108 | if [is_remote host] { | |
109 | set srecfile copy.sre | |
110 | set header_string S00B0000636F70792E737265C1 | |
111 | } else { | |
112 | set srecfile ${copyfile}.srec | |
113 | set header_string S0130000746D706469722F636F70792E7372656397 | |
114 | } | |
115 | ||
116 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"] | |
09250cfe ILT |
117 | |
118 | if ![string match "" $got] then { | |
119 | fail "objcopy -O srec" | |
120 | } else { | |
862a5313 VM |
121 | if [is_remote host] { |
122 | remote_upload host ${srecfile} tmpdir/copy.srec; | |
123 | set srecfile tmpdir/copy.srec; | |
124 | } | |
125 | set file [open ${srecfile} r] | |
09250cfe ILT |
126 | |
127 | # The first S record is fixed by the file name we are using. | |
128 | gets $file line | |
129 | send_log "$line\n" | |
130 | verbose $line | |
862a5313 | 131 | if ![regexp "$header_string.*" $line] { |
854efa68 ILT |
132 | send_log "bad header\n" |
133 | fail "objcopy -O srec" | |
09250cfe ILT |
134 | } else { |
135 | while {[gets $file line] != -1 \ | |
787f6220 | 136 | && [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} { |
09250cfe ILT |
137 | send_log "$line\n" |
138 | verbose $line | |
139 | set line "**EOF**" | |
140 | } | |
141 | send_log "$line\n" | |
142 | verbose $line | |
787f6220 | 143 | if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then { |
854efa68 ILT |
144 | send_log "bad trailer\n" |
145 | fail "objcopy -O srec" | |
09250cfe ILT |
146 | } else { |
147 | if {[gets $file line] != -1} then { | |
854efa68 | 148 | send_log "garbage at end\n" |
09250cfe ILT |
149 | send_log "$line\n" |
150 | verbose $line | |
854efa68 | 151 | fail "objcopy -O srec" |
09250cfe | 152 | } else { |
862a5313 | 153 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] |
09250cfe | 154 | if ![regexp "file format srec" $got] then { |
854efa68 ILT |
155 | send_log "objdump failed\n" |
156 | fail "objcopy -O srec" | |
09250cfe ILT |
157 | } else { |
158 | pass "objcopy -O srec" | |
159 | } | |
160 | } | |
161 | } | |
162 | } | |
163 | ||
164 | close $file | |
165 | } | |
166 | ||
167 | # Test setting and adjusting the start address. We only test this | |
168 | # while generating S records, because we may not be able to set the | |
169 | # start address for other object file formats, and the S record case | |
170 | # is the only useful one anyhow. | |
171 | ||
862a5313 | 172 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $tempfile"] |
09250cfe ILT |
173 | if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then { |
174 | perror "objdump can not recognize bintest.o" | |
175 | set origstart "" | |
176 | } else { | |
862a5313 | 177 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec --set-start 0x7654"] |
09250cfe ILT |
178 | if ![string match "" $got] then { |
179 | fail "objcopy --set-start" | |
180 | } else { | |
862a5313 | 181 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] |
09250cfe ILT |
182 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { |
183 | fail "objcopy --set-start" | |
184 | } else { | |
185 | if {$srecstart != 0x7654} then { | |
854efa68 ILT |
186 | send_log "$srecstart != 0x7654\n" |
187 | fail "objcopy --set-start" | |
09250cfe ILT |
188 | } else { |
189 | pass "objcopy --set-start" | |
190 | } | |
191 | } | |
192 | } | |
193 | ||
862a5313 | 194 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec --adjust-start 0x123"] |
09250cfe ILT |
195 | if ![string match "" $got] then { |
196 | fail "objcopy --adjust-start" | |
197 | } else { | |
862a5313 | 198 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] |
09250cfe ILT |
199 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { |
200 | fail "objcopy --adjust-start" | |
201 | } else { | |
202 | if {$srecstart != $origstart + 0x123} then { | |
854efa68 ILT |
203 | send_log "$srecstart != $origstart + 0x123\n" |
204 | fail "objcopy --adjust-start" | |
09250cfe ILT |
205 | } else { |
206 | pass "objcopy --adjust-start" | |
207 | } | |
208 | } | |
209 | } | |
210 | } | |
211 | ||
212 | # Test adjusting the overall VMA, and adjusting the VMA of a | |
854efa68 | 213 | # particular section. We again only test this when generating S |
09250cfe ILT |
214 | # records. |
215 | ||
216 | set low "" | |
217 | set lowname "" | |
218 | ||
862a5313 | 219 | set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $tempfile"] |
09250cfe | 220 | |
787f6220 | 221 | set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)" |
09250cfe ILT |
222 | |
223 | set got $headers | |
224 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
225 | set vma 0x$vma | |
854efa68 ILT |
226 | set size 0x$size |
227 | if {$size != 0} { | |
228 | if {$low == "" || $vma < $low} { | |
229 | set low $vma | |
230 | set lowname $name | |
231 | } | |
09250cfe ILT |
232 | } |
233 | set got $rest | |
234 | } | |
235 | ||
236 | if {$low == "" || $origstart == ""} then { | |
237 | perror "objdump can not recognize bintest.o" | |
238 | } else { | |
862a5313 | 239 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec --adjust-vma 0x123"] |
09250cfe ILT |
240 | if ![string match "" $got] then { |
241 | fail "objcopy --adjust-vma" | |
242 | } else { | |
862a5313 | 243 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"] |
787f6220 | 244 | set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" |
09250cfe ILT |
245 | if ![regexp $want $got all start vma] then { |
246 | fail "objcopy --adjust-vma" | |
247 | } else { | |
248 | set vma 0x$vma | |
249 | if {$vma != $low + 0x123} then { | |
854efa68 ILT |
250 | send_log "$vma != $low + 0x123\n" |
251 | fail "objcopy --adjust-vma" | |
09250cfe ILT |
252 | } else { |
253 | if {$start != $origstart + 0x123} then { | |
854efa68 ILT |
254 | send_log "$start != $origstart + 0x123\n" |
255 | fail "objcopy --adjust-vma" | |
09250cfe ILT |
256 | } else { |
257 | pass "objcopy --adjust-vma" | |
258 | } | |
259 | } | |
260 | } | |
261 | } | |
262 | ||
263 | set arg "" | |
264 | set got $headers | |
265 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
266 | set vma 0x$vma | |
267 | if {$vma == $low} then { | |
268 | set arg "$arg --adjust-section-vma $name+4" | |
269 | } | |
270 | set got $rest | |
271 | } | |
272 | ||
862a5313 | 273 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec $arg"] |
09250cfe ILT |
274 | if ![string match "" $got] then { |
275 | fail "objcopy --adjust-section-vma +" | |
276 | } else { | |
862a5313 | 277 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"] |
787f6220 | 278 | set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" |
09250cfe ILT |
279 | if ![regexp $want $got all vma] then { |
280 | fail "objcopy --adjust-section-vma +" | |
281 | } else { | |
282 | set vma 0x$vma | |
283 | if {$vma != $low + 4} then { | |
854efa68 ILT |
284 | send_log "$vma != $low + 4\n" |
285 | fail "objcopy --adjust-section-vma +" | |
09250cfe ILT |
286 | } else { |
287 | pass "objcopy --adjust-section-vma +" | |
288 | } | |
289 | } | |
290 | } | |
291 | ||
292 | regsub -all "\\+4" $arg "=[expr $low + 4]" argeq | |
862a5313 | 293 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${copyfile}.srec $argeq"] |
09250cfe ILT |
294 | if ![string match "" $got] then { |
295 | fail "objcopy --adjust-section-vma =" | |
296 | } else { | |
862a5313 | 297 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"] |
787f6220 | 298 | set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)" |
09250cfe ILT |
299 | if ![regexp $want $got all vma] then { |
300 | fail "objcopy --adjust-section-vma =" | |
301 | } else { | |
302 | set vma 0x$vma | |
303 | if {$vma != $low + 4} then { | |
854efa68 ILT |
304 | send_log "$vma != $low + 4\n" |
305 | fail "objcopy --adjust-section-vma =" | |
09250cfe ILT |
306 | } else { |
307 | pass "objcopy --adjust-section-vma =" | |
308 | } | |
309 | } | |
310 | } | |
311 | } | |
febc1fc3 ILT |
312 | |
313 | # Test stripping an object. | |
314 | ||
315 | proc strip_test { } { | |
316 | global CC | |
317 | global STRIP | |
318 | global STRIPFLAGS | |
319 | global NM | |
320 | global NMFLAGS | |
321 | global srcdir | |
322 | global subdir | |
323 | ||
324 | set test "strip" | |
325 | ||
862a5313 | 326 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { |
febc1fc3 ILT |
327 | untested $test |
328 | return | |
329 | } | |
330 | ||
862a5313 VM |
331 | if [is_remote host] { |
332 | set objfile [remote_download host tmpdir/testprog.o]; | |
333 | } else { | |
334 | set objfile tmpdir/testprog.o | |
febc1fc3 ILT |
335 | } |
336 | ||
862a5313 | 337 | set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"] |
febc1fc3 ILT |
338 | if ![string match "" $exec_output] { |
339 | fail $test | |
340 | return | |
341 | } | |
342 | ||
862a5313 | 343 | set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"] |
febc1fc3 ILT |
344 | if ![string match "No symbols in *" $exec_output] { |
345 | fail $test | |
346 | return | |
347 | } | |
348 | ||
349 | pass $test | |
350 | } | |
351 | ||
352 | strip_test | |
353 | ||
862a5313 | 354 | # Test stripping an object file with saving a symbol |
febc1fc3 | 355 | |
862a5313 | 356 | proc strip_test_with_saving_a_symbol { } { |
febc1fc3 | 357 | global CC |
862a5313 VM |
358 | global STRIP |
359 | global STRIPFLAGS | |
360 | global NM | |
361 | global NMFLAGS | |
febc1fc3 ILT |
362 | global srcdir |
363 | global subdir | |
364 | ||
862a5313 VM |
365 | set test "strip with saving a symbol" |
366 | ||
367 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { | |
368 | untested $test | |
369 | return | |
370 | } | |
371 | ||
372 | if [is_remote host] { | |
373 | set objfile [remote_download host tmpdir/testprog.o]; | |
374 | } else { | |
375 | set objfile tmpdir/testprog.o | |
febc1fc3 ILT |
376 | } |
377 | ||
862a5313 VM |
378 | set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main $objfile"] |
379 | if ![string match "" $exec_output] { | |
380 | fail $test | |
381 | return | |
febc1fc3 ILT |
382 | } |
383 | ||
862a5313 VM |
384 | set exec_output [binutils_run $NM "$NMFLAGS $objfile"] |
385 | if ![regexp {^([0-9a-fA-F]+)?[ ]+T main} $exec_output] { | |
386 | fail $test | |
387 | return | |
388 | } | |
389 | ||
390 | pass $test | |
391 | } | |
392 | ||
393 | strip_test_with_saving_a_symbol | |
394 | ||
395 | # Build a final executable. | |
396 | ||
397 | proc copy_setup { } { | |
398 | global srcdir | |
399 | global subdir | |
400 | ||
401 | set res [build_wrapper testglue.o]; | |
402 | set flags { debug }; | |
403 | ||
404 | if { $res != "" } { | |
405 | lappend flags "additional_flags=[lindex $res 1]"; | |
406 | set add_libs "testglue.o"; | |
407 | } else { | |
408 | set add_libs ""; | |
409 | } | |
410 | ||
411 | if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/testprog executable $flags] != "" } { | |
412 | return 2 | |
febc1fc3 ILT |
413 | } |
414 | ||
862a5313 VM |
415 | set result [remote_load target tmpdir/testprog]; |
416 | set status [lindex $result 0]; | |
417 | ||
418 | if { $status != "pass" } { | |
419 | perror "unresolved setup, status = $status" | |
febc1fc3 ILT |
420 | return 3 |
421 | } | |
422 | ||
423 | return 0 | |
424 | } | |
425 | ||
426 | # Test copying an executable. | |
427 | ||
428 | proc copy_executable { prog flags test1 test2 } { | |
429 | ||
862a5313 VM |
430 | if [is_remote host] { |
431 | set testfile [remote_download host tmpdir/testprog]; | |
432 | set testcopy copyprog | |
433 | } else { | |
434 | set testfile tmpdir/testprog | |
435 | set testcopy tmpdir/copyprog | |
436 | } | |
437 | remote_file host delete $testcopy; | |
438 | ||
439 | set exec_output [binutils_run $prog "$flags $testfile $testcopy"] | |
440 | ||
febc1fc3 ILT |
441 | if ![string match "" $exec_output] { |
442 | fail $test1 | |
443 | fail $test2 | |
444 | return | |
445 | } | |
446 | ||
862a5313 VM |
447 | if [is_remote host] { |
448 | remote_upload host $testcopy tmpdir/copyprog | |
449 | } | |
450 | ||
451 | set status [remote_exec build "cmp" "tmpdir/testprog tmpdir/copyprog"] | |
452 | set exec_output [lindex $status 1]; | |
febc1fc3 ILT |
453 | |
454 | if [string match "" $exec_output] then { | |
455 | pass $test1 | |
456 | } else { | |
457 | send_log "$exec_output\n" | |
458 | verbose "$exec_output" | |
862a5313 | 459 | |
febc1fc3 | 460 | # This will fail for many reasons. For example, it will most |
862a5313 | 461 | # likely fail if a non-GNU linker is used. Therefore, we do |
febc1fc3 ILT |
462 | # not insist that it pass. If you are using an assembler and |
463 | # linker based on the same BFD as objcopy, it is worth | |
862a5313 VM |
464 | # investigating to see why this failure occurs. If we are |
465 | # cross compiling, we assume that a GNU linker is being used, | |
466 | # and expect it to succeed. | |
467 | if {[isnative]} then { | |
468 | setup_xfail "*-*-*" | |
469 | } | |
470 | ||
febc1fc3 ILT |
471 | fail $test1 |
472 | } | |
473 | ||
862a5313 VM |
474 | set output [remote_load target tmpdir/copyprog] |
475 | set status [lindex $output 0]; | |
476 | if { $status != "pass" } { | |
febc1fc3 ILT |
477 | fail $test2 |
478 | } else { | |
479 | pass $test2 | |
480 | } | |
481 | } | |
482 | ||
483 | # Test stripping an executable | |
484 | ||
485 | proc strip_executable { prog flags test } { | |
862a5313 VM |
486 | global NM |
487 | global NMFLAGS | |
488 | ||
489 | remote_download build tmpdir/copyprog tmpdir/striprog | |
490 | if [is_remote host] { | |
491 | set copyfile [remote_download host tmpdir/striprog]; | |
492 | } else { | |
493 | set copyfile tmpdir/striprog | |
494 | } | |
febc1fc3 | 495 | |
862a5313 | 496 | set exec_output [binutils_run $prog "$flags ${copyfile}"] |
febc1fc3 ILT |
497 | if ![string match "" $exec_output] { |
498 | fail $test | |
499 | return | |
500 | } | |
501 | ||
862a5313 VM |
502 | if [is_remote host] { |
503 | remote_upload host ${copyfile} tmpdir/striprog; | |
504 | } | |
505 | ||
506 | set result [remote_load target tmpdir/striprog] | |
507 | set status [lindex $result 0]; | |
508 | if { $status != "pass" } { | |
febc1fc3 | 509 | fail $test |
862a5313 VM |
510 | return |
511 | } | |
512 | ||
513 | set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] | |
514 | if ![string match "$copyfile: no symbols*" $exec_output] { | |
515 | fail $test | |
516 | return | |
517 | } | |
518 | pass $test | |
519 | } | |
520 | ||
521 | # Test stripping an executable with saving a symbol | |
522 | ||
523 | proc strip_executable_with_saving_a_symbol { prog flags test } { | |
524 | global NM | |
525 | global NMFLAGS | |
526 | ||
527 | remote_download build tmpdir/copyprog tmpdir/striprog | |
528 | if [is_remote host] { | |
529 | set copyfile [remote_download host tmpdir/striprog]; | |
febc1fc3 | 530 | } else { |
862a5313 | 531 | set copyfile tmpdir/striprog |
febc1fc3 | 532 | } |
862a5313 VM |
533 | |
534 | set exec_output [binutils_run $prog "$flags ${copyfile}"] | |
535 | if ![string match "" $exec_output] { | |
536 | fail $test | |
537 | return | |
538 | } | |
539 | ||
540 | if [is_remote host] { | |
541 | remote_upload host ${copyfile} tmpdir/striprog; | |
542 | } | |
543 | ||
544 | set result [remote_load target tmpdir/striprog] | |
545 | set status [lindex $result 0]; | |
546 | if { $status != "pass" } { | |
547 | fail $test | |
548 | return | |
549 | } | |
550 | ||
551 | set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] | |
552 | if ![regexp {^[0-9a-fA-F]+ T main} $exec_output] { | |
553 | fail $test | |
554 | return | |
555 | } | |
556 | pass $test | |
febc1fc3 ILT |
557 | } |
558 | ||
559 | set test1 "simple objcopy of executable" | |
560 | set test2 "run objcopy of executable" | |
561 | set test3 "run stripped executable" | |
862a5313 | 562 | set test4 "run stripped executable with saving a symbol" |
febc1fc3 ILT |
563 | |
564 | switch [copy_setup] { | |
565 | "1" { | |
566 | # do nothing | |
567 | } | |
568 | "2" { | |
569 | untested $test1 | |
570 | untested $test2 | |
571 | untested $test3 | |
862a5313 | 572 | untested $test4 |
febc1fc3 ILT |
573 | } |
574 | "3" { | |
575 | unresolved $test1 | |
576 | unresolved $test2 | |
577 | unresolved $test3 | |
862a5313 | 578 | unresolved $test4 |
febc1fc3 ILT |
579 | } |
580 | "0" { | |
581 | copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2" | |
582 | strip_executable "$STRIP" "$STRIPFLAGS" "$test3" | |
862a5313 | 583 | strip_executable_with_saving_a_symbol "$STRIP" "-K main $STRIPFLAGS" "$test4" |
febc1fc3 ILT |
584 | } |
585 | } |