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, Roland McGrath wrote:

> Again, I'd prefer it without puts.
> But otherwise seems OKish.
> 
> However, I'm inclined to say we should define a macro for this type of test
> rather than repeating the boilerplate.  The macro would do the _start magic
> and the compile+link command that's common between the two tests.

I am testing this patch which creates and uses a LIBC_TRY_LINK_STATIC
macro for configure tests doing a -static link without standard
libraries.

(There are quite a lot of tests doing -shared links without standard
libraries; many of them define _start, although that shouldn't be
needed for -shared links.  It may make sense to define a separate
macro for those.  Unlike LIBC_TRY_LINK_STATIC, that macro would need
an argument for linker options since those tests are generally testing
with different linker options in each test to see if those options
work.)

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.  Do not call 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..dcd85cb 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) { }
+__attribute__ ((destructor))  void dtor (void) { }
 ],
 	      [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]