Jakub Jelinek <ja...@redhat.com> writes:

> The following patch attempts to perform a separate linker check
> (grepping objdump of a linked binary) and checks so far glibc version
> which is known to support .init_array properly.  Perhaps other
> C libraries could be added there too (does e.g. Solaris support .init_array
> properly, or FreeBSD, other OSes?).

As described in the PR, Solaris ld.so.1 does support
.init_array/.fini_array since an early Solaris 8 patch.

We can (and need to) use the Sun ld version number to check for a
matching ld.so.1 since both are updated in lockstep.  To support that, I
must check ld -V output in the native case even if a different linker is
configured.

The following patch has been bootstrapped without regressions on
i386-pc-solaris2.11 with Sun as/ld, gas/Sun ld, gas/gld, where only the
last combination fully supports .init_array/.fini_array due to the
requirement to merge .[cd]tors.* and .{init,fini}_array.* sections which
only gld does so far.  I've run H.J.'s original test program on Solaris
8 to 11 and it works on Solaris/x86.  The new test doesn't work on
Solaris/SPARC even with gld, still need to investigate why.

Ok for mainline?

        Rainer


2012-01-20  Rainer Orth  <r...@cebitec.uni-bielefeld.de>

        PR target/50166
        * configure.ac (sun_ld_vers_major, sun_ld_vers_minor): Set on
        native *-*-solaris2*.
        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Define _start.
        Remove -e 0 from $gcc_cv_ld invocation.
        Only use __GLIBC_PREREQ if defined.
        Enable on Solaris since Solaris 8 patch.
        * configure: Regenerate.

# HG changeset patch
# Parent 94f7fcd05ab2cbde19449f1a0fe7151dc01a8208
Enable initfini array support on Solaris

diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4
--- a/gcc/acinclude.m4
+++ b/gcc/acinclude.m4
@@ -1,4 +1,5 @@
-dnl Copyright (C) 2005, 2006, 2007, 2008, 2011 Free Software Foundation, Inc.
+dnl Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012
+dnl Free Software Foundation, Inc.
 dnl
 dnl This file is part of GCC.
 dnl
@@ -427,9 +428,11 @@ int (*fp) (void) __attribute__ ((section
 .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 -e 0 -o conftest conftest.o > /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 \
@@ -442,14 +445,38 @@ changequote([,])dnl
 	fi
 	AC_PREPROC_IFELSE([AC_LANG_SOURCE([
 #ifndef __ELF__
-#error Not an ELF OS
+# error Not an ELF OS
 #endif
 #include <stdlib.h>
-#if defined __GLIBC_PREREQ && __GLIBC_PREREQ (2, 4)
+#if defined __GLIBC_PREREQ
+# if __GLIBC_PREREQ (2, 4)
+# else
+#  error GLIBC 2.4 required
+# endif
 #else
-#error The C library not known to support .init_array/.fini_array
+# 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
-])],, [gcc_cv_initfini_array=no]);;
+])],[
+    case "${target}" in
+      *-*-solaris2.8*)
+	# .init_array/.fini_array support was introduced in Solaris 8
+	# patches 109147-08 (sparc) and 109148-08 (x86).  Since ld.so.1 and
+	# ld are guaranteed to be updated in lockstep, we can check ld -V
+	# instead.  Unfortunately, proper ld version numbers were only
+	# introduced in rev. -14, so we check for that.
+  	if test "$sun_ld_vers_minor" -lt 272; then
+	  gcc_cv_initfini_array=no
+	fi
+      ;;
+      *-*-solaris2.9* | *-*-solaris2.1[[0-9]]*)
+        # .init_array/.fini_array support is present since Solaris 9 FCS.
+        ;;
+    esac
+], [gcc_cv_initfini_array=no]);;
     esac
   else
     AC_MSG_CHECKING(cross compile... guessing)
diff --git a/gcc/configure.ac b/gcc/configure.ac
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2270,6 +2270,25 @@ if test x$enable_gnu_indirect_function =
 fi
 
 changequote(,)dnl
+if test "x${build}" = "x${target}" && test "x${build}" = "x${host}"; then
+  case "${target}" in
+    *-*-solaris2*)
+      # ld.so.1 and ld are guaranteed to be updated in lockstep, so check
+      # ld version number for use in ld.so.1 feature checks even if a
+      # different linker is configured.
+      #
+      # See below for the version number formats.
+      sun_ld_ver=`/usr/ccs/bin/ld -V 2>&1`
+      if echo "$sun_ld_ver" | grep 'Solaris Link Editors' > /dev/null; then
+	sun_ld_vers=`echo $sun_ld_ver | sed -n \
+	  -e 's,^.*: 5\.[0-9][0-9]*-\([0-9]\.[0-9][0-9]*\).*$,\1,p'`
+	sun_ld_vers_major=`expr "$sun_ld_vers" : '\([0-9]*\)'`
+	sun_ld_vers_minor=`expr "$sun_ld_vers" : '[0-9]*\.\([0-9]*\)'`
+      fi
+      ;;
+  esac
+fi
+
 if test $in_tree_ld != yes ; then
   ld_ver=`$gcc_cv_ld --version 2>/dev/null | sed 1q`
   if echo "$ld_ver" | grep GNU > /dev/null; then
@@ -2305,6 +2324,9 @@ if test $in_tree_ld != yes ; then
 	#
 	# ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.1701:onnv-ab196087-6931056-03/25/10
 	#
+	# Don't reuse sun_ld_vers_* above in case a linker other than
+	# /usr/ccs/bin/ld has been configured.
+	#
 	ld_ver=`$gcc_cv_ld -V 2>&1`
 	if echo "$ld_ver" | grep 'Solaris Link Editors' > /dev/null; then
 	  ld_vers=`echo $ld_ver | sed -n \

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

Reply via email to