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 # Check to see if ld is being invoked with a non-endian output format
48 proc is_endian_output_format { object_flags } {
50 if {[string match "*-oformat binary*" $object_flags] || \
51 [string match "*-oformat ieee*" $object_flags] || \
52 [string match "*-oformat ihex*" $object_flags] || \
53 [string match "*-oformat netbsd-core*" $object_flags] || \
54 [string match "*-oformat srec*" $object_flags] || \
55 [string match "*-oformat tekhex*" $object_flags] || \
56 [string match "*-oformat trad-core*" $object_flags] } then {
63 # Look for big-endian or little-endian switches in the multlib
64 # options and translate these into a -EB or -EL switch. Note
65 # we cannot rely upon proc process_multilib_options to do this
66 # for us because for some targets the compiler does not support
67 # -EB/-EL but it does support -mbig-endian/-mlittle-endian, and
68 # the site.exp file will include the switch "-mbig-endian"
69 # (rather than "big-endian") which is not detected by proc
70 # process_multilib_options.
72 proc big_or_little_endian {} {
74 if [board_info [target_info name] exists multilib_flags] {
75 set tmp_flags " [board_info [target_info name] multilib_flags]";
77 foreach x $tmp_flags {
79 {*big*endian eb EB -eb -EB} {
83 {*little*endian el EL -el -EL} {
97 # link a program using ld
99 proc default_ld_link { ld target objects } {
107 set objs "$HOSTING_CRT0 $objects"
108 set libs "$LIBS $HOSTING_LIBS"
110 if { [which $ld] == 0 } then {
111 perror "$ld does not exist"
115 if [is_endian_output_format $objects] then {
116 set flags [big_or_little_endian]
120 verbose -log "$ld $HOSTING_EMU $flags -o $target $objs $libs"
122 catch "exec $ld $HOSTING_EMU $flags -o $target $objs $libs" link_output
123 set exec_output [prune_warnings $link_output]
124 if [string match "" $link_output] then {
127 verbose -log "$link_output"
133 # default_ld_simple_link
134 # link a program using ld, without including any libraries
136 proc default_ld_simple_link { ld target objects } {
140 if { [which $ld] == 0 } then {
141 perror "$ld does not exist"
145 if [is_endian_output_format $objects] then {
146 set flags [big_or_little_endian]
151 verbose -log "$ld $flags -o $target $objects"
153 catch "exec $ld $flags -o $target $objects" link_output
154 set exec_output [prune_warnings $link_output]
156 # We don't care if we get a warning about a non-existent start
157 # symbol, since the default linker script might use ENTRY.
158 regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
160 if [string match "" $exec_output] then {
163 verbose -log "$exec_output"
170 # compile an object using cc
172 proc default_ld_compile { cc source object } {
180 if {[llength $cc_prog] > 1} then {
181 set cc_prog [lindex $cc_prog 0]
183 if {[which $cc_prog] == 0} then {
184 perror "$cc_prog does not exist"
188 catch "exec rm -f $object" exec_output
190 set flags "-I$srcdir/$subdir $CFLAGS"
192 # If we are compiling with gcc, we want to add gcc_gas_flag to
193 # flags. Rather than determine this in some complex way, we guess
194 # based on the name of the compiler.
195 if {[string match "*gcc*" $cc] || [string match "*++*" $cc]} then {
196 set flags "$gcc_gas_flag $flags"
199 if [board_info [target_info name] exists multilib_flags] {
200 append flags " [board_info [target_info name] multilib_flags]";
203 verbose -log "$cc $flags -c $source -o $object"
205 catch "exec $cc $flags -c $source -o $object" exec_output
206 set exec_output [prune_warnings $exec_output]
207 if [string match "" $exec_output] then {
208 if {![file exists $object]} then {
209 regexp ".*/(\[^/\]*)$" $source all dobj
210 regsub "\\.c" $dobj ".o" realobj
211 verbose "looking for $realobj"
212 if {[file exists $realobj]} then {
213 verbose -log "mv $realobj $object"
214 catch "exec mv $realobj $object" exec_output
215 set exec_output [prune_warnings $exec_output]
216 if {![string match "" $exec_output]} then {
217 verbose -log "$exec_output"
218 perror "could not move $realobj to $object"
222 perror "$object not found after compilation"
228 verbose -log "$exec_output"
229 perror "$source: compilation failed"
235 # default_ld_assemble
238 proc default_ld_assemble { as source object } {
242 if {[which $as] == 0} then {
243 perror "$as does not exist"
247 if ![info exists ASFLAGS] { set ASFLAGS "" }
249 set flags [big_or_little_endian]
251 verbose -log "$as $flags $ASFLAGS -o $object $source"
253 catch "exec $as $flags $ASFLAGS -o $object $source" exec_output
254 set exec_output [prune_warnings $exec_output]
255 if [string match "" $exec_output] then {
258 verbose -log "$exec_output"
259 perror "$source: assembly failed"
266 # run nm on a file, putting the result in the array nm_output
268 proc default_ld_nm { nm object } {
273 if {[which $nm] == 0} then {
274 perror "$nm does not exist"
278 if {[info exists nm_output]} {
282 if ![info exists NMFLAGS] { set NMFLAGS "" }
284 verbose -log "$nm $NMFLAGS $object >tmpdir/nm.out"
286 catch "exec $nm $NMFLAGS $object >tmpdir/nm.out" exec_output
287 set exec_output [prune_warnings $exec_output]
288 if [string match "" $exec_output] then {
289 set file [open tmpdir/nm.out r]
290 while { [gets $file line] != -1 } {
292 if [regexp "^(\[0-9a-fA-F\]+) \[a-zA-Z0-9\] (.+)$" $line whole value name] {
293 set name [string trimleft $name "_"]
294 verbose "Setting nm_output($name) to 0x$value" 2
295 set nm_output($name) 0x$value
301 verbose -log "$exec_output"
302 perror "$object: nm failed"
309 # compares two files line-by-line
310 # returns differences if exist
311 # returns null if file(s) cannot be opened
313 proc simple_diff { file_1 file_2 } {
319 if [file exists $file_1] then {
320 set file_a [open $file_1 r]
322 warning "$file_1 doesn't exist"
326 if [file exists $file_2] then {
327 set file_b [open $file_2 r]
329 fail "$file_2 doesn't exist"
333 verbose "# Diff'ing: $file_1 $file_2\n" 2
335 while { [gets $file_a line] != $eof } {
336 if [regexp "^#.*$" $line] then {
344 while { [gets $file_b line] != $eof } {
345 if [regexp "^#.*$" $line] then {
353 for { set i 0 } { $i < [llength $list_a] } { incr i } {
354 set line_a [lindex $list_a $i]
355 set line_b [lindex $list_b $i]
357 verbose "\t$file_1: $i: $line_a\n" 3
358 verbose "\t$file_2: $i: $line_b\n" 3
359 if [string compare $line_a $line_b] then {
360 verbose -log "\t$file_1: $i: $line_a\n"
361 verbose -log "\t$file_2: $i: $line_b\n"
368 if { [llength $list_a] != [llength $list_b] } {
373 if $differences<1 then {
378 # This definition is taken from an unreleased version of DejaGnu. Once
379 # that version gets released, and has been out in the world for a few
380 # months at least, it may be safe to delete this copy.
381 if ![string length [info proc prune_warnings]] {
383 # prune_warnings -- delete various system verbosities from TEXT
386 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
388 # Sites with particular verbose os's may wish to override this in site.exp.
390 proc prune_warnings { text } {
391 # This is from sun4's. Do it for all machines for now.
392 # The "\\1" is to try to preserve a "\n" but only if necessary.
393 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
395 # It might be tempting to get carried away and delete blank lines, etc.
396 # Just delete *exactly* what we're ask to, and that's it.