PATCH: Use gcc to build DSO

H. J. Lu hjl@lucon.org
Fri May 16 02:29:00 GMT 2003


On Thu, May 15, 2003 at 07:24:36PM -0700, H. J. Lu wrote:
> This patch fixes DSO build. We use "ld_link $ld" to build shared
> libraries. "ld_link $ld" is for building executables. It is
> totally wrong to use it for building shared libraries.
> 
> 

I should append the real patch.


H.J.
-------------- next part --------------
2003-05-15  H.J. Lu <hongjiu.lu@intel.com>

	* config/default.exp (gcc_ld_flag): New. Make the newly built
	linker available to gcc.
	* lib/ld-lib.exp (default_ld_simple_link): Pass $gcc_ld_flag
	to gcc.

	* ld-elfvers/vers.exp: Use "ld_simple_link $CC" to build shared
	libraries.
	* ld-elfvsb/elfvsb.exp: Likewise.
	* ld-elfweak/elfweak.exp: Likewise.
	* ld-shared/shared.exp: Likewise.

	* ld-elfvers/vers.exp: Remove xfail for powerpc-*-linux*.

	* ld-elfvers/vers.exp: Use "-Wl,-rpath,." to build shared
	libraries.

--- ld/testsuite/config/default.exp.dso	2003-05-07 12:05:09.000000000 -0400
+++ ld/testsuite/config/default.exp	2003-05-15 22:07:03.000000000 -0400
@@ -60,6 +60,15 @@ if {![file isdirectory tmpdir/gas]} then
 }
 set gcc_gas_flag "-B[pwd]/tmpdir/gas/"
 
+# Make a symlink from tmpdir/ld to the linker in the build tree, so
+# that we can use a -B option to gcc to force it to use the newly
+# built linker. 
+if {![file isdirectory tmpdir/ld]} then {
+    catch "exec mkdir tmpdir/ld" status
+    catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
+}
+set gcc_ld_flag "-B[pwd]/tmpdir/ld/"
+
 # The mips64-*-linux-gnu compiler defaults to the N32 ABI after
 # installed, but to the O32 ABI in the build tree, because of some
 # specs-file hacks.  Make sure we use an ABI that is compatible with
--- ld/testsuite/ld-elfvers/vers.exp.dso	2003-05-14 02:11:14.000000000 -0400
+++ ld/testsuite/ld-elfvers/vers.exp	2003-05-15 21:53:22.000000000 -0400
@@ -581,7 +581,6 @@ proc build_vers_lib_pic { test source li
 }
 
 proc test_ldfail { test flag source execname other mapfile whyfail } {
-    global ld
     global srcdir
     global subdir
     global exec_output
@@ -617,7 +616,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_simple_link $CC $tmpdir/$execname "$tmpdir/$execname.o $other_lib $script_arg"]}     {
 	pass "$test"
 	return
     }
@@ -686,7 +685,6 @@ proc test_strip_vers_lib { test srclib l
 
 
 proc build_exec { test source execname flags solibname verexp versymexp symexp } {
-    global ld
     global srcdir
     global subdir
     global exec_output
@@ -715,7 +713,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_simple_link $CC $tmpdir/$execname "$flags $tmpdir/$execname.o $solibname_lib"]}     {
 	fail "$test"
 	return
     }
@@ -877,7 +875,7 @@ build_exec "vers16" vers16.c vers16 "" v
 # Test a weak versioned symbol.
 build_vers_lib_no_pic "vers17" vers17.c vers17 "" vers17.map vers17.ver vers17.dsym ""
 build_vers_lib_no_pic "vers18" vers18.c vers18 vers17.so vers18.map vers18.ver vers18.dsym vers18.sym
-build_exec "vers19" vers19.c vers19 "-rpath ." vers18.so vers19.ver vers19.dsym ""
+build_exec "vers19" vers19.c vers19 "-Wl,-rpath,." vers18.so vers19.ver vers19.dsym ""
 
 build_vers_lib_no_pic "vers20a" vers20.c vers20a "" vers20.map vers20a.ver vers20.dsym ""
 exec cp $tmpdir/vers20a.so $tmpdir/vers20b.so
--- ld/testsuite/ld-elfvsb/elfvsb.exp.dso	2003-05-14 02:11:14.000000000 -0400
+++ ld/testsuite/ld-elfvsb/elfvsb.exp	2003-05-15 22:07:44.000000000 -0400
@@ -91,7 +91,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_simple_link $CC $tmpdir/main "$tmpdir/main.o"] {
 	catch "exec $tmpdir/main" support_protected
       }
     }
