Patchwork [google/gcc-4_6_2-mobile] PATCH: PR other/46770: Replace .ctors/.dtors with .init_array/.fini_array on targets supporting them

login
register
mail settings
Submitter H.J. Lu
Date Feb. 21, 2012, 5:34 p.m.
Message ID <CAMe9rOqq4_3JsQid5dwY69jh6Q+RjVG5bOHXx-Ny8ME91soNHg@mail.gmail.com>
Download mbox | patch
Permalink /patch/142341/
State New
Headers show

Comments

H.J. Lu - Feb. 21, 2012, 5:34 p.m.
On Mon, Feb 20, 2012 at 11:31 PM, Jing Yu <jingyu@google.com> wrote:
> Hi H.J.,
>
> I think the patch itself is not enough.
> I compared "AC_DEFUN([gcc_AC_INITFINI_ARRAY]" part (in acinclude.m4)
> of gcc trunk and google/gcc-4_6_2-mobile, and found how
> enable_initfini_array is
> configured is different.
>
> The patch breaks some of our tests. enable_initfini_array should be
> disabled for cross compile by default. But it is not true in our
> branch. Could you please point us all related patches?
>

I missed this backport. There are some additional changes needed for
non-Linux systems:

http://gcc.gnu.org/ml/gcc-cvs/2011-08/msg00978.html
http://gcc.gnu.org/ml/gcc-cvs/2011-08/msg01132.html
http://gcc.gnu.org/ml/gcc-cvs/2012-01/msg00544.html
Jing Yu - Feb. 22, 2012, 6:54 p.m.
The attachment is a complete patch for [google/gcc-4_6] branch, to
replace .ctors/.dtors with .init_array/.fini_array.

Bootstrap and crosstool testers pass.
I have verified that "gcc_cv_initfini_array=no", which means the
crosstool will do whatever it did before (won't replace .ctors/.dtors
with .init_array/.fini_array).

I also built Android toolchain and verified "gcc_cv_initfini_array=no".

r177933 is already in google/gcc-4_6_2-mobile and
google/gcc-4_6-mobile. I need to backport the rest to these two
branches.

ok?

2012-02-21   Jing Yu  <jingyu@google.com>

        Google Ref 47894
        Backport from mainline r177933, r175181, r177963, r178116, r183299.

        2011-08-20  H.J. Lu  <hongjiu.lu@intel.com>
        PR other/46770
        * config.gcc (tm_file): Add initfini-array.h if
        .init_arrary/.fini_array are supported.
        * crtstuff.c: Don't generate .ctors nor .dtors sections if
        USE_INITFINI_ARRAY is defined.
        * output.h (default_elf_init_array_asm_out_constructor): New.
        (default_elf_fini_array_asm_out_destructor): Likewise.
        * varasm.c (elf_init_array_section): Likewise.
        (elf_fini_array_section): Likewise.
        (get_elf_initfini_array_priority_section): Likewise.
        (default_elf_init_array_asm_out_constructor): Likewise.
        (default_elf_fini_array_asm_out_destructor): Likewise.
        * config/initfini-array.h: New.

        2011-06-18  H.J. Lu  <hongjiu.lu@intel.com>
        PR other/49325
        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Properly check if
        .init_array can be used with .ctors on targets.
        * configure: Regenerated.

        2011-08-22  H.J. Lu  <hongjiu.lu@intel.com>
        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Error if __ELF__ isn't
        defined.
        * configure: Regenerated.

        2011-08-26  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
        PR target/50166
        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Check count in main.
        * configure: Regenerate.

        2012-01-19  Jakub Jelinek  <jakub@redhat.com>
        PR bootstrap/50237
        * config/initfini-array.h: Guard content of the header
        with #ifdef HAVE_INITFINI_ARRAY.
        * configure.ac: Move gcc_AC_INITFINI_ARRAY much later into the
        file.
        Add initfini-array.h to tm_file here.
        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): For non-ia64 do a
        linker test.
        * config.gcc: Don't add initfini-array.h to tm_file here.
        * configure: Regenerated.

