1 # Test linking directly to S
-records.
2 # By Ian Lance Taylor
, Cygnus Support.
4 # Free Software Foundation
, Inc.
6 # This file is free software
; you can redistribute it and
/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation
; either version
2 of the License
, or
9 #
(at your option
) any later version.
11 # This
program is distributed in the hope that it will be useful
,
12 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License
for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this
program; if not
, write to the Free Software
18 # Foundation
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
20 #
Get the offset from an S
-record line to the start of the data.
23 if [string match
"S1*" $l] {
25 } else { if [string match
"S2*" $l] {
27 } else { if [string match
"S3*" $l] {
34 # See
if an S
-record line contains only zero data.
36 proc srec_zero
{ l
} {
37 if [string match
"S\[0789\]*" $l] {
41 #
Strip the address and checksum.
42 if [string match
"S\[123\]*" $l] {
43 set l
[string range $l
[srec_off $l
] [expr
[string length $l
] - 3]]
48 # The rest must be zero.
49 return [string match
"" [string trim $l "0"]]
52 #
Get the address of an S
-record line.
54 proc srec_addr
{ l
} {
55 if [string match
"S\[123\]*" $l] {
56 set addr
[string range $l
4 [expr
[srec_off $l
] - 1]]
64 #
Get the number of data bytes in an S
-record line.
67 if ![string match
"S\[123\]*" $l] {
71 return [expr
"0x[string range $l 2 3]" - ([srec_off $l] - 4) / 2 - 1]
74 # Extract bytes from an S
-record line.
76 proc srec_extract
{ l start len
} {
78 set rlen
[srec_len $l
]
79 set stop
[expr $start
+ $len
]
80 if { $stop
> $rlen
} {
83 set start
[expr $start
* 2 + $
off]
84 set stop
[expr $stop
* 2 + $
off - 1]
85 return [string range $l $start $stop
]
88 # See
if a range of bytes in an S
-record line is all zeroes.
90 proc srec_zero_range
{ l start len
} {
91 return [string match
"" [string trim [srec_extract $l $start $len] "0"]]
94 # Trim an S
-record line such that the specified number of bytes remain
97 proc srec_trim
{ l leave
} {
99 set addr
[srec_addr $l
]
100 set len
[srec_len $l
]
102 if { $leave
>= $len
} {
106 set s1
[string range $l
0 1]
107 set s2
[format
"%02x" [expr ($off - 4) / 2 + $leave + 1]]
108 set s3
[format
"%0[expr $off - 4]x" [expr $addr + $len - $leave]]
109 set s4
[string range $l
[expr
[string length $l
] - ($leave
* 2) - 2] end
]
110 set s
"${s1}${s2}${s3}${s4}"
112 verbose
"srec_trim { '$l' $leave } returning '$s'" 2
117 #
Report failure when comparing S
-record lines
119 proc srec_compare_fail
{ which l1 l2
} {
120 send_log
"comparison failure $which:\n$l1\n$l2\n"
121 verbose
"comparison failure $which:\n$l1\n$l2"
124 # Compare S
-record files. We don
't want to fuss about things like
125 # extra zeroes. Note that BFD always sorts S-records by address.
127 proc srec_compare { f1 f2 } {
131 while { $e1 != -1 } {
132 set l1 [string trimright $l1 "\r\n"]
133 set l2 [string trimright $l2 "\r\n"]
135 # If l1 contains data, it must be zero.
136 if ![srec_zero $l1] {
137 send_log "data after EOF: $l1\n"
138 verbose "data after EOF: $l1"
141 } else { if { [string compare $l1 $l2] == 0 } {
144 } else { if { [srec_zero $l1] } {
146 } else { if { [srec_zero $l2] } {
149 # The strings are not the same, and neither is all zeroes.
150 set a1 [srec_addr $l1]
151 set n1 [srec_len $l1]
152 set a2 [srec_addr $l2]
153 set n2 [srec_len $l2]
155 if { $a1 < $a2 && ![srec_zero_range $l1 0 [expr $a2 - $a1]] } {
156 verbose "$a1 $a2 [srec_extract $l1 0 [expr $a2 - $a1]]" 2
157 srec_compare_fail 1 $l1 $l2
160 if { $a2 < $a1 && ![srec_zero_range $l2 0 [expr $a1 - $a2]] } {
161 srec_compare_fail 2 $l1 $l2
165 # Here we know that any initial data in both lines is
166 # zero. Now make sure that any overlapping data matches.
168 set os1 [expr $a2 - $a1]
172 set os2 [expr $a1 - $a2]
174 if { $a1 + $n1 < $a2 + $n2 } {
175 set ol [expr $n1 - $os1]
177 set ol [expr $n2 - $os2]
180 set x1 [srec_extract $l1 $os1 $ol]
181 set x2 [srec_extract $l2 $os2 $ol]
182 if { [string compare $x1 $x2] != 0 } {
183 verbose "$os1 $ol $x1" 2
184 verbose "$os2 $ol $x2" 2
185 srec_compare_fail 3 $l1 $l2
189 # These strings match. Trim the data from the larger
190 # string, read a new copy of the smaller string, and
192 if { $a1 + $n1 < $a2 + $n2 } {
193 set l2 [srec_trim $l2 [expr ($a2 + $n2) - ($a1 + $n1)]]
195 } else { if { $a1 + $n1 > $a2 + $n2 } {
196 set l1 [srec_trim $l1 [expr ($a1 + $n1) - ($a2 + $n2)]]
205 # We've reached the end of the first file. The remainder of the
206 # second file must contain only zeroes.
207 while { $e2
!= -1 } {
208 set l2
[string trimright $l2
"\r\n"]
209 if ![srec_zero $l2
] {
210 send_log
"data after EOF: $l2\n"
211 verbose
"data after EOF: $l2"
220 # Link twice
, objcopy
, and compare
222 proc run_srec_test
{ test objs
} {
225 global sizeof_headers
230 #
If the linker script uses SIZEOF_HEADERS
, use a
-Ttext
argument
231 # to force both the
normal link and the S
-record link to be put in
232 # the same place. We don
't always use -Ttext because it interacts
235 if { $sizeof_headers } {
236 set flags "$flags -Ttext 0x1000"
239 # The a29k compiled code calls V_SPILL and V_FILL. Since we don't
240 # need to run this code
, but we don
't have definitions for those
241 # functions, we just define them out.
242 if [istarget a29k*-*-*] {
243 set flags "$flags --defsym V_SPILL=0 --defsym V_FILL=0"
246 if {[istarget arm*-*-*] || \
247 [istarget strongarm*-*-*] || \
248 [istarget xscale*-*-*] || \
249 [istarget thumb-*-*] } {
251 # ARM targets call __gccmain
252 set flags "$flags --defsym __gccmain=0"
254 # ARM targets cannot convert format in the linker
255 # using the --oformat command line switch
256 setup_xfail "*arm*-*-*"
257 setup_xfail "xscale-*-*"
258 setup_xfail "thumb-*-*"
261 # PowerPC EABI code calls __eabi.
262 if [istarget powerpc*-*-eabi*] {
263 set flags "$flags --defsym __eabi=0"
266 # mn10200 code calls __truncsipsi2_d0_d2.
267 if {[istarget mn10200*-*-*]} then {
268 set flags "$flags --defsym __truncsipsi2_d0_d2=0"
271 # m6811/m6812 code has references to soft registers.
272 if {[istarget m6811-*-*] || [istarget m6812-*-*]} {
273 set flags "$flags --defsym _.frame=0 --defsym _.d1=0 --defsym _.d2=0"
274 set flags "$flags --defsym _.d3=0 --defsym _.d4=0"
275 set flags "$flags --defsym _.tmp=0 --defsym _.xy=0"
278 # V850 targets need libgcc.a
279 if [istarget v850*-*-elf] {
280 set objs "$objs -L ../gcc -lgcc"
283 if { ![ld_simple_link $ld tmpdir/sr1 "$flags $objs"] \
284 || ![ld_simple_link $ld tmpdir/sr2.sr "$flags --oformat srec $objs"] } {
285 setup_xfail "hppa*-*-*elf*"
290 send_log "$objcopy -O srec tmpdir/sr1 tmpdir/sr1.sr\n"
291 verbose "$objcopy -O srec tmpdir/sr1 tmpdir/sr1.sr"
292 catch "exec $objcopy -O srec tmpdir/sr1 tmpdir/sr1.sr" exec_output
293 set exec_output [prune_warnings $exec_output]
294 if ![string match "" $exec_output] {
295 send_log "$exec_output\n"
296 verbose "$exec_output"
301 set f1 [open tmpdir/sr1.sr r]
302 set f2 [open tmpdir/sr2.sr r]
303 if [srec_compare $f1 $f2] {
312 set test1 "S-records"
313 set test2 "S-records with constructors"
315 # See whether the default linker script uses SIZEOF_HEADERS.
316 catch "exec $ld --verbose" exec_output
317 set sizeof_headers [string match "*SIZEOF_HEADERS*" $exec_output]
319 # First test linking a C program. We don't require
any libraries. We
320 # link it normally
, and objcopy to the S
-record format
, and
then link
321 # directly to the S
-record format
, and require that the two files
322 # contain the same data.
324 if { [which $CC
] == 0 } {
330 if { ![ld_compile $CC $srcdir
/$subdir
/sr1.c tmpdir
/sr1.o
] \
331 ||
![ld_compile $CC $srcdir
/$subdir
/sr2.c tmpdir
/sr2.o
] } {
337 # The i386
-aout target is confused
: the linker does not put the
338 # sections where objdump finds them. I don
't know which is wrong.
339 setup_xfail "i*86-*-aout*"
341 # These tests fail on the native MIPS ELF targets because the GP value
342 # in the .reginfo section is not updated when the S-record version is
343 # written out. The mips-elf target itself does not use a .reginfo section.
344 setup_xfail "mips*-*-irix5*" "mips*-*-irix6*"
346 # The S-record linker doesn't
do the magic TOC handling that XCOFF
348 setup_xfail
"*-*-aix*" "*-*-xcoff*"
350 # The S
-record linker doesn
't build ARM/Thumb stubs.
351 setup_xfail "arm-*-coff"
352 setup_xfail "strongarm*-*-coff"
353 setup_xfail "xscale*-*-coff"
354 setup_xfail "arm-*-pe*"
355 # setup_xfail "arm-*elf*"
356 setup_xfail "thumb-*-coff*"
357 setup_xfail "thumb-*-pe*"
358 setup_xfail "thumb-*-elf*"
359 setup_xfail "arm*-*-linux*"
361 # The S-record linker doesn't build special EABI sections.
362 setup_xfail
"powerpc*-*-eabi*"
364 # The S
-record linker doesn
't include the .{zda} sections.
365 setup_xfail "v850*-*-elf"
367 # The S-record linker doesn't handle Alpha Elf relaxation.
368 setup_xfail
"alpha*-*-elf*" "alpha*-*-linux-gnu*" "alpha*-*-gnu*"
369 setup_xfail
"alpha*-*-netbsd*"
371 # The S
-record linker hasn
't any hope of coping with HPPA relocs.
372 setup_xfail "hppa*-*-*"
374 # The S-record linker doesn't support the special PE headers
- the PE
375 # emulation tries to write pe
-specific information to the PE headers
376 # in the output bfd
, but it
's not a PE bfd (it's an srec bfd
)
377 setup_xfail
"*-*-cygwin*" "*-*-mingw*" "*-*-pe*" "*-*-winnt*"
379 run_srec_test $test1
"tmpdir/sr1.o tmpdir/sr2.o"
381 # Now try linking a C
++ program with global constructors and
382 # destructors. Note that since we are not linking against
any
383 # libraries
, this
program won
't actually work or anything.
385 if { [which $CXX] == 0 } {
390 if ![ld_compile "$CXX $CXXFLAGS -fgnu-linker" $srcdir/$subdir/sr3.cc tmpdir/sr3.o] {
396 setup_xfail "i*86-*-aout*"
397 setup_xfail "mips*-*-irix5*" "mips*-*-irix6*"
398 setup_xfail "*-*-aix*" "*-*-xcoff*"
399 setup_xfail "arm*-*-*"
400 setup_xfail "strongarm*-*-*"
401 setup_xfail "thumb-*-*"
402 setup_xfail "powerpc*-*-eabi*"
403 setup_xfail "v850*-*-elf"
404 setup_xfail "alpha*-*-elf*" "alpha*-*-linux-gnu*" "alpha*-*-gnu*"
405 setup_xfail "alpha*-*-netbsd*"
406 setup_xfail "hppa*-*-*"
407 setup_xfail "*-*-cygwin*" "*-*-mingw*" "*-*-pe*" "*-*-winnt*"
409 run_srec_test $test2 "tmpdir/sr3.o"