This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: 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, 06 May 2003 22:01:43 +0930
- Subject: Re: use gcc -### in ld tests
- References: <20030506101226.GG924@bubble.sa.bigpond.net.au>
On Tue, May 06, 2003 at 07:42:26PM +0930, Alan Modra wrote:
> 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?
This one works.
* lib/ld-lib.exp (default_ld_link): Add ldflags arg. Use
"gcc -###" to choose correct crt* and libs.
* config/default.exp (ld_link): Add ldflags arg.
* ld-bootstrap/bootstrap.exp: Adjust ld_link calls.
* ld-cdtest/cdtest.exp: Likewise.
* ld-elfvers/vers.exp: Likewise.
* ld-elfvsb/elfvsb.exp: Likewise.
* ld-elfweak/elfweak.exp: Likewise.
* ld-shared/shared.exp: Likewise.
* ld-elfvsb/elfvsb.exp: Remove some xfails for powerpc-linux.
Index: ld/testsuite/config/default.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/config/default.exp,v
retrieving revision 1.4
diff -u -p -r1.4 default.exp
--- ld/testsuite/config/default.exp 24 Jul 2001 11:07:06 -0000 1.4
+++ ld/testsuite/config/default.exp 6 May 2003 12:17:00 -0000
@@ -126,8 +126,8 @@ proc ld_relocate { ld target objects } {
# ld_link
# link a program using ld
#
-proc ld_link { ld target objects } {
- default_ld_link $ld $target $objects
+proc ld_link { ld ldflags target objects } {
+ default_ld_link $ld $ldflags $target $objects
}
#
Index: ld/testsuite/ld-bootstrap/bootstrap.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-bootstrap/bootstrap.exp,v
retrieving revision 1.9
diff -u -p -r1.9 bootstrap.exp
--- ld/testsuite/ld-bootstrap/bootstrap.exp 30 May 2002 21:39:41 -0000 1.9
+++ ld/testsuite/ld-bootstrap/bootstrap.exp 6 May 2003 12:17:00 -0000
@@ -86,7 +86,7 @@ foreach flags {"" "strip" "--static" "--
setup_xfail "mips*-*-irix5*"
}
- if ![ld_link $ld tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY"] {
+ if ![ld_link $ld $flags tmpdir/ld1 "tmpdir/ld-partial.o $BFDLIB $LIBIBERTY"] {
fail $testname
continue
}
@@ -101,12 +101,12 @@ foreach flags {"" "strip" "--static" "--
}
}
- if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
+ if ![ld_link tmpdir/ld1 $flags tmpdir/ld2 "$OFILES $BFDLIB $LIBIBERTY"] {
fail $testname
continue
}
- if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
+ if ![ld_link tmpdir/ld2 $flags tmpdir/ld3 "$OFILES $BFDLIB $LIBIBERTY"] {
fail $testname
continue
}
@@ -117,7 +117,7 @@ foreach flags {"" "strip" "--static" "--
# On ia64, tmpdir/ld2 != tmpdir/ld3 is normal since they are
# generated by different linkers, tmpdir/ld1 and tmpdir/ld2.
# So we rebuild tmpdir/ld2 with tmpdir/ld3.
- if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
+ if ![ld_link tmpdir/ld3 $flags tmpdir/ld2 "$OFILES $BFDLIB $LIBIBERTY"] {
fail $testname
continue
}
@@ -127,7 +127,7 @@ foreach flags {"" "strip" "--static" "--
# On Linux/mips, tmpdir/ld2 != tmpdir/ld3 is normal since
# they are generated by different linkers, tmpdir/ld1 and
# tmpdir/ld2. So we rebuild tmpdir/ld2 with tmpdir/ld3.
- if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
+ if ![ld_link tmpdir/ld3 $flags tmpdir/ld2 "$OFILES $BFDLIB $LIBIBERTY"] {
fail $testname
continue
}
Index: ld/testsuite/ld-cdtest/cdtest.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-cdtest/cdtest.exp,v
retrieving revision 1.3
diff -u -p -r1.3 cdtest.exp
--- ld/testsuite/ld-cdtest/cdtest.exp 1 Aug 2001 14:37:47 -0000 1.3
+++ ld/testsuite/ld-cdtest/cdtest.exp 6 May 2003 12:17:00 -0000
@@ -45,7 +45,7 @@ if { ![ld_compile "$CXX $CXXFLAGS -fgn
set expected_output "$srcdir/$subdir/cdtest.dat"
-if ![ld_link $ld tmpdir/cdtest {tmpdir/cdtest-foo.o tmpdir/cdtest-bar.o tmpdir/cdtest-main.o}] {
+if ![ld_link $ld "" tmpdir/cdtest {tmpdir/cdtest-foo.o tmpdir/cdtest-bar.o tmpdir/cdtest-main.o}] {
fail $test1
} else {
send_log "tmpdir/cdtest >tmpdir/cdtest.out\n"
@@ -92,7 +92,7 @@ if ![ld_link $ld tmpdir/cdtest {tmpdir/c
if ![ld_relocate $ld tmpdir/cdtest.o {-Ur tmpdir/cdtest-foo.o tmpdir/cdtest-bar.o tmpdir/cdtest-main.o}] {
fail $test2
} else {
- if ![ld_link $ld tmpdir/cdtest tmpdir/cdtest.o] {
+ if ![ld_link $ld "" tmpdir/cdtest tmpdir/cdtest.o] {
fail $test2
} else {
send_log "tmpdir/cdtest >tmpdir/cdtest.out\n"
Index: ld/testsuite/ld-elfvers/vers.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elfvers/vers.exp,v
retrieving revision 1.25
diff -u -p -r1.25 vers.exp
--- ld/testsuite/ld-elfvers/vers.exp 3 May 2003 16:51:05 -0000 1.25
+++ ld/testsuite/ld-elfvers/vers.exp 6 May 2003 12:17:01 -0000
@@ -607,7 +607,7 @@ proc test_ldfail { test flag source exec
set script_arg "$script $srcdir/$subdir/$mapfile"
}
- if {![ld_link $ld $tmpdir/$execname "$tmpdir/$execname.o $other_lib $script_arg"]} {
+ if {![ld_link $ld $script_arg $tmpdir/$execname "$tmpdir/$execname.o $other_lib"]} {
pass "$test"
return
}
@@ -705,7 +705,7 @@ proc build_exec { test source execname f
set solibname_lib $tmpdir/$solibname
}
- if {![ld_link $ld $tmpdir/$execname "$flags $tmpdir/$execname.o $solibname_lib"]} {
+ if {![ld_link $ld $flags $tmpdir/$execname "$tmpdir/$execname.o $solibname_lib"]} {
fail "$test"
return
}
Index: ld/testsuite/ld-elfvsb/elfvsb.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elfvsb/elfvsb.exp,v
retrieving revision 1.16
diff -u -p -r1.16 elfvsb.exp
--- ld/testsuite/ld-elfvsb/elfvsb.exp 28 Apr 2003 03:31:36 -0000 1.16
+++ ld/testsuite/ld-elfvsb/elfvsb.exp 6 May 2003 12:17:01 -0000
@@ -90,7 +90,7 @@ set support_protected "no"
if [istarget *-*-linux*] {
if [ld_compile "$CC -g $CFLAGS -DPROTECTED_CHECK" $srcdir/$subdir/main.c $tmpdir/main.o] {
- if [ld_link $ld $tmpdir/main "$tmpdir/main.o"] {
+ if [ld_link $ld "" $tmpdir/main $tmpdir/main.o] {
catch "exec $tmpdir/main" support_protected
}
}
@@ -137,7 +137,7 @@ proc visibility_test { visibility progna
if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
set rpath /lib:$tmpdir
}
- if ![ld_link $ld $tmpdir/$progname "-rpath $rpath $tmpdir/$main $tmpdir/$progname.so"] {
+ if ![ld_link $ld "-rpath $rpath" $tmpdir/$progname "$tmpdir/$main $tmpdir/$progname.so"] {
if { [ string match $visibility "hidden" ]
&& [regexp ".*/main.c.*: undefined reference to \`visibility\'" $link_output]
&& [regexp ".*/main.c.*: undefined reference to \`visibility_var\'" $link_output] } {
@@ -246,10 +246,6 @@ proc visibility_run {visibility} {
} else {
setup_xfail "*-*-sunos4*"
}
- if { [ string match $visibility "hidden_weak" ]
- || [ string match $visibility "protected_weak" ] } {
- setup_xfail "powerpc-*-linux*"
- }
# Non-pic code uses name binding rules for applications to
# reference variables by gp-relative relocs, which can't be
@@ -337,10 +333,6 @@ proc visibility_run {visibility} {
}
} else {
setup_xfail "*-*-sunos4*"
- }
- if { [ string match $visibility "hidden_weak" ]
- || [ string match $visibility "protected_weak" ] } {
- setup_xfail "powerpc-*-linux*"
}
if { ![ string match $visibility "hidden_undef" ]
&& ![ string match $visibility "protected_undef" ] } {
Index: ld/testsuite/ld-elfweak/elfweak.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elfweak/elfweak.exp,v
retrieving revision 1.5
diff -u -p -r1.5 elfweak.exp
--- ld/testsuite/ld-elfweak/elfweak.exp 5 May 2003 03:33:09 -0000 1.5
+++ ld/testsuite/ld-elfweak/elfweak.exp 6 May 2003 12:17:01 -0000
@@ -281,7 +281,7 @@ proc build_lib {test libname objs dynsym
set files "$files $tmpdir/$obj"
}
- if {![ld_link $ld $tmpdir/$libname.so "$shared $files"]} {
+ if {![ld_link $ld $shared $tmpdir/$libname.so $files]} {
fail $test
return
}
@@ -307,7 +307,7 @@ proc build_exec { test execname objs fla
set files "$files $tmpdir/$obj"
}
- if {![ld_link $ld $tmpdir/$execname "$flags $files"]} {
+ if {![ld_link $ld $flags $tmpdir/$execname $files]} {
fail "$test"
return
}
@@ -391,7 +391,7 @@ if ![ld_compile "$CC $CFLAGS" $srcdir/$s
return
}
-if {![ld_link $ld $tmpdir/libbar.so "$shared $tmpdir/bar.o"]} {
+if {![ld_link $ld $shared $tmpdir/libbar.so $tmpdir/bar.o]} {
fail "ELF weak"
return
}
@@ -426,17 +426,17 @@ if ![ld_compile "$CC $CFLAGS" $srcdir/$s
return
}
-if {![ld_link $ld $tmpdir/libfoo1a.so "$shared $tmpdir/foo1a.o"]} {
+if {![ld_link $ld $shared $tmpdir/libfoo1a.so $tmpdir/foo1a.o]} {
fail "ELF weak"
return
}
-if {![ld_link $ld $tmpdir/libfoo1b.so "$shared $tmpdir/foo1b.o"]} {
+if {![ld_link $ld $shared $tmpdir/libfoo1b.so $tmpdir/foo1b.o]} {
fail "ELF weak"
return
}
-if {![ld_link $ld $tmpdir/libbar1a.so "$shared $tmpdir/bar1a.o $tmpdir/libfoo1a.so"]} {
+if {![ld_link $ld $shared $tmpdir/libbar1a.so "$tmpdir/bar1a.o $tmpdir/libfoo1a.so"]} {
fail "ELF weak"
return
}
Index: ld/testsuite/ld-shared/shared.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-shared/shared.exp,v
retrieving revision 1.14
diff -u -p -r1.14 shared.exp
--- ld/testsuite/ld-shared/shared.exp 13 Feb 2003 22:14:11 -0000 1.14
+++ ld/testsuite/ld-shared/shared.exp 6 May 2003 12:17:02 -0000
@@ -123,7 +123,7 @@ proc shared_test { progname testname mai
if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
set rpath /lib:$tmpdir
}
- if ![ld_link $ld $tmpdir/$progname "-rpath $rpath $tmpdir/$main $tmpdir/$progname.so"] {
+ if ![ld_link $ld "-rpath $rpath" $tmpdir/$progname "$tmpdir/$main $tmpdir/$progname.so"] {
fail "$testname"
return
}
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 12:17:03 -0000
@@ -114,7 +114,9 @@ proc big_or_little_endian {} {
# default_ld_link
# link a program using ld
#
-proc default_ld_link { ld target objects } {
+proc default_ld_link { ld ldflags 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,52 @@ 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 {
+ set xf $flags
+ if {[string match "*--shared*" $ldflags]} then {
+ set xf "$xf --shared"
+ }
+ if {[string match "*--static*" $ldflags]} then {
+ set xf "$xf --static"
+ }
+ catch "exec $cc -\#\#\# $xf -o $target $objects" args
+ if { [string match "*illegal option*" $args] \
+ || [string match "*option ignored*" $args] \
+ || [string match "*unrecognized option*" $args] } then {
+ set args ""
+ } else {
+ # 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]
+ # Find where -o went, and put $ldflags there.
+ set qq [string first " \"-o\"" $args]
+ set a1 [string range $args 0 $qq]
+ set a2 [string range $args $qq end]
+ set args "$a1$ldflags$a2"
+ } else {
+ set args ""
+ }
+ }
+ }
+ # Otherwise default to something that might work sometimes
+ if {[string equal $args ""]} then {
+ set args "$flags -o $target $HOSTING_CRT0 $ldflags $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