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"
46 # Look for big-endian or little-endian switches in the multlib
47 # options and translate these into a -EB or -EL switch. Note
48 # we cannot rely upon proc process_multilib_options to do this
49 # for us because for some targets the compiler does not support
50 # -EB/-EL but it does support -mbig-endian/-mlittle-endian, and
51 # the site.exp file will include the switch "-mbig-endian"
52 # (rather than "big-endian") which is not detected by proc
53 # process_multilib_options.
55 proc big_or_little_endian {} {
57 if [board_info [target_info name] exists multilib_flags] {
58 set tmp_flags " [board_info [target_info name] multilib_flags]";
60 foreach x $tmp_flags {
66 {*little*endian el EL} {
80 # link a program using ld
82 proc default_ld_link { ld target objects } {
88 set objs "$HOSTING_CRT0 $objects"
89 set libs "$HOSTING_LIBS"
91 if { [which $ld] == 0 } then {
92 perror "$ld does not exist"
96 set flags [big_or_little_endian]
98 verbose -log "$ld $HOSTING_EMU $flags -o $target $objs $libs"
100 catch "exec $ld $HOSTING_EMU $flags -o $target $objs $libs" exec_output
101 set exec_output [prune_warnings $exec_output]
102 if [string match "" $exec_output] then {
105 verbose -log "$exec_output"
111 # default_ld_simple_link
112 # link a program using ld, without including any libraries
114 proc default_ld_simple_link { ld target objects } {
117 if { [which $ld] == 0 } then {
118 perror "$ld does not exist"
122 set flags [big_or_little_endian]
124 verbose -log "$ld $flags -o $target $objects"
126 catch "exec $ld $flags -o $target $objects" exec_output
127 set exec_output [prune_warnings $exec_output]
129 # We don't care if we get a warning about a non-existent start
130 # symbol, since the default linker script might use ENTRY.
131 regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
133 if [string match "" $exec_output] then {
136 verbose -log "$exec_output"
143 # compile an object using cc
145 proc default_ld_compile { cc source object } {
153 if {[llength $cc_prog] > 1} then {
154 set cc_prog [lindex $cc_prog 0]
156 if {[which $cc_prog] == 0} then {
157 perror "$cc_prog does not exist"
161 catch "exec rm -f $object" exec_output
163 set flags "-I$srcdir/$subdir $CFLAGS"
165 # If we are compiling with gcc, we want to add gcc_gas_flag to
166 # flags. Rather than determine this in some complex way, we guess
167 # based on the name of the compiler.
168 if {[string match "*gcc*" $cc] || [string match "*++*" $cc]} then {
169 set flags "$gcc_gas_flag $flags"
172 if [board_info [target_info name] exists multilib_flags] {
173 append flags " [board_info [target_info name] multilib_flags]";
176 verbose -log "$cc $flags -c $source -o $object"
178 catch "exec $cc $flags -c $source -o $object" exec_output
179 set exec_output [prune_warnings $exec_output]
180 if [string match "" $exec_output] then {
181 if {![file exists $object]} then {
182 regexp ".*/(\[^/\]*)$" $source all dobj
183 regsub "\\.c" $dobj ".o" realobj
184 verbose "looking for $realobj"
185 if {[file exists $realobj]} then {
186 verbose -log "mv $realobj $object"
187 catch "exec mv $realobj $object" exec_output
188 set exec_output [prune_warnings $exec_output]
189 if {![string match "" $exec_output]} then {
190 verbose -log "$exec_output"
191 perror "could not move $realobj to $object"
195 perror "$object not found after compilation"
201 verbose -log "$exec_output"
202 perror "$source: compilation failed"
208 # default_ld_assemble
211 proc default_ld_assemble { as source object } {
215 if {[which $as] == 0} then {
216 perror "$as does not exist"
220 if ![info exists ASFLAGS] { set ASFLAGS "" }
222 set flags [big_or_little_endian]
224 verbose -log "$as $flags $ASFLAGS -o $object $source"
226 catch "exec $as $flags $ASFLAGS -o $object $source" exec_output
227 set exec_output [prune_warnings $exec_output]
228 if [string match "" $exec_output] then {
231 verbose -log "$exec_output"
232 perror "$source: assembly failed"
239 # run nm on a file, putting the result in the array nm_output
241 proc default_ld_nm { nm object } {
246 if {[which $nm] == 0} then {
247 perror "$nm does not exist"
251 if {[info exists nm_output]} {
255 if ![info exists NMFLAGS] { set NMFLAGS "" }
257 verbose -log "$nm $NMFLAGS $object >tmpdir/nm.out"
259 catch "exec $nm $NMFLAGS $object >tmpdir/nm.out" exec_output
260 set exec_output [prune_warnings $exec_output]
261 if [string match "" $exec_output] then {
262 set file [open tmpdir/nm.out r]
263 while { [gets $file line] != -1 } {
265 if [regexp "^(\[0-9a-fA-F\]+) \[a-zA-Z0-9\] (.+)$" $line whole value name] {
266 set name [string trimleft $name "_"]
267 verbose "Setting nm_output($name) to 0x$value" 2
268 set nm_output($name) 0x$value
274 verbose -log "$exec_output"
275 perror "$object: nm failed"
282 # compares two files line-by-line
283 # returns differences if exist
284 # returns null if file(s) cannot be opened
286 proc simple_diff { file_1 file_2 } {
292 if [file exists $file_1] then {
293 set file_a [open $file_1 r]
295 warning "$file_1 doesn't exist"
299 if [file exists $file_2] then {
300 set file_b [open $file_2 r]
302 fail "$file_2 doesn't exist"
306 verbose "# Diff'ing: $file_1 $file_2\n" 2
308 while { [gets $file_a line] != $eof } {
309 if [regexp "^#.*$" $line] then {
317 while { [gets $file_b line] != $eof } {
318 if [regexp "^#.*$" $line] then {
326 for { set i 0 } { $i < [llength $list_a] } { incr i } {
327 set line_a [lindex $list_a $i]
328 set line_b [lindex $list_b $i]
330 verbose "\t$file_1: $i: $line_a\n" 3
331 verbose "\t$file_2: $i: $line_b\n" 3
332 if [string compare $line_a $line_b] then {
333 verbose -log "\t$file_1: $i: $line_a\n"
334 verbose -log "\t$file_2: $i: $line_b\n"
341 if { [llength $list_a] != [llength $list_b] } {
346 if $differences<1 then {
351 # This definition is taken from an unreleased version of DejaGnu. Once
352 # that version gets released, and has been out in the world for a few
353 # months at least, it may be safe to delete this copy.
354 if ![string length [info proc prune_warnings]] {
356 # prune_warnings -- delete various system verbosities from TEXT
359 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
361 # Sites with particular verbose os's may wish to override this in site.exp.
363 proc prune_warnings { text } {
364 # This is from sun4's. Do it for all machines for now.
365 # The "\\1" is to try to preserve a "\n" but only if necessary.
366 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
368 # It might be tempting to get carried away and delete blank lines, etc.
369 # Just delete *exactly* what we're ask to, and that's it.