This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
use gcc -### in ld tests
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sources dot redhat dot com
- Date: Tue, 6 May 2003 19:42:26 +0930
- Subject: use gcc -### in ld tests
Some of the ld elfweak tests fail for powerpc because ld is linking
in the wrong crt* files for use in a shared lib. This is an attempt
to fix the problem by using gcc -###. Would one of the testsuite
gurus like to review it for me, please?
* lib/ld-lib.exp (default_ld_link): Use "gcc -###" to choose
correct crt* and libs.
Index: ld/testsuite/lib/ld-lib.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/lib/ld-lib.exp,v
retrieving revision 1.20
diff -u -p -r1.20 ld-lib.exp
--- ld/testsuite/lib/ld-lib.exp 25 Apr 2003 14:23:31 -0000 1.20
+++ ld/testsuite/lib/ld-lib.exp 6 May 2003 10:09:13 -0000
@@ -115,6 +115,8 @@ proc big_or_little_endian {} {
# link a program using ld
#
proc default_ld_link { ld target objects } {
+ global CC
+ global CFLAGS
global HOSTING_EMU
global HOSTING_CRT0
global HOSTING_LIBS
@@ -122,9 +124,6 @@ proc default_ld_link { ld target objects
global host_triplet
global link_output
- set objs "$HOSTING_CRT0 $objects"
- set libs "$LIBS $HOSTING_LIBS"
-
if { [which $ld] == 0 } then {
perror "$ld does not exist"
return 0
@@ -135,9 +134,41 @@ proc default_ld_link { ld target objects
} else {
set flags ""
}
- verbose -log "$ld $HOSTING_EMU $flags -o $target $objs $libs"
- catch "exec $ld $HOSTING_EMU $flags -o $target $objs $libs" link_output
+ # Try to use gcc -### to set up the correct crt* and libs
+ set cc "$CC $CFLAGS"
+ if {[string match "*gcc*" $cc]} then {
+ catch "exec $cc -\#\#\#" args
+ if { [string match "*illegal option*" $args] \
+ || [string match "*option ignored*" $args] \
+ || [string match "*unrecognized option*" $args] } then {
+ set args ""
+ } else {
+ catch "exec $cc -\#\#\# $flags -o $target $objects" args
+ # gcc -### is like gcc -v, but doesn't execute the commands
+ # and wraps individual options in quotes. Skip over config
+ # and version info until we get to the ld/collect2 command.
+ set qq [string first "\n \"" $args]
+ if { $qq != -1 } then {
+ incr qq 3
+ # Skip the command.
+ set qq [string first "\"" $args $qq]
+ incr qq 2
+ # Use the rest of the line as our ld args.
+ set ee [string first "\n" $args $qq]
+ set args [string range $args $qq $ee]
+ } else {
+ set args ""
+ }
+ }
+ }
+ # Otherwise default to something that might work sometimes
+ if {[string equal $args ""]} then {
+ set args "$flags -o $target $HOSTING_CRT0 $objects $LIBS $HOSTING_LIBS"
+ }
+
+ verbose -log "$ld $HOSTING_EMU $args"
+ catch "exec $ld $HOSTING_EMU $args" link_output
set exec_output [prune_warnings $link_output]
if [string match "" $link_output] then {
return 1
--
Alan Modra
IBM OzLabs - Linux Technology Centre