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_warnings $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_warnings $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_warnings $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_warnings $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)(\[^\n\]*: 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 } {
118 if {[llength $cc_prog] > 1} then {
119 set cc_prog [lindex $cc_prog 0]
121 if {[which $cc_prog] == 0} then {
122 perror "$cc_prog does not exist"
126 catch "exec rm -f $object" exec_output
128 set flags "-I$srcdir/$subdir $CFLAGS"
130 # If we are compiling with gcc, we want to add gcc_gas_flag to
131 # flags. Rather than determine this in some complex way, we guess
132 # based on the name of the compiler.
133 if {[string match "*gcc*" $cc] || [string match "*++*" $cc]} then {
134 set flags "$gcc_gas_flag $flags"
137 verbose -log "$cc $flags -c $source -o $object"
139 catch "exec $cc $flags -c $source -o $object" exec_output
140 set exec_output [prune_warnings $exec_output]
141 if [string match "" $exec_output] then {
142 if {![file exists $object]} then {
143 regexp ".*/(\[^/\]*)$" $source all dobj
144 regsub "\\.c" $dobj ".o" realobj
145 verbose "looking for $realobj"
146 if {[file exists $realobj]} then {
147 verbose -log "mv $realobj $object"
148 catch "exec mv $realobj $object" exec_output
149 set exec_output [prune_warnings $exec_output]
150 if {![string match "" $exec_output]} then {
151 verbose -log "$exec_output"
152 perror "could not move $realobj to $object"
156 perror "$object not found after compilation"
162 verbose -log "$exec_output"
163 perror "$source: compilation failed"
169 # default_ld_assemble
172 proc default_ld_assemble { as source object } {
176 if {[which $as] == 0} then {
177 perror "$as does not exist"
181 if ![info exists ASFLAGS] { set ASFLAGS "" }
183 verbose -log "$as $ASFLAGS -o $object $source"
185 catch "exec $as $ASFLAGS -o $object $source" exec_output
186 set exec_output [prune_warnings $exec_output]
187 if [string match "" $exec_output] then {
190 verbose -log "$exec_output"
191 perror "$source: assembly failed"
198 # run nm on a file, putting the result in the array nm_output
200 proc default_ld_nm { nm object } {
205 if {[which $nm] == 0} then {
206 perror "$nm does not exist"
210 if {[info exists nm_output]} {
214 if ![info exists NMFLAGS] { set NMFLAGS "" }
216 verbose -log "$nm $NMFLAGS $object >tmpdir/nm.out"
218 catch "exec $nm $NMFLAGS $object >tmpdir/nm.out" exec_output
219 set exec_output [prune_warnings $exec_output]
220 if [string match "" $exec_output] then {
221 set file [open tmpdir/nm.out r]
222 while { [gets $file line] != -1 } {
224 if [regexp "^(\[0-9a-fA-F\]+) \[a-zA-Z0-9\] (.+)$" $line whole value name] {
225 set name [string trimleft $name "_"]
226 verbose "Setting nm_output($name) to 0x$value" 2
227 set nm_output($name) 0x$value
233 verbose -log "$exec_output"
234 perror "$object: nm failed"
241 # compares two files line-by-line
242 # returns differences if exist
243 # returns null if file(s) cannot be opened
245 proc simple_diff { file_1 file_2 } {
251 if [file exists $file_1] then {
252 set file_a [open $file_1 r]
254 warning "$file_1 doesn't exist"
258 if [file exists $file_2] then {
259 set file_b [open $file_2 r]
261 fail "$file_2 doesn't exist"
265 verbose "# Diff'ing: $file_1 $file_2\n" 2
267 while { [gets $file_a line] != $eof } {
268 if [regexp "^#.*$" $line] then {
276 while { [gets $file_b line] != $eof } {
277 if [regexp "^#.*$" $line] then {
285 for { set i 0 } { $i < [llength $list_a] } { incr i } {
286 set line_a [lindex $list_a $i]
287 set line_b [lindex $list_b $i]
289 verbose "\t$file_1: $i: $line_a\n" 3
290 verbose "\t$file_2: $i: $line_b\n" 3
291 if [string compare $line_a $line_b] then {
292 verbose -log "\t$file_1: $i: $line_a\n"
293 verbose -log "\t$file_2: $i: $line_b\n"
300 if { [llength $list_a] != [llength $list_b] } {
305 if $differences<1 then {
310 # This definition is taken from an unreleased version of DejaGnu. Once
311 # that version gets released, and has been out in the world for a few
312 # months at least, it may be safe to delete this copy.
313 if ![string length [info proc prune_warnings]] {
315 # prune_warnings -- delete various system verbosities from TEXT
318 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
320 # Sites with particular verbose os's may wish to override this in site.exp.
322 proc prune_warnings { text } {
323 # This is from sun4's. Do it for all machines for now.
324 # The "\\1" is to try to preserve a "\n" but only if necessary.
325 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
327 # It might be tempting to get carried away and delete blank lines, etc.
328 # Just delete *exactly* what we're ask to, and that's it.