Support for .preinit_array/.init_array/.fini_array has been available in
glibc since version 2.4.

[gcc]
2014-08-27  Tulio Magno Quites Machado Filho  <tul...@linux.vnet.ibm.com>

        * acinclude.m4: Automatically detect if glibc supports
        .preinit_array/.init_array/.fini_array on cross compilers.
        * configure: Regenerate.
        * configure.ac: Detect support for
        .preinit_array/.init_array/.fini_array only after detecting glibc
        version.
---
 gcc/acinclude.m4 |   3 +-
 gcc/configure    | 324 ++++++++++++++++++++++++++++---------------------------
 gcc/configure.ac |   4 +-
 3 files changed, 169 insertions(+), 162 deletions(-)

diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4
index 58daa44..72480f6 100644
--- a/gcc/acinclude.m4
+++ b/gcc/acinclude.m4
@@ -371,7 +371,8 @@ changequote([,])dnl
     esac
   else
     AC_MSG_CHECKING(cross compile... guessing)
-    gcc_cv_initfini_array=no
+    GCC_GLIBC_VERSION_GTE_IFELSE(2, 4, [gcc_cv_initfini_array=yes],
+      [gcc_cv_initfini_array=no])
   fi])
   enable_initfini_array=$gcc_cv_initfini_array
 ])
diff --git a/gcc/configure b/gcc/configure
index fc78f42..1826f36 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -918,9 +918,9 @@ enable_ld
 enable_gold
 with_plugin_ld
 enable_gnu_indirect_function
-enable_initfini_array
 enable_comdat
 with_glibc_version
+enable_initfini_array
 enable_gnu_unique_object
 enable_linker_build_id
 with_long_double_128
@@ -1636,8 +1636,8 @@ Optional Features:
   --enable-gnu-indirect-function
                           enable the use of the @gnu_indirect_function to
                           glibc systems
-  --enable-initfini-array      use .init_array/.fini_array sections
   --enable-comdat         enable COMDAT group support
+  --enable-initfini-array      use .init_array/.fini_array sections
   --enable-gnu-unique-object
                           enable the use of the @gnu_unique_object ELF
                           extension on glibc systems
@@ -22448,163 +22448,6 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_ro_rw_mix" >&5
 $as_echo "$gcc_cv_ld_ro_rw_mix" >&6; }
 
