This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

If configure compile&link test has -shared, use -fPIC as well


My x86_64-*-linux-gnu build of glibc wasn't passing all tests.  One of
the reason for failures was that the test for --as-needed as broken:
it compiled a source file without -fPIC, then attempted to include it
in a shared library.  The relocations emitted in the eh_frame and
debugging sections caused the file to be rejected by the linker.  A
number of other tests that used to fail because of this mistake pass
after installing the following patch.

Please check it in.  I haven't included the changes autoconf made to
the configure script, only configure.in.


For the record, the failure mode was that tests such as tst-cancelx4
aborted.  That was because the main executable ended up linked with
libgcc_eh.a, taking a number of functions from it, whereas libpthread
dlopen()ed libgcc_s.so.1 to obtain such functions for thread
cancellation.  The shared-library copy initialized its dwarf reg sizes
table correctly, per libpthread's request, whereas the other didn't
get it initialized at all.  However, the dynamic loader resolved the
personality function in the main executable to the copy in the main
executable, and that called _Unwind_SetGR in the main executable as
well, thus using the uninitialized table and abort()ing.

Index: ChangeLog
2005-09-05  Alexandre Oliva  <aoliva@redhat.com>

	* configure.in: Compile source test file with -fPIC for -shared.
	* configure: Rebuilt.

Index: configure.in
===================================================================
RCS file: /cvs/glibc/libc/configure.in,v
retrieving revision 1.442
diff -u -p -r1.442 configure.in
--- configure.in 19 Jul 2005 15:34:30 -0000 1.442
+++ configure.in 5 Sep 2005 17:07:31 -0000
@@ -1238,7 +1238,7 @@ EOF
 		 libc_cv_have_sdata_section,
 		 [echo "int i;" > conftest.c
 		  libc_cv_have_sdata_section=no
-		  if ${CC-cc} $LDFLAGS -shared -Wl,--verbose conftest.c -o conftest.so 2>&1 \
+		  if ${CC-cc} $LDFLAGS -fPIC -shared -Wl,--verbose conftest.c -o conftest.so 2>&1 \
 		     | grep '\.sdata' >/dev/null; then
 		    libc_cv_have_sdata_section=yes
 		  fi
@@ -1297,7 +1297,7 @@ EOF
 int _start (void) { return 42; }
 EOF
   if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
-		     -shared -o conftest.so conftest.c
+		     -fPIC -shared -o conftest.so conftest.c
 		     -nostartfiles -nostdlib
 		     -Wl,--enable-new-dtags,-z,nodelete 1>&AS_MESSAGE_LOG_FD])
   then
@@ -1314,7 +1314,7 @@ EOF
 int _start (void) { return 42; }
 EOF
   if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
-			-shared -o conftest.so conftest.c
+			-fPIC -shared -o conftest.so conftest.c
 			-nostartfiles -nostdlib
 			-Wl,--enable-new-dtags,-z,nodlopen 1>&AS_MESSAGE_LOG_FD])
   then
@@ -1331,7 +1331,7 @@ EOF
 int _start (void) { return 42; }
 EOF
   if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
-			-shared -o conftest.so conftest.c
+			-fPIC -shared -o conftest.so conftest.c
 			-nostartfiles -nostdlib
 			-Wl,--enable-new-dtags,-z,initfirst 1>&AS_MESSAGE_LOG_FD])
   then
@@ -1363,7 +1363,7 @@ EOF
 int _start (void) { return 42; }
 EOF
   if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
-			      -shared -o conftest.so conftest.c
+			      -fPIC -shared -o conftest.so conftest.c
 			      -Wl,-Bgroup -nostdlib 1>&AS_MESSAGE_LOG_FD])
   then
     libc_cv_Bgroup=yes
@@ -1380,7 +1380,7 @@ int main (void) { return 0; }
 EOF
 changequote(,)dnl
   libc_cv_libgcc_s_suffix=`${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
-			   -shared -shared-libgcc -o conftest.so \
+			   -fPIC -shared -shared-libgcc -o conftest.so \
 			   conftest.c -v 2>&1 >/dev/null \
 			   | sed -n 's/^.* -lgcc_s\([^ ]*\) .*$/\1/p'`
 changequote([,])dnl
@@ -1393,7 +1393,7 @@ changequote([,])dnl
 int main (void) { return 0; }
 EOF
   if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
-			      -shared -o conftest.so conftest.c
+			      -fPIC -shared -o conftest.so conftest.c
 			      -lgcc_s$libc_cv_libgcc_s_suffix -Wl,--as-needed
 			      -nostdlib 1>&AS_MESSAGE_LOG_FD])
   then
@@ -1434,7 +1434,7 @@ extern int mumble;
 int foo (void) { return bar (mumble); }
 EOF
   if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
-			-shared -o conftest.so conftest.c
+			-fPIC -shared -o conftest.so conftest.c
 			-nostdlib -nostartfiles
 			-Wl,-z,combreloc 1>&AS_MESSAGE_LOG_FD])
   then
@@ -1463,7 +1463,7 @@ dnl look for a section named .rel.dyn.
 int _start (void) { return 42; }
 EOF
   if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
-			      -shared -o conftest.so conftest.c
+			      -fPIC -shared -o conftest.so conftest.c
 			      -Wl,-z,execstack -nostdlib
 			      1>&AS_MESSAGE_LOG_FD])
   then
-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]