3 # extract and print the version number of ld
5 proc default_ld_version { ld } {
8 if { [which $ld] == 0 } then {
9 perror "$ld does not exist"
13 catch "exec $ld --version" tmp
14 set tmp [prune_system_crud $host_triplet $tmp]
15 regexp "version.*$" $tmp version
17 if [info exists version] then {
18 clone_output "$ld $version\n"
24 # link an object using relocation
26 proc default_ld_relocate { ld target objects } {
30 if { [which $ld] == 0 } then {
31 perror "$ld does not exist"
35 send_log "$ld $HOSTING_EMU -o $target -r $objects\n"
36 verbose "$ld $HOSTING_EMU -o $target -r $objects"
38 catch "exec $ld $HOSTING_EMU -o $target -r $objects" exec_output
39 set exec_output [prune_system_crud $host_triplet $exec_output]
40 if [string match "" $exec_output] then {
43 send_log "$exec_output\n"
44 verbose "$exec_output"
52 # link a program using ld
54 proc default_ld_link { ld target objects } {
60 set objs "$HOSTING_CRT0 $objects"
61 set libs "$HOSTING_LIBS"
63 if { [which $ld] == 0 } then {
64 perror "$ld does not exist"
68 send_log "$ld $HOSTING_EMU -o $target $objs $libs\n"
69 verbose "$ld $HOSTING_EMU -o $target $objs $libs"
71 catch "exec $ld $HOSTING_EMU -o $target $objs $libs" exec_output
72 set exec_output [prune_system_crud $host_triplet $exec_output]
73 if [string match "" $exec_output] then {
76 send_log "$exec_output\n"
77 verbose "$exec_output"
83 # default_ld_simple_link
84 # link a program using ld, without including any libraries
86 proc default_ld_simple_link { ld target objects } {
89 if { [which $ld] == 0 } then {
90 perror "$ld does not exist"
94 send_log "$ld -o $target $objects\n"
95 verbose "$ld -o $target $objects"
97 catch "exec $ld -o $target $objects" exec_output
98 set exec_output [prune_system_crud $host_triplet $exec_output]
99 if [string match "" $exec_output] then {
102 send_log "$exec_output\n"
103 verbose "$exec_output"
110 # compile an object using cc
112 proc default_ld_compile { cc source object } {
119 if {[llength $cc_prog] > 1} then {
120 set cc_prog [lindex $cc_prog 0]
122 if {[which $cc_prog] == 0} then {
123 perror "$cc_prog does not exist"
127 catch "exec rm -f $object" exec_output
129 send_log "$cc -I$srcdir$subdir -c $CFLAGS $source -o $object\n"
130 verbose "$cc -I$srcdir$subdir -c $CFLAGS $source -o $object"
132 catch "exec $cc -I$srcdir$subdir -c $CFLAGS $source -o $object" exec_output
133 set exec_output [prune_system_crud $host_triplet $exec_output]
134 if [string match "" $exec_output] then {
135 if {![file exists $object]} then {
136 regexp ".*/(\[^/\]*)$" $source all dobj
137 regsub "\\.c" $dobj ".o" realobj
138 verbose "looking for $realobj"
139 if {[file exists $realobj]} then {
140 send_log "mv $realobj $object\n"
141 verbose "mv $realobj $object"
142 catch "exec mv $realobj $object" exec_output
143 set exec_output [prune_system_crud $host_triplet $exec_output]
144 if {![string match "" $exec_output]} then {
145 send_log "$exec_output\n"
146 verbose "$exec_output"
147 perror "could not move $realobj to $object"
151 perror "$object not found after compilation"
157 send_log "$exec_output\n"
158 verbose "$exec_output"
159 perror "$source: compilation failed"
165 # default_ld_assemble
168 proc default_ld_assemble { as source object } {
172 if {[which $as] == 0} then {
173 perror "$as does not exist"
177 if ![info exists ASFLAGS] { set ASFLAGS "" }
179 send_log "$as $ASFLAGS -o $object $source\n"
180 verbose "$as $ASFLAGS -o $object $source"
182 catch "exec $as $ASFLAGS -o $object $source" exec_output
183 set exec_output [prune_system_crud $host_triplet $exec_output]
184 if [string match "" $exec_output] then {
187 send_log "$exec_output\n"
188 verbose "$exec_output"
189 perror "$source: assembly failed"
196 # run nm on a file, putting the result in the array nm_output
198 proc default_ld_nm { nm object } {
203 if {[which $nm] == 0} then {
204 perror "$nm does not exist"
208 if ![info exists NMFLAGS] { set NMFLAGS "" }
210 send_log "$nm $NMFLAGS $object >tmpdir/nm.out\n"
211 verbose "$nm $NMFLAGS $object >tmpdir/nm.out"
213 catch "exec $nm $NMFLAGS $object >tmpdir/nm.out" exec_output
214 set exec_output [prune_system_crud $host_triplet $exec_output]
215 if [string match "" $exec_output] then {
216 set file [open tmpdir/nm.out r]
217 while { [gets $file line] != -1 } {
219 if [regexp "^(\[0-9a-fA-F\]+) \[a-zA-Z0-9\] (.+)$" $line whole value name] {
220 verbose "Setting nm_output($name) to 0x$value" 2
221 set nm_output($name) 0x$value
227 send_log "$exec_output\n"
229 perror "$object: nm failed"
236 # compares two files line-by-line
237 # returns differences if exist
238 # returns null if file(s) cannot be opened
240 proc simple_diff { file_1 file_2 } {
246 if [file exists $file_1] then {
247 set file_a [open $file_1 r]
249 warning "$file_1 doesn't exist"
253 if [file exists $file_2] then {
254 set file_b [open $file_2 r]
256 fail "$file_2 doesn't exist"
260 verbose "# Diff'ing: $file_1 $file_2\n" 2
262 while { [gets $file_a line] != $eof } {
263 if [regexp "^#.*$" $line] then {
271 while { [gets $file_b line] != $eof } {
272 if [regexp "^#.*$" $line] then {
280 for { set i 0 } { $i < [llength $list_a] } { incr i } {
281 set line_a [lindex $list_a $i]
282 set line_b [lindex $list_b $i]
284 verbose "\t$file_1: $i: $line_a\n" 3
285 verbose "\t$file_2: $i: $line_b\n" 3
286 if [string compare $line_a $line_b] then {
287 verbose "\t$file_1: $i: $line_a\n" 1
288 verbose "\t$file_2: $i: $line_b\n" 1
290 send_log "\t$file_1: $i: $line_a\n"
291 send_log "\t$file_2: $i: $line_b\n"
298 if { [llength $list_a] != [llength $list_b] } {
303 if $differences<1 then {
308 # This definition is taken from an unreleased version of DejaGnu. Once
309 # that version gets released, and has been out in the world for a few
310 # months at least, it may be safe to delete this copy.
311 if ![string length [info proc prune_system_crud]] {
313 # prune_system_crud -- delete various system verbosities from TEXT on SYSTEM
316 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
318 # SYSTEM is typical $target_triplet or $host_triplet.
320 # This is useful when trying to do pattern matches on program output.
321 # Sites with particular verbose os's may wish to override this in site.exp.
323 proc prune_system_crud { system text } {
324 # This is from sun4's. Do it for all machines for now.
325 # The "\\1" is to try to preserve a "\n" but only if necessary.
326 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
328 # It might be tempting to get carried away and delete blank lines, etc.
329 # Just delete *exactly* what we're ask to, and that's it.