-if test "x${build}" = "x${target}" && test "x${build}" = "x${host}"; then
-  case "${target}" in
-    *-*-solaris2*)
-      #
-      # Solaris 2 ld -V output looks like this for a regular version:
-      #
-      # ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.1699
-      #
-      # but test versions add stuff at the end:
-      #
-      # ld: Software Generation Utilities - Solaris Link Editors: 
5.11-1.1701:onnv-ab196087-6931056-03/25/10
-      #
-      gcc_cv_sun_ld_ver=`/usr/ccs/bin/ld -V 2>&1`
-      if echo "$gcc_cv_sun_ld_ver" | grep 'Solaris Link Editors' > /dev/null; 
then
-       gcc_cv_sun_ld_vers=`echo $gcc_cv_sun_ld_ver | sed -n \
-         -e 's,^.*: 5\.[0-9][0-9]*-\([0-9]\.[0-9][0-9]*\).*$,\1,p'`
-       gcc_cv_sun_ld_vers_major=`expr "$gcc_cv_sun_ld_vers" : '\([0-9]*\)'`
-       gcc_cv_sun_ld_vers_minor=`expr "$gcc_cv_sun_ld_vers" : 
'[0-9]*\.\([0-9]*\)'`
-      fi
-      ;;
-  esac
-fi
-
-# Check whether --enable-initfini-array was given.
-if test "${enable_initfini_array+set}" = set; then :
-  enableval=$enable_initfini_array;
-else
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for 
.preinit_array/.init_array/.fini_array support" >&5
-$as_echo_n "checking for .preinit_array/.init_array/.fini_array support... " 
>&6; }
-if test "${gcc_cv_initfini_array+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-    if test "x${build}" = "x${target}" && test "x${build}" = "x${host}"; then
-    case "${target}" in
-      ia64-*)
-       if test "$cross_compiling" = yes; then :
-  gcc_cv_initfini_array=no
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-#ifndef __ELF__
-#error Not an ELF OS
-#endif
-/* We turn on .preinit_array/.init_array/.fini_array support for ia64
-   if it can be used.  */
-static int x = -1;
-int main (void) { return x; }
-int foo (void) { x = 0; }
-int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;
-
-_ACEOF
-if ac_fn_c_try_run "$LINENO"; then :
-  gcc_cv_initfini_array=yes
-else
-  gcc_cv_initfini_array=no
-fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
-  conftest.$ac_objext conftest.beam conftest.$ac_ext
-fi
-;;
-      *)
-       gcc_cv_initfini_array=no
-       if test $in_tree_ld = yes ; then
-         if test "$gcc_cv_gld_major_version" -eq 2 \
-            -a "$gcc_cv_gld_minor_version" -ge 22 \
-            -o "$gcc_cv_gld_major_version" -gt 2 \
-            && test $in_tree_ld_is_elf = yes; then
-           gcc_cv_initfini_array=yes
-         fi
-       elif test x$gcc_cv_as != x -a x$gcc_cv_ld != x -a x$gcc_cv_objdump != x 
; then
-         cat > conftest.s <<\EOF
-.section .dtors,"a",%progbits
-.balign 4
-.byte 'A', 'A', 'A', 'A'
-.section .ctors,"a",%progbits
-.balign 4
-.byte 'B', 'B', 'B', 'B'
-.section .fini_array.65530,"a",%progbits
-.balign 4
-.byte 'C', 'C', 'C', 'C'
-.section .init_array.65530,"a",%progbits
-.balign 4
-.byte 'D', 'D', 'D', 'D'
-.section .dtors.64528,"a",%progbits
-.balign 4
-.byte 'E', 'E', 'E', 'E'
-.section .ctors.64528,"a",%progbits
-.balign 4
-.byte 'F', 'F', 'F', 'F'
-.section .fini_array.01005,"a",%progbits
-.balign 4
-.byte 'G', 'G', 'G', 'G'
-.section .init_array.01005,"a",%progbits
-.balign 4
-.byte 'H', 'H', 'H', 'H'
-.text
-.globl _start
-_start:
-EOF
-         if $gcc_cv_as -o conftest.o conftest.s > /dev/null 2>&1 \
-            && $gcc_cv_ld -o conftest conftest.o > /dev/null 2>&1 \
-            && $gcc_cv_objdump -s -j .init_array conftest \
-               | grep HHHHFFFFDDDDBBBB > /dev/null 2>&1 \
-            && $gcc_cv_objdump -s -j .fini_array conftest \
-               | grep GGGGEEEECCCCAAAA > /dev/null 2>&1; then
-           gcc_cv_initfini_array=yes
-         fi
-         rm -f conftest conftest.*
-       fi
-       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-#ifndef __ELF__
-# error Not an ELF OS
-#endif
-#include <stdlib.h>
-#if defined __GLIBC_PREREQ
-# if __GLIBC_PREREQ (2, 4)
-# else
-#  error GLIBC 2.4 required
-# endif
-#else
-# if defined __sun__ && defined __svr4__
-   /* Solaris ld.so.1 supports .init_array/.fini_array since Solaris 8.  */
-# else
-#  error The C library not known to support .init_array/.fini_array
-# endif
-#endif
-
-_ACEOF
-if ac_fn_c_try_cpp "$LINENO"; then :
-
-else
-  gcc_cv_initfini_array=no
-fi
-rm -f conftest.err conftest.$ac_ext;;
-    esac
-  else
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking cross compile... 
guessing" >&5
-$as_echo_n "checking cross compile... guessing... " >&6; }
-    gcc_cv_initfini_array=no
-  fi
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_initfini_array" >&5
-$as_echo "$gcc_cv_initfini_array" >&6; }
-  enable_initfini_array=$gcc_cv_initfini_array
-
-fi
-
-if test $enable_initfini_array = yes; then
-
-$as_echo "#define HAVE_INITFINI_ARRAY_SUPPORT 1" >>confdefs.h
-
-fi
-
 # Check if we have .[us]leb128, and support symbol arithmetic with it.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .sleb128 and 
