public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* If configure compile&link test has -shared, use -fPIC as well
@ 2005-09-05 17:20 Alexandre Oliva
  2005-09-06  1:17 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Oliva @ 2005-09-05 17:20 UTC (permalink / raw)
  To: libc-hacker

[-- Attachment #1: Type: text/plain, Size: 1234 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: glibc-configure-use-PIC-for-shared.patch --]
[-- Type: text/x-patch, Size: 3377 bytes --]

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

[-- Attachment #3: Type: text/plain, Size: 188 bytes --]


-- 
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}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: If configure compile&link test has -shared, use -fPIC as well
  2005-09-05 17:20 If configure compile&link test has -shared, use -fPIC as well Alexandre Oliva
@ 2005-09-06  1:17 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2005-09-06  1:17 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: libc-hacker

[-- Attachment #1: Type: text/plain, Size: 101 bytes --]

Applied.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-09-06  1:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-05 17:20 If configure compile&link test has -shared, use -fPIC as well Alexandre Oliva
2005-09-06  1:17 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).