@@ -99,7 +99,7 @@ if [istarget *-*-linux*] {
 
 # The test procedure.
 proc visibility_test { visibility progname testname main sh1 sh2 dat args } {
-    global ld
+    global CC
     global srcdir
     global subdir
     global exec_output
@@ -115,7 +115,7 @@ proc visibility_test { visibility progna
     if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
 	set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
     }
-    if {![ld_simple_link $ld $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
+    if {![ld_simple_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
 	if { [ string match $visibility "hidden_undef" ]
 	     && [regexp ".*/sh1.c.*: undefined reference to \`visibility\'" $link_output]
 	     && [regexp ".*/sh1.c.*: undefined reference to \`visibility_var\'" $link_output] } {
@@ -138,7 +138,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_simple_link $CC $tmpdir/$progname "-Wl,-rpath,$rpath $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] } {
@@ -247,10 +247,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
@@ -345,10 +341,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" ] } {
 		    setup_xfail "ia64-*-linux*"
--- ld/testsuite/ld-elfweak/elfweak.exp.dso	2003-05-14 02:11:14.000000000 -0400
+++ ld/testsuite/ld-elfweak/elfweak.exp	2003-05-15 21:57:41.000000000 -0400
@@ -270,7 +270,7 @@ proc objdump_dynsymstuff { objdump objec
 }
 
 proc build_lib {test libname objs dynsymexp} {
-    global ld
+    global CC
     global objdump
     global tmpdir
     global shared
@@ -282,7 +282,7 @@ proc build_lib {test libname objs dynsym
       set files "$files $tmpdir/$obj"
     }
 
-    if {![ld_link $ld $tmpdir/$libname.so "$shared $files"]} {
+    if {![ld_simple_link $CC $tmpdir/$libname.so "$shared $files"]} {
 	fail $test
 	return
     }
@@ -295,7 +295,7 @@ proc build_lib {test libname objs dynsym
 }
 
 proc build_exec { test execname objs flags dat dynsymexp symexp} {
-    global ld
+    global CC
     global objdump
     global tmpdir
     global shared
@@ -308,7 +308,7 @@ proc build_exec { test execname objs fla
       set files "$files $tmpdir/$obj"
     }
 
-    if {![ld_link $ld $tmpdir/$execname "$flags $files"]} {
+    if {![ld_simple_link $CC $tmpdir/$execname "$flags $files"]} {
 	fail "$test"
 	return
     }
@@ -392,7 +392,7 @@ if ![ld_compile "$CC $CFLAGS" $srcdir/$s
     return
 }
 
-if {![ld_link $ld $tmpdir/libbar.so "$shared $tmpdir/bar.o"]} {
+if {![ld_simple_link $CC $tmpdir/libbar.so "$shared $tmpdir/bar.o"]} {
     fail "ELF weak"
     return
 }
@@ -407,17 +407,17 @@ if ![ld_compile "$CC $CFLAGS $picflag" $
     return
 }
 
-if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/bar1a.c $tmpdir/bar1a.o] {
+if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1a.c $tmpdir/bar1a.o] {
     unresolved "ELF weak"
     return
 }
 
-if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/bar1b.c $tmpdir/bar1b.o] {
+if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1b.c $tmpdir/bar1b.o] {
     unresolved "ELF weak"
     return
 }
 
-if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/bar1c.c $tmpdir/bar1c.o] {
+if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1c.c $tmpdir/bar1c.o] {
     unresolved "ELF weak"
     return
 }
@@ -427,17 +427,17 @@ if ![ld_compile "$CC $CFLAGS" $srcdir/$s
     return
 }
 
-if {![ld_link $ld $tmpdir/libfoo1a.so "$shared $tmpdir/foo1a.o"]} {
+if {![ld_simple_link $CC $tmpdir/libfoo1a.so "$shared $tmpdir/foo1a.o"]} {
     fail "ELF weak"
     return
 }
 
-if {![ld_link $ld $tmpdir/libfoo1b.so "$shared $tmpdir/foo1b.o"]} {
+if {![ld_simple_link $CC $tmpdir/libfoo1b.so "$shared $tmpdir/foo1b.o"]} {
     fail "ELF weak"
     return
 }
 
-if {![ld_link $ld $tmpdir/libbar1a.so "$shared $tmpdir/bar1a.o $tmpdir/libfoo1a.so"]} {
+if {![ld_simple_link $CC $tmpdir/libbar1a.so "$shared $tmpdir/bar1a.o $tmpdir/libfoo1a.so"]} {
     fail "ELF weak"
     return
 }
@@ -448,8 +448,8 @@ build_lib "ELF DSO weak func first DSO" 
 build_lib "ELF DSO weak func last DSO" libfoo "libbar.so foo.o" dsow.dsym
 build_exec "ELF weak func first" foo "main.o bar.o" "" strong "" strong.sym
 build_exec "ELF weak func last" foo "bar.o main.o" "" strong "" strong.sym
-build_exec "ELF weak func first DSO" foo "main.o libbar.so" "-rpath ." weak weak.dsym ""
-build_exec "ELF weak func last DSO" foo "libbar.so main.o" "-rpath ." weak weak.dsym ""
+build_exec "ELF weak func first DSO" foo "main.o libbar.so" "-Wl,-rpath,." weak weak.dsym ""
+build_exec "ELF weak func last DSO" foo "libbar.so main.o" "-Wl,-rpath,." weak weak.dsym ""
 
 build_lib "ELF DSO weak data first" libfoo "bar1a.o foo1a.o" dsodata.dsym
 build_lib "ELF DSO weak data last" libfoo "foo1a.o bar1a.o" dsodata.dsym
@@ -461,7 +461,7 @@ build_exec "ELF weak data first" foo "ma
 build_exec "ELF weak data last" foo "foo1a.o main1.o bar1a.o" "" strongdata "" strongdata.sym
 build_exec "ELF weak data first common" foo "main1.o bar1a.o foo1b.o" "" strongdata "" strongcomm.sym
 build_exec "ELF weak data last common" foo "foo1b.o main1.o bar1a.o" "" strongdata "" strongcomm.sym
-build_exec "ELF weak data first DSO" foo "main1.o libbar1a.so libfoo1a.so" "-rpath ." weakdata weakdata.dsym ""
-build_exec "ELF weak data last DSO" foo "libfoo1a.so main1.o libbar1a.so" "-rpath ." weakdata weakdata.dsym ""
-build_exec "ELF weak data first DSO common" foo "main1.o libbar1a.so libfoo1b.so" "-rpath ." weakdata weakdata.dsym ""
-build_exec "ELF weak data last DSO common" foo "libfoo1b.so main1.o libbar1a.so" "-rpath ." weakdata weakdata.dsym ""
+build_exec "ELF weak data first DSO" foo "main1.o libbar1a.so libfoo1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
+build_exec "ELF weak data last DSO" foo "libfoo1a.so main1.o libbar1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
+build_exec "ELF weak data first DSO common" foo "main1.o libbar1a.so libfoo1b.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
+build_exec "ELF weak data last DSO common" foo "libfoo1b.so main1.o libbar1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
--- ld/testsuite/ld-shared/shared.exp.dso	2003-05-14 02:11:15.000000000 -0400
+++ ld/testsuite/ld-shared/shared.exp	2003-05-15 21:53:22.000000000 -0400
@@ -95,7 +95,7 @@ if { [istarget rs6000*-*-aix*] || [istar
 
 # The test procedure.
 proc shared_test { progname testname main sh1 sh2 dat args } {
-    global ld
+    global CC
     global srcdir
     global subdir
     global exec_output
@@ -110,7 +110,7 @@ proc shared_test { progname testname mai
     if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
 	set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
     }
-    if {![ld_simple_link $ld $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
+    if {![ld_simple_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
         fail "$testname"
     	return
     }
@@ -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_simple_link $CC $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] {
     	fail "$testname"
     	return
     }
--- ld/testsuite/lib/ld-lib.exp.dso	2003-04-25 11:46:05.000000000 -0400
+++ ld/testsuite/lib/ld-lib.exp	2003-05-15 21:53:22.000000000 -0400
@@ -154,6 +154,7 @@ proc default_ld_link { ld target objects
 proc default_ld_simple_link { ld target objects } {
     global host_triplet
     global link_output
+    global gcc_ld_flag
 
     if { [which $ld] == 0 } then {
 	perror "$ld does not exist"
@@ -166,6 +167,13 @@ proc default_ld_simple_link { ld target 
 	set flags ""
     }
 
+    # If we are compiling with gcc, we want to add gcc_ld_flag to
+    # flags.  Rather than determine this in some complex way, we guess
+    # based on the name of the compiler.
+    if {[string match "*gcc*" $ld] || [string match "*++*" $ld]} then {
+	set flags "$gcc_ld_flag $flags"
+    }
+
     verbose -log "$ld $flags -o $target $objects"
 
     catch "exec $ld $flags -o $target $objects" link_output


More information about the Binutils mailing list