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


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

Re: Fix .ctors/.dtors header configure test for bootstrapping


On Wed, 7 Mar 2012, Richard Henderson wrote:

> On 03/07/12 14:30, Joseph S. Myers wrote:
> > -  AC_TRY_LINK([], [
> > -__attribute__ ((constructor)) void ctor (void) { puts("ctor"); }
> > -__attribute__ ((destructor))  void dtor (void) { puts("dtor"); }
> > +  LIBC_TRY_LINK_STATIC([
> > +__attribute__ ((constructor)) void ctor (void) { }
> > +__attribute__ ((destructor))  void dtor (void) { }
> 
> I recommend an asm("") in those function bodies.
> 
> Gcc could legitimately eliminate those functions as empty.
> I think that's the reason for the puts hack originally.

Now testing this version.

2012-03-07  Joseph Myers  <joseph@codesourcery.com>

	* aclocal.m4 (LIBC_TRY_LINK_STATIC): New macro.
	* configure.in (libc_cv_preinit_array): Use LIBC_TRY_LINK_STATIC.
	(libc_cv_ctors_header): Likewise.  Use asm ("") instead of calling
	puts.
	* configure: Regenerated.

diff --git a/aclocal.m4 b/aclocal.m4
index dafa972..02ff9bc 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -113,3 +113,17 @@ AC_CACHE_CHECK(whether $LD is GNU ld, libc_cv_prog_ld_gnu,
 [LIBC_PROG_FOO_GNU($LD, libc_cv_prog_ld_gnu=yes, libc_cv_prog_ld_gnu=no)])
 gnu_ld=$libc_cv_prog_ld_gnu
 ])
+
+dnl Run a static link test with -nostdlib -nostartfiles.
+dnl LIBC_TRY_LINK_STATIC([code], [action-if-true], [action-if-false])
+AC_DEFUN([LIBC_TRY_LINK_STATIC],
+[cat > conftest.c <<EOF
+int _start (void) { return 0; }
+int __start (void) { return 0; }
+$1
+EOF
+AS_IF([AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -o conftest
+		       conftest.c -static -nostartfiles -nostdlib
+		       1>&AS_MESSAGE_LOG_FD])],
+      [$2], [$3])
+rm -f conftest*])
diff --git a/configure.in b/configure.in
index 7ebeba4..ee9e3d8 100644
--- a/configure.in
+++ b/configure.in
@@ -1349,24 +1349,17 @@ fi
 
 AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support,
 	       libc_cv_initfini_array, [dnl
-cat > conftest.c <<EOF
-int _start (void) { return 0; }
-int __start (void) { return 0; }
+LIBC_TRY_LINK_STATIC([
 int foo (void) { return 1; }
 int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;
-EOF
-if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -o conftest conftest.c
-		   -static -nostartfiles -nostdlib 1>&AS_MESSAGE_LOG_FD])
-then
-  if $READELF -S conftest | fgrep INIT_ARRAY > /dev/null; then
+],
+  [if $READELF -S conftest | fgrep INIT_ARRAY > /dev/null; then
     libc_cv_initfini_array=yes
   else
     libc_cv_initfini_array=no
-  fi
-else
-  libc_cv_initfini_array=no
-fi
-rm -f conftest*])
+  fi],
+  [libc_cv_initfini_array=no])
+])
 if test $libc_cv_initfini_array != yes; then
   AC_MSG_ERROR([Need linker with .init_array/.fini_array support.])
 fi
@@ -1374,9 +1367,9 @@ fi
 AC_CACHE_CHECK(whether to use .ctors/.dtors header and trailer,
 	       libc_cv_ctors_header, [dnl
   libc_cv_ctors_header=yes
-  AC_TRY_LINK([], [
-__attribute__ ((constructor)) void ctor (void) { puts("ctor"); }
-__attribute__ ((destructor))  void dtor (void) { puts("dtor"); }
+  LIBC_TRY_LINK_STATIC([
+__attribute__ ((constructor)) void ctor (void) { asm (""); }
+__attribute__ ((destructor))  void dtor (void) { asm (""); }
 ],
 	      [dnl
       AS_IF([$READELF -WS conftest$ac_exeext | $AWK '

-- 
Joseph S. Myers
joseph@codesourcery.com


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