Thanks,
Jing

On Tue, Feb 21, 2012 at 9:34 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Feb 20, 2012 at 11:31 PM, Jing Yu <jingyu@google.com> wrote:
>> Hi H.J.,
>>
>> I think the patch itself is not enough.
>> I compared "AC_DEFUN([gcc_AC_INITFINI_ARRAY]" part (in acinclude.m4)
>> of gcc trunk and google/gcc-4_6_2-mobile, and found how
>> enable_initfini_array is
>> configured is different.
>>
>> The patch breaks some of our tests. enable_initfini_array should be
>> disabled for cross compile by default. But it is not true in our
>> branch. Could you please point us all related patches?
>>
>
> I missed this backport. There are some additional changes needed for
> non-Linux systems:
>
> http://gcc.gnu.org/ml/gcc-cvs/2011-08/msg00978.html
> http://gcc.gnu.org/ml/gcc-cvs/2011-08/msg01132.html
> http://gcc.gnu.org/ml/gcc-cvs/2012-01/msg00544.html
>
>
>
> --
> H.J.

Patch

diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4
index 3eec559..ff38682 100644
--- a/gcc/acinclude.m4
+++ b/gcc/acinclude.m4
@@ -375,13 +375,115 @@  AC_DEFUN([gcc_AC_INITFINI_ARRAY],
 	[], [
 AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support,
 		 gcc_cv_initfini_array, [dnl
-  AC_RUN_IFELSE([AC_LANG_SOURCE([
+  if test "x${build}" = "x${target}" && test "x${build}" = "x${host}"; then
+    AC_RUN_IFELSE([AC_LANG_SOURCE([
+#ifdef __ia64__
+/* 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;])],
+int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;
+#else
+extern void abort ();
+static int count;
+
+static void
+init1005 ()
+{
+  if (count != 0)
+    abort ();
+  count = 1005;
+}
+void (*const init_array1005[]) ()
+  __attribute__ ((section (".init_array.01005"), aligned (sizeof (void *))))
+  = { init1005 };
+static void
+fini1005 ()
+{
+  if (count != 1005)
+    abort ();
+}
+void (*const fini_array1005[]) ()
+  __attribute__ ((section (".fini_array.01005"), aligned (sizeof (void *))))
+  = { fini1005 };
+
+static void
+ctor1007 ()
+{
+  if (count != 1005)
+    abort ();
+  count = 1007;
+}
+void (*const ctors1007[]) ()
+  __attribute__ ((section (".ctors.64528"), aligned (sizeof (void *))))
+  = { ctor1007 };
+static void
+dtor1007 ()
+{
+  if (count != 1007)
+    abort ();
+  count = 1005;
+}
+void (*const dtors1007[]) ()
+  __attribute__ ((section (".dtors.64528"), aligned (sizeof (void *))))
+  = { dtor1007 };
+
+static void
+init65530 ()
+{
+  if (count != 1007)
+    abort ();
+  count = 65530;
+}
+void (*const init_array65530[]) ()
+  __attribute__ ((section (".init_array.65530"), aligned (sizeof (void *))))
+  = { init65530 };
+static void
+fini65530 ()
+{
+  if (count != 65530)
+    abort ();
+  count = 1007;
+}
+void (*const fini_array65530[]) ()
+  __attribute__ ((section (".fini_array.65530"), aligned (sizeof (void *))))
+  = { fini65530 };
+
+static void
+ctor65535 ()
+{
+  if (count != 65530)
+    abort ();
+  count = 65535;
+}
+void (*const ctors65535[]) ()
+  __attribute__ ((section (".ctors"), aligned (sizeof (void *))))
+  = { ctor65535 };
+static void
+dtor65535 ()
+{
+  if (count != 65535)
+    abort ();
+  count = 65530;
+}
+void (*const dtors65535[]) ()
+  __attribute__ ((section (".dtors"), aligned (sizeof (void *))))
+  = { dtor65535 };
+
+int
+main ()
+{
+  return 0;
+}
+#endif
+])],
 	     [gcc_cv_initfini_array=yes], [gcc_cv_initfini_array=no],
-	     [gcc_cv_initfini_array=no])])
+	     [gcc_cv_initfini_array=no])
+   else
+     AC_MSG_CHECKING(cross compile... guessing)
+     gcc_cv_initfini_array=no
+   fi])
   enable_initfini_array=$gcc_cv_initfini_array
 ])
 if test $enable_initfini_array = yes; then
diff --git a/gcc/configure b/gcc/configure
index 1438b94..329d3e0 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -4861,7 +4861,7 @@  fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $acx_cv_cc_gcc_supports_ada" >&5
 $as_echo "$acx_cv_cc_gcc_supports_ada" >&6; }
 
-if test x$GNATBIND != xno && test x$GNATMAKE != xno && test x$acx_cv_cc_gcc_supports_ada != xno; then
+if test "x$GNATBIND" != xno && test "x$GNATMAKE" != xno && test x$acx_cv_cc_gcc_supports_ada != xno; then
   have_gnat=yes
 else
   have_gnat=no
@@ -10504,16 +10504,114 @@  $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
     if test "$cross_compiling" = yes; then :
   gcc_cv_initfini_array=no
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
+#ifdef __ia64__
+/* 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;
+#else
+extern void abort ();
+static int count;
+
+static void
+init1005 ()
+{
+  if (count != 0)
+    abort ();
+  count = 1005;
+}
+void (*const init_array1005) ()
+  __attribute__ ((section (".init_array.01005"), aligned (sizeof (void *))))
+  = { init1005 };
+static void
+fini1005 ()
+{
+  if (count != 1005)
+    abort ();
+}
+void (*const fini_array1005) ()
+  __attribute__ ((section (".fini_array.01005"), aligned (sizeof (void *))))
+  = { fini1005 };
+
+static void
+ctor1007 ()
+{
+  if (count != 1005)
+    abort ();
+  count = 1007;
+}
+void (*const ctors1007) ()
+  __attribute__ ((section (".ctors.64528"), aligned (sizeof (void *))))
+  = { ctor1007 };
+static void
+dtor1007 ()
+{
+  if (count != 1007)
+    abort ();
+  count = 1005;
+}
+void (*const dtors1007) ()
+  __attribute__ ((section (".dtors.64528"), aligned (sizeof (void *))))
+  = { dtor1007 };
+
+static void
+init65530 ()
+{
+  if (count != 1007)
+    abort ();
+  count = 65530;
+}
+void (*const init_array65530) ()
+  __attribute__ ((section (".init_array.65530"), aligned (sizeof (void *))))
+  = { init65530 };
+static void
+fini65530 ()
+{
+  if (count != 65530)
+    abort ();
+  count = 1007;
+}
+void (*const fini_array65530) ()
+  __attribute__ ((section (".fini_array.65530"), aligned (sizeof (void *))))
+  = { fini65530 };
+
+static void
+ctor65535 ()
+{
+  if (count != 65530)
+    abort ();
+  count = 65535;
+}
+void (*const ctors65535) ()
+  __attribute__ ((section (".ctors"), aligned (sizeof (void *))))
+  = { ctor65535 };
+static void
+dtor65535 ()
+{
+  if (count != 65535)
+    abort ();
+  count = 65530;
+}
+void (*const dtors65535) ()
+  __attribute__ ((section (".dtors"), aligned (sizeof (void *))))
+  = { dtor65535 };
+
+int
+main ()
+{
+  return 0;
+}
+#endif
+
 _ACEOF
 if ac_fn_c_try_run "$LINENO"; then :
   gcc_cv_initfini_array=yes
@@ -10524,6 +10622,11 @@  rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
   conftest.$ac_objext conftest.beam conftest.$ac_ext
 fi
 
+   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; }
@@ -17572,7 +17675,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 17575 "configure"
+#line 17678 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -17678,7 +17781,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 17681 "configure"
+#line 17784 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H