.uleb128" >&5
 $as_echo_n "checking assembler for .sleb128 and .uleb128... " >&6; }
@@ -26671,6 +26514,169 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$glibc_version_major.$glibc_version_minor" >&5
 $as_echo "$glibc_version_major.$glibc_version_minor" >&6; }
 
+if test "x${build}" = "x${target}" && test "x${build}" = "x${host}"; then
+  case "${target}" in
+    *-*-solaris2*)
+      #
+      # Solaris 2 ld -V output looks like this for a regular version:
+      #
+      # ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.1699
+      #
+      # but test versions add stuff at the end:
+      #
+      # ld: Software Generation Utilities - Solaris Link Editors: 
5.11-1.1701:onnv-ab196087-6931056-03/25/10
+      #
+      gcc_cv_sun_ld_ver=`/usr/ccs/bin/ld -V 2>&1`
+      if echo "$gcc_cv_sun_ld_ver" | grep 'Solaris Link Editors' > /dev/null; 
then
+       gcc_cv_sun_ld_vers=`echo $gcc_cv_sun_ld_ver | sed -n \
+         -e 's,^.*: 5\.[0-9][0-9]*-\([0-9]\.[0-9][0-9]*\).*$,\1,p'`
+       gcc_cv_sun_ld_vers_major=`expr "$gcc_cv_sun_ld_vers" : '\([0-9]*\)'`
+       gcc_cv_sun_ld_vers_minor=`expr "$gcc_cv_sun_ld_vers" : 
'[0-9]*\.\([0-9]*\)'`
+      fi
+      ;;
+  esac
+fi
+
+# Check whether --enable-initfini-array was given.
+if test "${enable_initfini_array+set}" = set; then :
+  enableval=$enable_initfini_array;
+else
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for 
.preinit_array/.init_array/.fini_array support" >&5
+$as_echo_n "checking for .preinit_array/.init_array/.fini_array support... " 
>&6; }
+if test "${gcc_cv_initfini_array+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+    if test "x${build}" = "x${target}" && test "x${build}" = "x${host}"; then
+    case "${target}" in
+      ia64-*)
+       if test "$cross_compiling" = yes; then :
+  gcc_cv_initfini_array=no
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#ifndef __ELF__
+#error Not an ELF OS
+#endif
+/* We turn on .preinit_array/.init_array/.fini_array support for ia64
+   if it can be used.  */
+static int x = -1;
+int main (void) { return x; }
+int foo (void) { x = 0; }
+int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gcc_cv_initfini_array=yes
+else
+  gcc_cv_initfini_array=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+;;
+      *)
+       gcc_cv_initfini_array=no
+       if test $in_tree_ld = yes ; then
+         if test "$gcc_cv_gld_major_version" -eq 2 \
+            -a "$gcc_cv_gld_minor_version" -ge 22 \
+            -o "$gcc_cv_gld_major_version" -gt 2 \
+            && test $in_tree_ld_is_elf = yes; then
+           gcc_cv_initfini_array=yes
+         fi
+       elif test x$gcc_cv_as != x -a x$gcc_cv_ld != x -a x$gcc_cv_objdump != x 
; then
+         cat > conftest.s <<\EOF
+.section .dtors,"a",%progbits
+.balign 4
+.byte 'A', 'A', 'A', 'A'
+.section .ctors,"a",%progbits
+.balign 4
+.byte 'B', 'B', 'B', 'B'
+.section .fini_array.65530,"a",%progbits
+.balign 4
+.byte 'C', 'C', 'C', 'C'
+.section .init_array.65530,"a",%progbits
+.balign 4
+.byte 'D', 'D', 'D', 'D'
+.section .dtors.64528,"a",%progbits
+.balign 4
+.byte 'E', 'E', 'E', 'E'
+.section .ctors.64528,"a",%progbits
+.balign 4
+.byte 'F', 'F', 'F', 'F'
+.section .fini_array.01005,"a",%progbits
+.balign 4
+.byte 'G', 'G', 'G', 'G'
+.section .init_array.01005,"a",%progbits
+.balign 4
+.byte 'H', 'H', 'H', 'H'
+.text
+.globl _start
+_start:
+EOF
+         if $gcc_cv_as -o conftest.o conftest.s > /dev/null 2>&1 \
+            && $gcc_cv_ld -o conftest conftest.o > /dev/null 2>&1 \
+            && $gcc_cv_objdump -s -j .init_array conftest \
+               | grep HHHHFFFFDDDDBBBB > /dev/null 2>&1 \
+            && $gcc_cv_objdump -s -j .fini_array conftest \
+               | grep GGGGEEEECCCCAAAA > /dev/null 2>&1; then
+           gcc_cv_initfini_array=yes
+         fi
+         rm -f conftest conftest.*
+       fi
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#ifndef __ELF__
+# error Not an ELF OS
+#endif
+#include <stdlib.h>
+#if defined __GLIBC_PREREQ
+# if __GLIBC_PREREQ (2, 4)
+# else
+#  error GLIBC 2.4 required
+# endif
+#else
+# if defined __sun__ && defined __svr4__
+   /* Solaris ld.so.1 supports .init_array/.fini_array since Solaris 8.  */
+# else
+#  error The C library not known to support .init_array/.fini_array
+# endif
+#endif
+
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  gcc_cv_initfini_array=no
+fi
+rm -f conftest.err conftest.$ac_ext;;
+    esac
+  else
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking cross compile... 
guessing" >&5
+$as_echo_n "checking cross compile... guessing... " >&6; }
+
+if test $glibc_version_major -gt 2 \
+  || ( test $glibc_version_major -eq 2 && test $glibc_version_minor -ge 4 ); 
then :
+  gcc_cv_initfini_array=yes
+else
+  gcc_cv_initfini_array=no
+fi
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_initfini_array" >&5
+$as_echo "$gcc_cv_initfini_array" >&6; }
+  enable_initfini_array=$gcc_cv_initfini_array
+
+fi
+
+if test $enable_initfini_array = yes; then
+
+$as_echo "#define HAVE_INITFINI_ARRAY_SUPPORT 1" >>confdefs.h
+
+fi
+
 # Check whether --enable-gnu-unique-object was given.
 if test "${enable_gnu_unique_object+set}" = set; then :
   enableval=$enable_gnu_unique_object; case $enable_gnu_unique_object in
diff --git a/gcc/configure.ac b/gcc/configure.ac
index c7f0e6a..5bfa729 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2538,8 +2538,6 @@ if test x$gcc_cv_ld_ro_rw_mix = xread-write; then
 fi
 AC_MSG_RESULT($gcc_cv_ld_ro_rw_mix)
 
-gcc_AC_INITFINI_ARRAY
-
 # Check if we have .[us]leb128, and support symbol arithmetic with it.
 gcc_GAS_CHECK_FEATURE([.sleb128 and .uleb128], gcc_cv_as_leb128,
   [elf,2,11,0],,
@@ -4480,6 +4478,8 @@ glibc_version_minor=0
 fi]])
 AC_MSG_RESULT([$glibc_version_major.$glibc_version_minor])
 
+gcc_AC_INITFINI_ARRAY
+
 AC_ARG_ENABLE(gnu-unique-object,
  [AS_HELP_STRING([--enable-gnu-unique-object],
    [enable the use of the @gnu_unique_object ELF extension on glibc systems])],
-- 
1.8.3.1

Reply via email to