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 "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" $tmp version cyg number
16 if [info exists number] then {
17 clone_output "$ld $number\n"
23 # link an object using relocation
25 proc default_ld_relocate { ld target objects } {
29 if { [which $ld] == 0 } then {
30 perror "$ld does not exist"
34 verbose -log "$ld $HOSTING_EMU -o $target -r $objects"
36 catch "exec $ld $HOSTING_EMU -o $target -r $objects" exec_output
37 set exec_output [prune_system_crud $host_triplet $exec_output]
38 if [string match "" $exec_output] then {
41 verbose -log "$exec_output"
49 # link a program using ld
51 proc default_ld_link { ld target objects } {
57 set objs "$HOSTING_CRT0 $objects"
58 set libs "$HOSTING_LIBS"
60 if { [which $ld] == 0 } then {
61 perror "$ld does not exist"
65 verbose -log "$ld $HOSTING_EMU -o $target $objs $libs"
67 catch "exec $ld $HOSTING_EMU -o $target $objs $libs" exec_output
68 set exec_output [prune_system_crud $host_triplet $exec_output]
69 if [string match "" $exec_output] then {
72 verbose -log "$exec_output"
78 # default_ld_simple_link
79 # link a program using ld, without including any libraries
81 proc default_ld_simple_link { ld target objects } {
84 if { [which $ld] == 0 } then {
85 perror "$ld does not exist"
89 verbose -log "$ld -o $target $objects"
91 catch "exec $ld -o $target $objects" exec_output
92 set exec_output [prune_system_crud $host_triplet $exec_output]
94 # We don't care if we get a warning about a non-existent start
95 # symbol, since the default linker script might use ENTRY.
96 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
98 if [string match "" $exec_output] then {
101 verbose -log "$exec_output"
108 # compile an object using cc
110 proc default_ld_compile { cc source object } {
117 if {[llength $cc_prog] > 1} then {
118 set cc_prog [lindex $cc_prog 0]
120 if {[which $cc_prog] == 0} then {
121 perror "$cc_prog does not exist"
125 catch "exec rm -f $object" exec_output
127 verbose -log "$cc -I$srcdir$subdir -c $CFLAGS $source -o $object"
129 catch "exec $cc -I$srcdir$subdir -c $CFLAGS $source -o $object" exec_output
130 set exec_output [prune_system_crud $host_triplet $exec_output]
131 if [string match "" $exec_output] then {
132 if {![file exists $object]} then {
133 regexp ".*/(\[^/\]*)$" $source all dobj
134 regsub "\\.c" $dobj ".o" realobj
135 verbose "looking for $realobj"
136 if {[file exists $realobj]} then {
137 verbose -log "mv $realobj $object"
138 catch "exec mv $realobj $object" exec_output
139 set exec_output [prune_system_crud $host_triplet $exec_output]
140 if {![string match "" $exec_output]} then {
141 verbose -log "$exec_output"
142 perror "could not move $realobj to $object"
146 perror "$object not found after compilation"
152 verbose -log "$exec_output"
153 perror "$source: compilation failed"
159 # default_ld_assemble
162 proc default_ld_assemble { as source object } {
166 if {[which $as] == 0} then {
167 perror "$as does not exist"
171 if ![info exists ASFLAGS] { set ASFLAGS "" }
173 verbose -log "$as $ASFLAGS -o $object $source"
175 catch "exec $as $ASFLAGS -o $object $source" exec_output
176 set exec_output [prune_system_crud $host_triplet $exec_output]
177 if [string match "" $exec_output] then {
180 verbose -log "$exec_output"
181 perror "$source: assembly failed"
188 # run nm on a file, putting the result in the array nm_output
190 proc default_ld_nm { nm object } {
195 if {[which $nm] == 0} then {
196 perror "$nm does not exist"
200 if ![info exists NMFLAGS] { set NMFLAGS "" }
202 verbose -log "$nm $NMFLAGS $object >tmpdir/nm.out"
204 catch "exec $nm $NMFLAGS $object >tmpdir/nm.out" exec_output
205 set exec_output [prune_system_crud $host_triplet $exec_output]
206 if [string match "" $exec_output] then {
207 set file [open tmpdir/nm.out r]
208 while { [gets $file line] != -1 } {
210 if [regexp "^(\[0-9a-fA-F\]+) \[a-zA-Z0-9\] (.+)$" $line whole value name] {
211 verbose "Setting nm_output($name) to 0x$value" 2
212 set nm_output($name) 0x$value
218 verbose -log "$exec_output"
219 perror "$object: nm failed"
226 # compares two files line-by-line
227 # returns differences if exist
228 # returns null if file(s) cannot be opened
230 proc simple_diff { file_1 file_2 } {
236 if [file exists $file_1] then {
237 set file_a [open $file_1 r]
239 warning "$file_1 doesn't exist"
243 if [file exists $file_2] then {
244 set file_b [open $file_2 r]
246 fail "$file_2 doesn't exist"
250 verbose "# Diff'ing: $file_1 $file_2\n" 2
252 while { [gets $file_a line] != $eof } {
253 if [regexp "^#.*$" $line] then {
261 while { [gets $file_b line] != $eof } {
262 if [regexp "^#.*$" $line] then {
270 for { set i 0 } { $i < [llength $list_a] } { incr i } {
271 set line_a [lindex $list_a $i]
272 set line_b [lindex $list_b $i]
274 verbose "\t$file_1: $i: $line_a\n" 3
275 verbose "\t$file_2: $i: $line_b\n" 3
276 if [string compare $line_a $line_b] then {
277 verbose -log "\t$file_1: $i: $line_a\n"
278 verbose -log "\t$file_2: $i: $line_b\n"
285 if { [llength $list_a] != [llength $list_b] } {
290 if $differences<1 then {
295 # This definition is taken from an unreleased version of DejaGnu. Once
296 # that version gets released, and has been out in the world for a few
297 # months at least, it may be safe to delete this copy.
298 if ![string length [info proc prune_system_crud]] {
300 # prune_system_crud -- delete various system verbosities from TEXT on SYSTEM
303 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
305 # SYSTEM is typical $target_triplet or $host_triplet.
307 # This is useful when trying to do pattern matches on program output.
308 # Sites with particular verbose os's may wish to override this in site.exp.
310 proc prune_system_crud { system text } {
311 # This is from sun4's. Do it for all machines for now.
312 # The "\\1" is to try to preserve a "\n" but only if necessary.
313 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
315 # It might be tempting to get carried away and delete blank lines, etc.
316 # Just delete *exactly* what we're ask to, and that's it.