summary refs log tree commit diff
diff options
context:
space:
mode:
authorRoland McGrath <roland@hack.frob.com>2011-07-09 14:41:39 -0700
committerRoland McGrath <roland@hack.frob.com>2011-07-09 14:41:39 -0700
commit113ddea44742d006d7a910a0707106c7defcfd9b (patch)
treed27e74deae49fc9dc8eb8f51af35363f958925b6
parent574920b446870648623a85e00dd8f3ca9f482c0e (diff)
downloadglibc-113ddea44742d006d7a910a0707106c7defcfd9b.tar.gz
glibc-113ddea44742d006d7a910a0707106c7defcfd9b.tar.xz
glibc-113ddea44742d006d7a910a0707106c7defcfd9b.zip
Use an empirical check for .ctors/.dtors -> .init_array/.fini_array magic.
-rw-r--r--ChangeLog4
-rwxr-xr-xconfigure51
-rw-r--r--configure.in28
3 files changed, 67 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 78ab917840..b2d282f9dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-07-09  Roland McGrath  <roland@hack.frob.com>
 
+	* configure.in (.ctors/.dtors header and trailer check):
+	Use an empirical test on a built program.
+	* configure: Regenerated.
+
 	* configure.in (-z relro check): Use an empirical test on a built DSO.
 	Detect, but do not require, on ia64.
 	* configure: Regenerated.
diff --git a/configure b/configure
index 252f637466..ffeb89057f 100755
--- a/configure
+++ b/configure
@@ -6217,20 +6217,49 @@ $as_echo_n "checking whether to use .ctors/.dtors header and trailer... " >&6; }
 if ${libc_cv_ctors_header+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-    if { ac_try='${CC-cc} -Wl,--verbose 2>&1|grep SORT_BY_INIT_PRIORITY 1>&5'
-  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }; then
-    libc_cv_ctors_header=no
-  else
-    libc_cv_ctors_header=yes
-  fi
+      libc_cv_ctors_header=yes
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+__attribute__ ((constructor)) void ctor (void) { puts("ctor"); }
+__attribute__ ((destructor))  void dtor (void) { puts("dtor"); }
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+        if $READELF -WS conftest$ac_exeext | $AWK '
+        { gsub(/\[ */, "[") }
+	$2 == ".ctors" || $2 == ".dtors" {
+	  size = strtonum("0x" $6)
+	  align = strtonum("0x" $NF)
+	  seen[$2] = 1
+	  stub[$2] = size == align * 2
+        }
+	END {
+	  ctors_ok = !seen[".ctors"] || stub[".ctors"]
+	  dtors_ok = !seen[".dtors"] || stub[".dtors"]
+	  exit ((ctors_ok && dtors_ok) ? 0 : 1)
+	}
+      '; then :
+  libc_cv_ctors_header=no
+fi
+
+else
+        as_fn_error $? "missing __attribute__ ((constructor)) support??" "$LINENO" 5
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_ctors_header" >&5
 $as_echo "$libc_cv_ctors_header" >&6; }
-
   if test $libc_cv_ctors_header = no; then
     $as_echo "#define NO_CTORS_DTORS_SECTIONS 1" >>confdefs.h
 
diff --git a/configure.in b/configure.in
index e9464d89e6..e18b343416 100644
--- a/configure.in
+++ b/configure.in
@@ -1486,12 +1486,30 @@ EOF
 
   AC_CACHE_CHECK(whether to use .ctors/.dtors header and trailer,
 		 libc_cv_ctors_header, [dnl
-  if AC_TRY_COMMAND([${CC-cc} -Wl,--verbose 2>&1|grep SORT_BY_INIT_PRIORITY 1>&AS_MESSAGE_LOG_FD]); then
-    libc_cv_ctors_header=no
-  else
     libc_cv_ctors_header=yes
-  fi])
-
+    AC_TRY_LINK([], [
+__attribute__ ((constructor)) void ctor (void) { puts("ctor"); }
+__attribute__ ((destructor))  void dtor (void) { puts("dtor"); }
+],
+		[dnl
+      AS_IF([$READELF -WS conftest$ac_exeext | $AWK '
+        { gsub(/\@<:@ */, "@<:@") }
+	$2 == ".ctors" || $2 == ".dtors" {
+	  size = strtonum("0x" $6)
+	  align = strtonum("0x" $NF)
+	  seen@<:@$2@:>@ = 1
+	  stub@<:@$2@:>@ = size == align * 2
+        }
+	END {
+	  ctors_ok = !seen@<:@".ctors"@:>@ || stub@<:@".ctors"@:>@
+	  dtors_ok = !seen@<:@".dtors"@:>@ || stub@<:@".dtors"@:>@
+	  exit ((ctors_ok && dtors_ok) ? 0 : 1)
+	}
+      '], [libc_cv_ctors_header=no])
+    ], [dnl
+      AC_MSG_ERROR([missing __attribute__ ((constructor)) support??])
+    ])
+  ])
   if test $libc_cv_ctors_header = no; then
     AC_DEFINE(NO_CTORS_DTORS_SECTIONS)
   fi