public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
@ 2011-03-21 18:40 H.J. Lu
  2011-03-31 15:15 ` H.J. Lu
  0 siblings, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-03-21 18:40 UTC (permalink / raw)
  To: GCC Patches

On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
> <richard.guenther@gmail.com> wrote:
>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>> This patch uses .init_array/.fini_array sections instead of
>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>> .ctors/.dtors sections with init_priority works.
>>>>
>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>> remove one function call at startup time from each executable and DSO.
>>>> It should reduce image size and improve system startup time.
>>>>
>>>> If a platform with a working .init_array/.fini_array support needs a
>>>> different .init_array/.fini_array implementation, it can set
>>>> use_initfini_array to no.
>>>>
>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>> is default to no unless the native run-time test is passed.
>>>>
>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>> support is required.  The binutils patch is available at
>>>>
>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>
>>> Linker patch has been checked in.
>>>
>>>>
>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>> comments?
>>>>
>>>
>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>> Any comments?
>>
>> Yes.  This is stage1 material.
>>
>
> Here is the updated patch.  OK for trunk?
>
> Thanks.
>
>
> --
> H.J.
> ----
> 2011-03-14  H.J. Lu  <hongjiu.lu@intel.com>
>
>        PR target/46770
>        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>
>        * config.gcc (use_initfini_array): New variable.
>        Use initfini-array.o if supported.
>
>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>        NO_CTORS_DTORS_SECTIONS is defined.
>
>        * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>        --enable-initfini-array and check if .init_array can be used with
>        .ctors.
>
>        * configure: Regenerated.
>
>        * config/initfini-array.c: New.
>        * config/initfini-array.h: Likewise.
>        * config/t-initfini-array: Likewise.
>
>        * config/arm/arm.c (arm_asm_init_sections): Call
>        elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>        is defined.
>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>        Likewise.
>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>        Likewise.
>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>

PING:

http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html

-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-03-21 18:40 PING: PATCH: PR target/46770: Use .init_array/.fini_array sections H.J. Lu
@ 2011-03-31 15:15 ` H.J. Lu
  2011-04-14 19:11   ` H.J. Lu
  2011-04-26 13:08   ` H.J. Lu
  0 siblings, 2 replies; 46+ messages in thread
From: H.J. Lu @ 2011-03-31 15:15 UTC (permalink / raw)
  To: GCC Patches

On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
>> <richard.guenther@gmail.com> wrote:
>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>>> This patch uses .init_array/.fini_array sections instead of
>>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>>> .ctors/.dtors sections with init_priority works.
>>>>>
>>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>>> remove one function call at startup time from each executable and DSO.
>>>>> It should reduce image size and improve system startup time.
>>>>>
>>>>> If a platform with a working .init_array/.fini_array support needs a
>>>>> different .init_array/.fini_array implementation, it can set
>>>>> use_initfini_array to no.
>>>>>
>>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>>> is default to no unless the native run-time test is passed.
>>>>>
>>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>>> support is required.  The binutils patch is available at
>>>>>
>>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>>
>>>> Linker patch has been checked in.
>>>>
>>>>>
>>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>>> comments?
>>>>>
>>>>
>>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>>> Any comments?
>>>
>>> Yes.  This is stage1 material.
>>>
>>
>> Here is the updated patch.  OK for trunk?
>>
>> Thanks.
>>
>>
>> --
>> H.J.
>> ----
>> 2011-03-14  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>        PR target/46770
>>        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>>
>>        * config.gcc (use_initfini_array): New variable.
>>        Use initfini-array.o if supported.
>>
>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>        NO_CTORS_DTORS_SECTIONS is defined.
>>
>>        * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>>        --enable-initfini-array and check if .init_array can be used with
>>        .ctors.
>>
>>        * configure: Regenerated.
>>
>>        * config/initfini-array.c: New.
>>        * config/initfini-array.h: Likewise.
>>        * config/t-initfini-array: Likewise.
>>
>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>        elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>>        is defined.
>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>        Likewise.
>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>        Likewise.
>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>
>
> PING:
>
> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>

Any comments?  Any objections?

-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-03-31 15:15 ` H.J. Lu
@ 2011-04-14 19:11   ` H.J. Lu
  2011-04-26 13:08   ` H.J. Lu
  1 sibling, 0 replies; 46+ messages in thread
From: H.J. Lu @ 2011-04-14 19:11 UTC (permalink / raw)
  To: GCC Patches; +Cc: Richard Henderson

On Thu, Mar 31, 2011 at 7:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
>>> <richard.guenther@gmail.com> wrote:
>>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>>>> This patch uses .init_array/.fini_array sections instead of
>>>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>>>> .ctors/.dtors sections with init_priority works.
>>>>>>
>>>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>>>> remove one function call at startup time from each executable and DSO.
>>>>>> It should reduce image size and improve system startup time.
>>>>>>
>>>>>> If a platform with a working .init_array/.fini_array support needs a
>>>>>> different .init_array/.fini_array implementation, it can set
>>>>>> use_initfini_array to no.
>>>>>>
>>>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>>>> is default to no unless the native run-time test is passed.
>>>>>>
>>>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>>>> support is required.  The binutils patch is available at
>>>>>>
>>>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>>>
>>>>> Linker patch has been checked in.
>>>>>
>>>>>>
>>>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>>>> comments?
>>>>>>
>>>>>
>>>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>>>> Any comments?
>>>>
>>>> Yes.  This is stage1 material.
>>>>
>>>
>>> Here is the updated patch.  OK for trunk?
>>>
>>> Thanks.
>>>
>>>
>>> --
>>> H.J.
>>> ----
>>> 2011-03-14  H.J. Lu  <hongjiu.lu@intel.com>
>>>
>>>        PR target/46770
>>>        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>>>
>>>        * config.gcc (use_initfini_array): New variable.
>>>        Use initfini-array.o if supported.
>>>
>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>        NO_CTORS_DTORS_SECTIONS is defined.
>>>
>>>        * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>>>        --enable-initfini-array and check if .init_array can be used with
>>>        .ctors.
>>>
>>>        * configure: Regenerated.
>>>
>>>        * config/initfini-array.c: New.
>>>        * config/initfini-array.h: Likewise.
>>>        * config/t-initfini-array: Likewise.
>>>
>>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>>        elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>>>        is defined.
>>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>>        Likewise.
>>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>>        Likewise.
>>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>>
>>
>> PING:
>>
>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>
>
> Any comments?  Any objections?
>

Hi Richard,

Can you take a look at this patch?

Thanks.



-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-03-31 15:15 ` H.J. Lu
  2011-04-14 19:11   ` H.J. Lu
@ 2011-04-26 13:08   ` H.J. Lu
  2011-05-18 17:30     ` H.J. Lu
  1 sibling, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-04-26 13:08 UTC (permalink / raw)
  To: GCC Patches, Ian Lance Taylor, Richard Henderson, Jeffrey Law,
	Diego Novillo

[-- Attachment #1: Type: text/plain, Size: 3552 bytes --]

On Thu, Mar 31, 2011 at 7:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
>>> <richard.guenther@gmail.com> wrote:
>>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>>>> This patch uses .init_array/.fini_array sections instead of
>>>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>>>> .ctors/.dtors sections with init_priority works.
>>>>>>
>>>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>>>> remove one function call at startup time from each executable and DSO.
>>>>>> It should reduce image size and improve system startup time.
>>>>>>
>>>>>> If a platform with a working .init_array/.fini_array support needs a
>>>>>> different .init_array/.fini_array implementation, it can set
>>>>>> use_initfini_array to no.
>>>>>>
>>>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>>>> is default to no unless the native run-time test is passed.
>>>>>>
>>>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>>>> support is required.  The binutils patch is available at
>>>>>>
>>>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>>>
>>>>> Linker patch has been checked in.
>>>>>
>>>>>>
>>>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>>>> comments?
>>>>>>
>>>>>
>>>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>>>> Any comments?
>>>>
>>>> Yes.  This is stage1 material.
>>>>
>>>
>>> Here is the updated patch.  OK for trunk?
>>>
>>> Thanks.
>>>
>>>
>>> --
>>> H.J.
>>> ----
>>> 2011-03-14  H.J. Lu  <hongjiu.lu@intel.com>
>>>
>>>        PR target/46770
>>>        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>>>
>>>        * config.gcc (use_initfini_array): New variable.
>>>        Use initfini-array.o if supported.
>>>
>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>        NO_CTORS_DTORS_SECTIONS is defined.
>>>
>>>        * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>>>        --enable-initfini-array and check if .init_array can be used with
>>>        .ctors.
>>>
>>>        * configure: Regenerated.
>>>
>>>        * config/initfini-array.c: New.
>>>        * config/initfini-array.h: Likewise.
>>>        * config/t-initfini-array: Likewise.
>>>
>>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>>        elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>>>        is defined.
>>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>>        Likewise.
>>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>>        Likewise.
>>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>>
>>
>> PING:
>>
>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>
>
> Any comments?  Any objections?
>

Here is the patch updated for the current trunk.  OK for trunk?

Thanks.


-- 
H.J.

[-- Attachment #2: gcc-pr46770-5.patch --]
[-- Type: text/plain, Size: 21414 bytes --]

This patch uses .init_array/.fini_array sections instead of
.ctors/.dtors sections if mixing .init_array/.fini_array and
.ctors/.dtors sections with init_priority works.

It removes .ctors/.ctors sections from executables and DSOes, which will
remove one function call at startup time from each executable and DSO.
It should reduce image size and improve system startup time. 

If a platform with a working .init_array/.fini_array support needs a
different .init_array/.fini_array implementation, it can set
use_initfini_array to no.

Since .init_array/.fini_array is a target feature. --enable-initfini-array
is default to no unless the native run-time test is passed.

To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
support is required.  The binutils patch is available at

http://sourceware.org/ml/binutils/2010-12/msg00466.html

This patch passed 32bit/64bit regression test on Linux/x86-64.

Thanks.

H.J.
---
2010-12-14  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/46770
	* acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.

	* config.gcc (use_initfini_array): New variable.
	Use initfini-array.o if supported.

	* crtstuff.c: Don't generate .ctors nor .dtors sections if
	NO_CTORS_DTORS_SECTIONS is defined.

	* configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
	--enable-initfini-array and check if .init_array can be used with
	.ctors.

	* configure: Regenerated.

	* config/initfini-array.c: New.
	* config/initfini-array.h: Likewise.
	* config/t-initfini-array: Likewise.

	* config/arm/arm.c (arm_asm_init_sections): Call
	elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
	is defined.
	* config/avr/avr.c (avr_asm_init_sections): Likewise.
	* config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
	* config/mep/mep.c (mep_asm_init_sections): Likewise.
	* config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
	Likewise.
	* config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
	* config/stormy16/stormy16.c (xstormy16_asm_init_sections):
	Likewise.
	* config/v850/v850.c (v850_asm_init_sections): Likewise.

diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4
index 3eec559..0f5f686 100644
--- a/gcc/acinclude.m4
+++ b/gcc/acinclude.m4
@@ -369,26 +369,6 @@ else
 fi
 fi])
 
-AC_DEFUN([gcc_AC_INITFINI_ARRAY],
-[AC_ARG_ENABLE(initfini-array,
-	[  --enable-initfini-array	use .init_array/.fini_array sections],
-	[], [
-AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support,
-		 gcc_cv_initfini_array, [dnl
-  AC_RUN_IFELSE([AC_LANG_SOURCE([
-static int x = -1;
-int main (void) { return x; }
-int foo (void) { x = 0; }
-int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;])],
-	     [gcc_cv_initfini_array=yes], [gcc_cv_initfini_array=no],
-	     [gcc_cv_initfini_array=no])])
-  enable_initfini_array=$gcc_cv_initfini_array
-])
-if test $enable_initfini_array = yes; then
-  AC_DEFINE(HAVE_INITFINI_ARRAY, 1,
-    [Define .init_array/.fini_array sections are available and working.])
-fi])
-
 dnl # _gcc_COMPUTE_GAS_VERSION
 dnl # Used by gcc_GAS_VERSION_GTE_IFELSE
 dnl #
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 7c318de..7c27a9b 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -177,6 +177,9 @@
 #  configure_default_options
 #			Set to an initializer for configure_default_options
 #			in configargs.h, based on --with-cpu et cetera.
+#
+#  use_initfini_array	If set to yes, .init_array/.fini_array sections
+#			will be used if they work.
 
 # The following variables are used in each case-construct to build up the
 # outgoing variables:
@@ -223,6 +226,7 @@ default_gnu_indirect_function=no
 target_gtfiles=
 need_64bit_hwint=
 need_64bit_isa=
+use_initfini_array=yes
 
 # Don't carry these over build->host->target.  Please.
 xm_file=
@@ -3037,6 +3041,16 @@ if test x$with_schedule = x; then
 	esac
 fi
 
+# Support --enable-initfini-array.  Use initfini-array.h only if
+# use_initfini_array is also set to yes.  Some platforms don't need it
+# even if enable_initfini_array is yes.
+if test x$enable_initfini_array$use_initfini_array = xyesyes; then
+  tm_file="${tm_file} initfini-array.h"
+  tmake_file="${tmake_file} t-initfini-array"
+  extra_objs="$extra_objs initfini-array.o"
+  target_gtfiles="$target_gtfiles \$(srcdir)/config/initfini-array.c"
+fi
+
 # Validate and mark as valid any --with options supported
 # by this target.  In order to use a particular --with option
 # you must list it in supported_defaults; validating the value
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 5cf9bd0..bf8bd07 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -22881,6 +22881,9 @@ arm_asm_init_sections (void)
 {
   exception_section = get_unnamed_section (0, output_section_asm_op,
 					   "\t.handlerdata");
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 #endif /* ARM_UNWIND_INFO */
 
diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c
index 9184d6c..bfecaf1 100644
--- a/gcc/config/avr/avr.c
+++ b/gcc/config/avr/avr.c
@@ -5264,6 +5264,10 @@ avr_asm_init_sections (void)
 					 NULL);
   readonly_data_section = data_section;
 
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
+
   data_section->unnamed.callback = avr_output_data_section_asm_op;
   bss_section->unnamed.callback = avr_output_bss_section_asm_op;
 }
diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
index 0512ece..873346a 100644
--- a/gcc/config/ia64/ia64.c
+++ b/gcc/config/ia64/ia64.c
@@ -10093,6 +10093,9 @@ ia64_asm_init_sections (void)
 {
   exception_section = get_unnamed_section (0, output_section_asm_op,
 					   "\t.handlerdata");
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 
 /* Implement TARGET_DEBUG_UNWIND_INFO.  */
diff --git a/gcc/config/initfini-array.c b/gcc/config/initfini-array.c
new file mode 100644
index 0000000..d5fd40f
--- /dev/null
+++ b/gcc/config/initfini-array.c
@@ -0,0 +1,79 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   Copyright (C) 2010
+   Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "target.h"
+#include "output.h"
+#include "tree.h"
+#include "ggc.h"
+
+static GTY(()) section *init_array_section;
+static GTY(()) section *fini_array_section;
+
+void
+elf_initfini_array_init_sections (void)
+{
+  init_array_section = get_unnamed_section (0, output_section_asm_op,
+					    "\t.section\t.init_array");
+  fini_array_section = get_unnamed_section (0, output_section_asm_op,
+					    "\t.section\t.fini_array");
+}
+
+static section *
+get_elf_initfini_array_priority_section (int priority,
+					 bool constructor_p)
+{
+  section *sec;
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      char buf[18];
+      sprintf (buf, "%s.%.5u", 
+	       constructor_p ? ".init_array" : ".fini_array",
+	       priority);
+      sec = get_section (buf, SECTION_WRITE, NULL_TREE);
+    }
+  else
+    sec = constructor_p ? init_array_section : fini_array_section;
+  return sec;
+}
+
+/* Use .init_array section for constructors. */
+
+void
+elf_init_array_asm_out_constructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  true);
+  assemble_addr_to_section (symbol, sec);
+}
+
+/* Use .fini_array section for destructors. */
+
+void
+elf_fini_array_asm_out_destructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  false);
+  assemble_addr_to_section (symbol, sec);
+}
+
+#include "gt-initfini-array.h"
diff --git a/gcc/config/initfini-array.h b/gcc/config/initfini-array.h
new file mode 100644
index 0000000..b0b422a
--- /dev/null
+++ b/gcc/config/initfini-array.h
@@ -0,0 +1,46 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   support.
+   Copyright (C) 2010
+   Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+/* No need for .ctors/.dtors section since linker can place them in
+   .init_array/.fini_array section.  */
+#define NO_CTORS_DTORS_SECTIONS
+
+#undef INIT_SECTION_ASM_OP
+#undef FINI_SECTION_ASM_OP
+
+/* FIXME: INIT_ARRAY_SECTION_ASM_OP and FINI_ARRAY_SECTION_ASM_OP
+	  aren't used in any assembly codes.  But we have to define
+	  them to something.  */
+#define INIT_ARRAY_SECTION_ASM_OP Something
+#define FINI_ARRAY_SECTION_ASM_OP Something
+
+#ifndef TARGET_ASM_INIT_SECTIONS
+#define TARGET_ASM_INIT_SECTIONS elf_initfini_array_init_sections
+#endif
+extern void elf_initfini_array_init_sections (void);
+
+/* Use .init_array/.fini_array section for constructors and destructors. */
+#undef TARGET_ASM_CONSTRUCTOR
+#define TARGET_ASM_CONSTRUCTOR elf_init_array_asm_out_constructor
+#undef TARGET_ASM_DESTRUCTOR
+#define TARGET_ASM_DESTRUCTOR elf_fini_array_asm_out_destructor
+extern void elf_init_array_asm_out_constructor (rtx, int);
+extern void elf_fini_array_asm_out_destructor (rtx, int);
diff --git a/gcc/config/mep/mep.c b/gcc/config/mep/mep.c
index 60cf4eb..2c79cf9 100644
--- a/gcc/config/mep/mep.c
+++ b/gcc/config/mep/mep.c
@@ -7392,6 +7392,9 @@ mep_asm_init_sections (void)
     = get_unnamed_section (SECTION_CODE, output_section_asm_op,
 			   "\t.section .ftext,\"ax\"\n\t.core");
 
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 \f
 /* Initialize the GCC target structure.  */
diff --git a/gcc/config/microblaze/microblaze.c b/gcc/config/microblaze/microblaze.c
index 1cec425..12c2e46 100644
--- a/gcc/config/microblaze/microblaze.c
+++ b/gcc/config/microblaze/microblaze.c
@@ -2751,6 +2751,9 @@ microblaze_elf_asm_init_sections (void)
   sdata2_section
     = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
 			   SDATA2_SECTION_ASM_OP);
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 
 /*  Generate assembler code for constant parts of a trampoline.  */
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 6113a75..656c0b2 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -25415,6 +25415,10 @@ rs6000_elf_asm_init_sections (void)
   sdata2_section
     = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
 			   SDATA2_SECTION_ASM_OP);
+
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 
 /* Implement TARGET_SELECT_RTX_SECTION.  */
diff --git a/gcc/config/stormy16/stormy16.c b/gcc/config/stormy16/stormy16.c
index 052285c..30e5a00 100644
--- a/gcc/config/stormy16/stormy16.c
+++ b/gcc/config/stormy16/stormy16.c
@@ -1569,6 +1569,9 @@ xstormy16_asm_init_sections (void)
     = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
 			   output_section_asm_op,
 			   "\t.section \".bss_below100\",\"aw\",@nobits");
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 
 /* Mark symbols with the "below100" attribute so that we can use the
diff --git a/gcc/config/t-initfini-array b/gcc/config/t-initfini-array
new file mode 100644
index 0000000..3dcb25d
--- /dev/null
+++ b/gcc/config/t-initfini-array
@@ -0,0 +1,23 @@
+# Copyright (C) 2010
+# 2009 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+initfini-array.o: $(srcdir)/config/initfini-array.c gt-initfini-array.h \
+	$(CONFIG_H) $(SYSTEM_H) coretypes.h $(TARGET_H) output.h \
+	$(TREE_H) $(GGC_H)
+	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
diff --git a/gcc/config/v850/v850.c b/gcc/config/v850/v850.c
index 86509e0..4efaeaa 100644
--- a/gcc/config/v850/v850.c
+++ b/gcc/config/v850/v850.c
@@ -2982,6 +2982,10 @@ v850_asm_init_sections (void)
     = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
 			   output_section_asm_op,
 			   "\t.section .zbss,\"aw\"");
+
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 
 static section *
diff --git a/gcc/configure b/gcc/configure
index 9056adb..d08d15a 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -10442,6 +10442,7 @@ fi
 # Restore CFLAGS from before the gcc_AC_NEED_DECLARATIONS tests.
 CFLAGS="$saved_CFLAGS"
 
+# Check if .init_array can be used with .ctors.
 # Check whether --enable-initfini-array was given.
 if test "${enable_initfini_array+set}" = set; then :
   enableval=$enable_initfini_array;
@@ -10452,16 +10453,104 @@ $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}" ; then
     if test "$cross_compiling" = yes; then :
   gcc_cv_initfini_array=no
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
-static int x = -1;
-int main (void) { return x; }
-int foo (void) { x = 0; }
-int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;
+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;
+}
 _ACEOF
 if ac_fn_c_try_run "$LINENO"; then :
   gcc_cv_initfini_array=yes
@@ -10472,6 +10561,9 @@ rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
   conftest.$ac_objext conftest.beam conftest.$ac_ext
 fi
 
+   else
+     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; }
diff --git a/gcc/configure.ac b/gcc/configure.ac
index eacf200..ffa4a81 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1125,7 +1125,116 @@ fi
 # Restore CFLAGS from before the gcc_AC_NEED_DECLARATIONS tests.
 CFLAGS="$saved_CFLAGS"
 
-gcc_AC_INITFINI_ARRAY
+# Check if .init_array can be used with .ctors.
+AC_ARG_ENABLE(initfini-array,
+	[  --enable-initfini-array	use .init_array/.fini_array sections],
+	[], [
+AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support,
+		 gcc_cv_initfini_array, [dnl
+  if test "x${build}" = "x${target}" ; then
+    AC_RUN_IFELSE([AC_LANG_SOURCE([
+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;
+}])],
+	     [gcc_cv_initfini_array=yes], [gcc_cv_initfini_array=no],
+	     [gcc_cv_initfini_array=no])
+   else
+     gcc_cv_initfini_array=no
+   fi])
+  enable_initfini_array=$gcc_cv_initfini_array
+])
+if test $enable_initfini_array = yes; then
+  AC_DEFINE(HAVE_INITFINI_ARRAY, 1,
+    [Define .init_array/.fini_array sections are available and working.])
+fi
 
 # mkdir takes a single argument on some systems. 
 gcc_AC_FUNC_MKDIR_TAKES_ONE_ARG
diff --git a/gcc/crtstuff.c b/gcc/crtstuff.c
index b65f490..7d31934e 100644
--- a/gcc/crtstuff.c
+++ b/gcc/crtstuff.c
@@ -189,6 +189,9 @@ typedef void (*func_ptr) (void);
    refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
    symbol in crtbegin.o, where they are defined.  */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef NO_CTORS_DTORS_SECTIONS
 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
    does not start with a count of elements.  */
 #ifdef CTOR_LIST_BEGIN
@@ -219,6 +222,7 @@ STATIC func_ptr __DTOR_LIST__[1]
   __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) (-1) };
 #endif /* __DTOR_LIST__ alternatives */
+#endif /* NO_CTORS_DTORS_SECTIONS */
 
 #ifdef USE_EH_FRAME_REGISTRY
 /* Stick a label at the beginning of the frame unwind info so we can register
@@ -489,6 +493,9 @@ __do_global_ctors_1(void)
 
 #elif defined(CRT_END) /* ! CRT_BEGIN */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef NO_CTORS_DTORS_SECTIONS
 /* Put a word containing zero at the end of each of our two lists of function
    addresses.  Note that the words defined here go into the .ctors and .dtors
    sections of the crtend.o file, and since that file is always linked in
@@ -534,6 +541,7 @@ STATIC func_ptr __DTOR_END__[1]
   __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) 0 };
 #endif
+#endif /* NO_CTORS_DTORS_SECTIONS */
 
 #ifdef EH_FRAME_SECTION_NAME
 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-04-26 13:08   ` H.J. Lu
@ 2011-05-18 17:30     ` H.J. Lu
  2011-06-01 23:30       ` Carrot Wei
  2011-06-03  4:31       ` H.J. Lu
  0 siblings, 2 replies; 46+ messages in thread
From: H.J. Lu @ 2011-05-18 17:30 UTC (permalink / raw)
  To: GCC Patches, Ian Lance Taylor, Richard Henderson, Jeffrey Law,
	Diego Novillo

On Tue, Apr 26, 2011 at 6:05 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Mar 31, 2011 at 7:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
>>>> <richard.guenther@gmail.com> wrote:
>>>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>>>>> This patch uses .init_array/.fini_array sections instead of
>>>>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>>>>> .ctors/.dtors sections with init_priority works.
>>>>>>>
>>>>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>>>>> remove one function call at startup time from each executable and DSO.
>>>>>>> It should reduce image size and improve system startup time.
>>>>>>>
>>>>>>> If a platform with a working .init_array/.fini_array support needs a
>>>>>>> different .init_array/.fini_array implementation, it can set
>>>>>>> use_initfini_array to no.
>>>>>>>
>>>>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>>>>> is default to no unless the native run-time test is passed.
>>>>>>>
>>>>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>>>>> support is required.  The binutils patch is available at
>>>>>>>
>>>>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>>>>
>>>>>> Linker patch has been checked in.
>>>>>>
>>>>>>>
>>>>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>>>>> comments?
>>>>>>>
>>>>>>
>>>>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>>>>> Any comments?
>>>>>
>>>>> Yes.  This is stage1 material.
>>>>>
>>>>
>>>> Here is the updated patch.  OK for trunk?
>>>>
>>>> Thanks.
>>>>
>>>>
>>>> --
>>>> H.J.
>>>> ----
>>>> 2011-03-14  H.J. Lu  <hongjiu.lu@intel.com>
>>>>
>>>>        PR target/46770
>>>>        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>>>>
>>>>        * config.gcc (use_initfini_array): New variable.
>>>>        Use initfini-array.o if supported.
>>>>
>>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>>        NO_CTORS_DTORS_SECTIONS is defined.
>>>>
>>>>        * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>>>>        --enable-initfini-array and check if .init_array can be used with
>>>>        .ctors.
>>>>
>>>>        * configure: Regenerated.
>>>>
>>>>        * config/initfini-array.c: New.
>>>>        * config/initfini-array.h: Likewise.
>>>>        * config/t-initfini-array: Likewise.
>>>>
>>>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>>>        elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>>>>        is defined.
>>>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>>>        Likewise.
>>>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>>>        Likewise.
>>>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>>>
>>>
>>> PING:
>>>
>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>>
>>
>> Any comments?  Any objections?
>>
>
> Here is the patch updated for the current trunk.  OK for trunk?
>

PING,.

-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-05-18 17:30     ` H.J. Lu
@ 2011-06-01 23:30       ` Carrot Wei
  2011-06-03  4:31       ` H.J. Lu
  1 sibling, 0 replies; 46+ messages in thread
From: Carrot Wei @ 2011-06-01 23:30 UTC (permalink / raw)
  To: H.J. Lu
  Cc: GCC Patches, Ian Lance Taylor, Richard Henderson, Jeffrey Law,
	Diego Novillo

Hi H.J.

This patch is also important to ChromeOS toolchain. Could you also try
to update and test it for google/main?

thanks
Carrot

On Wed, May 18, 2011 at 11:57 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Apr 26, 2011 at 6:05 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Thu, Mar 31, 2011 at 7:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
>>>>> <richard.guenther@gmail.com> wrote:
>>>>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>>>>>> This patch uses .init_array/.fini_array sections instead of
>>>>>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>>>>>> .ctors/.dtors sections with init_priority works.
>>>>>>>>
>>>>>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>>>>>> remove one function call at startup time from each executable and DSO.
>>>>>>>> It should reduce image size and improve system startup time.
>>>>>>>>
>>>>>>>> If a platform with a working .init_array/.fini_array support needs a
>>>>>>>> different .init_array/.fini_array implementation, it can set
>>>>>>>> use_initfini_array to no.
>>>>>>>>
>>>>>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>>>>>> is default to no unless the native run-time test is passed.
>>>>>>>>
>>>>>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>>>>>> support is required.  The binutils patch is available at
>>>>>>>>
>>>>>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>>>>>
>>>>>>> Linker patch has been checked in.
>>>>>>>
>>>>>>>>
>>>>>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>>>>>> comments?
>>>>>>>>
>>>>>>>
>>>>>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>>>>>> Any comments?
>>>>>>
>>>>>> Yes.  This is stage1 material.
>>>>>>
>>>>>
>>>>> Here is the updated patch.  OK for trunk?
>>>>>
>>>>> Thanks.
>>>>>
>>>>>
>>>>> --
>>>>> H.J.
>>>>> ----
>>>>> 2011-03-14  H.J. Lu  <hongjiu.lu@intel.com>
>>>>>
>>>>>        PR target/46770
>>>>>        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>>>>>
>>>>>        * config.gcc (use_initfini_array): New variable.
>>>>>        Use initfini-array.o if supported.
>>>>>
>>>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>>>        NO_CTORS_DTORS_SECTIONS is defined.
>>>>>
>>>>>        * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>>>>>        --enable-initfini-array and check if .init_array can be used with
>>>>>        .ctors.
>>>>>
>>>>>        * configure: Regenerated.
>>>>>
>>>>>        * config/initfini-array.c: New.
>>>>>        * config/initfini-array.h: Likewise.
>>>>>        * config/t-initfini-array: Likewise.
>>>>>
>>>>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>>>>        elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>>>>>        is defined.
>>>>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>>>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>>>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>>>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>>>>        Likewise.
>>>>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>>>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>>>>        Likewise.
>>>>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>>>>
>>>>
>>>> PING:
>>>>
>>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>>>
>>>
>>> Any comments?  Any objections?
>>>
>>
>> Here is the patch updated for the current trunk.  OK for trunk?
>>
>
> PING,.
>
> --
> H.J.
>

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-05-18 17:30     ` H.J. Lu
  2011-06-01 23:30       ` Carrot Wei
@ 2011-06-03  4:31       ` H.J. Lu
  2011-06-03 12:31         ` Richard Guenther
  1 sibling, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-06-03  4:31 UTC (permalink / raw)
  To: GCC Patches, Richard Guenther

On Wed, May 18, 2011 at 8:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Apr 26, 2011 at 6:05 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Thu, Mar 31, 2011 at 7:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
>>>>> <richard.guenther@gmail.com> wrote:
>>>>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>>>>>> This patch uses .init_array/.fini_array sections instead of
>>>>>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>>>>>> .ctors/.dtors sections with init_priority works.
>>>>>>>>
>>>>>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>>>>>> remove one function call at startup time from each executable and DSO.
>>>>>>>> It should reduce image size and improve system startup time.
>>>>>>>>
>>>>>>>> If a platform with a working .init_array/.fini_array support needs a
>>>>>>>> different .init_array/.fini_array implementation, it can set
>>>>>>>> use_initfini_array to no.
>>>>>>>>
>>>>>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>>>>>> is default to no unless the native run-time test is passed.
>>>>>>>>
>>>>>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>>>>>> support is required.  The binutils patch is available at
>>>>>>>>
>>>>>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>>>>>
>>>>>>> Linker patch has been checked in.
>>>>>>>
>>>>>>>>
>>>>>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>>>>>> comments?
>>>>>>>>
>>>>>>>
>>>>>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>>>>>> Any comments?
>>>>>>
>>>>>> Yes.  This is stage1 material.
>>>>>>
>>>>>
>>>>> Here is the updated patch.  OK for trunk?
>>>>>
>>>>> Thanks.
>>>>>
>>>>>
>>>>> --
>>>>> H.J.
>>>>> ----
>>>>> 2011-03-14  H.J. Lu  <hongjiu.lu@intel.com>
>>>>>
>>>>>        PR target/46770
>>>>>        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>>>>>
>>>>>        * config.gcc (use_initfini_array): New variable.
>>>>>        Use initfini-array.o if supported.
>>>>>
>>>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>>>        NO_CTORS_DTORS_SECTIONS is defined.
>>>>>
>>>>>        * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>>>>>        --enable-initfini-array and check if .init_array can be used with
>>>>>        .ctors.
>>>>>
>>>>>        * configure: Regenerated.
>>>>>
>>>>>        * config/initfini-array.c: New.
>>>>>        * config/initfini-array.h: Likewise.
>>>>>        * config/t-initfini-array: Likewise.
>>>>>
>>>>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>>>>        elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>>>>>        is defined.
>>>>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>>>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>>>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>>>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>>>>        Likewise.
>>>>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>>>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>>>>        Likewise.
>>>>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>>>>
>>>>
>>>> PING:
>>>>
>>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>>>
>>>
>>> Any comments?  Any objections?
>>>
>>
>> Here is the patch updated for the current trunk.  OK for trunk?
>>
>
> PING,.

Hi Richard,

You commented my patch was stage 1 material:

http://gcc.gnu.org/ml/gcc-patches/2011-01/msg01989.html

Is my patch:

http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html

OK for trunk?

Thanks.


-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-06-03  4:31       ` H.J. Lu
@ 2011-06-03 12:31         ` Richard Guenther
  2011-06-03 12:52           ` H.J. Lu
  2011-06-03 17:13           ` Michael Eager
  0 siblings, 2 replies; 46+ messages in thread
From: Richard Guenther @ 2011-06-03 12:31 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches

On Fri, Jun 3, 2011 at 6:31 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, May 18, 2011 at 8:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Tue, Apr 26, 2011 at 6:05 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Thu, Mar 31, 2011 at 7:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
>>>>>> <richard.guenther@gmail.com> wrote:
>>>>>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>>>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>>>>>>> This patch uses .init_array/.fini_array sections instead of
>>>>>>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>>>>>>> .ctors/.dtors sections with init_priority works.
>>>>>>>>>
>>>>>>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>>>>>>> remove one function call at startup time from each executable and DSO.
>>>>>>>>> It should reduce image size and improve system startup time.
>>>>>>>>>
>>>>>>>>> If a platform with a working .init_array/.fini_array support needs a
>>>>>>>>> different .init_array/.fini_array implementation, it can set
>>>>>>>>> use_initfini_array to no.
>>>>>>>>>
>>>>>>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>>>>>>> is default to no unless the native run-time test is passed.
>>>>>>>>>
>>>>>>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>>>>>>> support is required.  The binutils patch is available at
>>>>>>>>>
>>>>>>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>>>>>>
>>>>>>>> Linker patch has been checked in.
>>>>>>>>
>>>>>>>>>
>>>>>>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>>>>>>> comments?
>>>>>>>>>
>>>>>>>>
>>>>>>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>>>>>>> Any comments?
>>>>>>>
>>>>>>> Yes.  This is stage1 material.
>>>>>>>
>>>>>>
>>>>>> Here is the updated patch.  OK for trunk?
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>>
>>>>>> --
>>>>>> H.J.
>>>>>> ----
>>>>>> 2011-03-14  H.J. Lu  <hongjiu.lu@intel.com>
>>>>>>
>>>>>>        PR target/46770
>>>>>>        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>>>>>>
>>>>>>        * config.gcc (use_initfini_array): New variable.
>>>>>>        Use initfini-array.o if supported.
>>>>>>
>>>>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>>>>        NO_CTORS_DTORS_SECTIONS is defined.
>>>>>>
>>>>>>        * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>>>>>>        --enable-initfini-array and check if .init_array can be used with
>>>>>>        .ctors.
>>>>>>
>>>>>>        * configure: Regenerated.
>>>>>>
>>>>>>        * config/initfini-array.c: New.
>>>>>>        * config/initfini-array.h: Likewise.
>>>>>>        * config/t-initfini-array: Likewise.
>>>>>>
>>>>>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>>>>>        elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>>>>>>        is defined.
>>>>>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>>>>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>>>>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>>>>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>>>>>        Likewise.
>>>>>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>>>>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>>>>>        Likewise.
>>>>>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>>>>>
>>>>>
>>>>> PING:
>>>>>
>>>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>>>>
>>>>
>>>> Any comments?  Any objections?
>>>>
>>>
>>> Here is the patch updated for the current trunk.  OK for trunk?
>>>
>>
>> PING,.
>
> Hi Richard,
>
> You commented my patch was stage 1 material:
>
> http://gcc.gnu.org/ml/gcc-patches/2011-01/msg01989.html
>
> Is my patch:
>
> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>
> OK for trunk?

I can't approve the configury changes and would like to defer
to target maintainers for the target specific changes.  That said,
I'm not familiar enough with the area of the patch.  But yes,
it's stage1 now - so if anyone else wants to approve this patch...

Richard.

> Thanks.
>
>
> --
> H.J.
>

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-06-03 12:31         ` Richard Guenther
@ 2011-06-03 12:52           ` H.J. Lu
  2011-06-19 20:02             ` H.J. Lu
  2011-06-03 17:13           ` Michael Eager
  1 sibling, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-06-03 12:52 UTC (permalink / raw)
  To: Richard Guenther; +Cc: GCC Patches

On Fri, Jun 3, 2011 at 5:31 AM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Fri, Jun 3, 2011 at 6:31 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Wed, May 18, 2011 at 8:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Tue, Apr 26, 2011 at 6:05 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Thu, Mar 31, 2011 at 7:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
>>>>>>> <richard.guenther@gmail.com> wrote:
>>>>>>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>>>>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>>>>>>>> This patch uses .init_array/.fini_array sections instead of
>>>>>>>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>>>>>>>> .ctors/.dtors sections with init_priority works.
>>>>>>>>>>
>>>>>>>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>>>>>>>> remove one function call at startup time from each executable and DSO.
>>>>>>>>>> It should reduce image size and improve system startup time.
>>>>>>>>>>
>>>>>>>>>> If a platform with a working .init_array/.fini_array support needs a
>>>>>>>>>> different .init_array/.fini_array implementation, it can set
>>>>>>>>>> use_initfini_array to no.
>>>>>>>>>>
>>>>>>>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>>>>>>>> is default to no unless the native run-time test is passed.
>>>>>>>>>>
>>>>>>>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>>>>>>>> support is required.  The binutils patch is available at
>>>>>>>>>>
>>>>>>>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>>>>>>>
>>>>>>>>> Linker patch has been checked in.
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>>>>>>>> comments?
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>>>>>>>> Any comments?
>>>>>>>>
>>>>>>>> Yes.  This is stage1 material.
>>>>>>>>
>>>>>>>
>>>>>>> Here is the updated patch.  OK for trunk?
>>>>>>>
>>>>>>> Thanks.
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> H.J.
>>>>>>> ----
>>>>>>> 2011-03-14  H.J. Lu  <hongjiu.lu@intel.com>
>>>>>>>
>>>>>>>        PR target/46770
>>>>>>>        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>>>>>>>
>>>>>>>        * config.gcc (use_initfini_array): New variable.
>>>>>>>        Use initfini-array.o if supported.
>>>>>>>
>>>>>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>>>>>        NO_CTORS_DTORS_SECTIONS is defined.
>>>>>>>
>>>>>>>        * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>>>>>>>        --enable-initfini-array and check if .init_array can be used with
>>>>>>>        .ctors.
>>>>>>>
>>>>>>>        * configure: Regenerated.
>>>>>>>
>>>>>>>        * config/initfini-array.c: New.
>>>>>>>        * config/initfini-array.h: Likewise.
>>>>>>>        * config/t-initfini-array: Likewise.
>>>>>>>
>>>>>>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>>>>>>        elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>>>>>>>        is defined.
>>>>>>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>>>>>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>>>>>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>>>>>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>>>>>>        Likewise.
>>>>>>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>>>>>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>>>>>>        Likewise.
>>>>>>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>>>>>>
>>>>>>
>>>>>> PING:
>>>>>>
>>>>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>>>>>
>>>>>
>>>>> Any comments?  Any objections?
>>>>>
>>>>
>>>> Here is the patch updated for the current trunk.  OK for trunk?
>>>>
>>>
>>> PING,.
>>
>> Hi Richard,
>>
>> You commented my patch was stage 1 material:
>>
>> http://gcc.gnu.org/ml/gcc-patches/2011-01/msg01989.html
>>
>> Is my patch:
>>
>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>
>> OK for trunk?
>
> I can't approve the configury changes and would like to defer
> to target maintainers for the target specific changes.  That said,
> I'm not familiar enough with the area of the patch.  But yes,
> it's stage1 now - so if anyone else wants to approve this patch...

My first attempt:

http://gcc.gnu.org/ml/gcc-patches/2010-12/msg00589.html

only affects x86.  I changed it to generic based on the
feedbacks.  But other target maintainers show no interests.
Should I make it x86 only first?  Each target can enable it
if needed.

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-06-03 12:31         ` Richard Guenther
  2011-06-03 12:52           ` H.J. Lu
@ 2011-06-03 17:13           ` Michael Eager
  1 sibling, 0 replies; 46+ messages in thread
From: Michael Eager @ 2011-06-03 17:13 UTC (permalink / raw)
  To: Richard Guenther; +Cc: H.J. Lu, GCC Patches

On 06/03/2011 05:31 AM, Richard Guenther wrote:
> On Fri, Jun 3, 2011 at 6:31 AM, H.J. Lu<hjl.tools@gmail.com>  wrote:
>> On Wed, May 18, 2011 at 8:57 AM, H.J. Lu<hjl.tools@gmail.com>  wrote:
>>> On Tue, Apr 26, 2011 at 6:05 AM, H.J. Lu<hjl.tools@gmail.com>  wrote:
>>>> On Thu, Mar 31, 2011 at 7:57 AM, H.J. Lu<hjl.tools@gmail.com>  wrote:
>>>>> On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu<hjl.tools@gmail.com>  wrote:
>>>>>> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu<hjl.tools@gmail.com>  wrote:
>>>>>>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
>>>>>>> <richard.guenther@gmail.com>  wrote:
>>>>>>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu<hongjiu.lu@intel.com>  wrote:
>>>>>>>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>>>>>>>> This patch uses .init_array/.fini_array sections instead of
>>>>>>>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>>>>>>>> .ctors/.dtors sections with init_priority works.
>>>>>>>>>>
>>>>>>>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>>>>>>>> remove one function call at startup time from each executable and DSO.
>>>>>>>>>> It should reduce image size and improve system startup time.
>>>>>>>>>>
>>>>>>>>>> If a platform with a working .init_array/.fini_array support needs a
>>>>>>>>>> different .init_array/.fini_array implementation, it can set
>>>>>>>>>> use_initfini_array to no.
>>>>>>>>>>
>>>>>>>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>>>>>>>> is default to no unless the native run-time test is passed.
>>>>>>>>>>
>>>>>>>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>>>>>>>> support is required.  The binutils patch is available at
>>>>>>>>>>
>>>>>>>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>>>>>>>
>>>>>>>>> Linker patch has been checked in.
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>>>>>>>> comments?
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>>>>>>>> Any comments?
>>>>>>>>
>>>>>>>> Yes.  This is stage1 material.
>>>>>>>>
>>>>>>>
>>>>>>> Here is the updated patch.  OK for trunk?
>>>>>>>
>>>>>>> Thanks.
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> H.J.
>>>>>>> ----
>>>>>>> 2011-03-14  H.J. Lu<hongjiu.lu@intel.com>
>>>>>>>
>>>>>>>         PR target/46770
>>>>>>>         * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>>>>>>>
>>>>>>>         * config.gcc (use_initfini_array): New variable.
>>>>>>>         Use initfini-array.o if supported.
>>>>>>>
>>>>>>>         * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>>>>>         NO_CTORS_DTORS_SECTIONS is defined.
>>>>>>>
>>>>>>>         * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>>>>>>>         --enable-initfini-array and check if .init_array can be used with
>>>>>>>         .ctors.
>>>>>>>
>>>>>>>         * configure: Regenerated.
>>>>>>>
>>>>>>>         * config/initfini-array.c: New.
>>>>>>>         * config/initfini-array.h: Likewise.
>>>>>>>         * config/t-initfini-array: Likewise.
>>>>>>>
>>>>>>>         * config/arm/arm.c (arm_asm_init_sections): Call
>>>>>>>         elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>>>>>>>         is defined.
>>>>>>>         * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>>>>>>         * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>>>>>>         * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>>>>>>         * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>>>>>>         Likewise.
>>>>>>>         * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>>>>>>         * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>>>>>>         Likewise.
>>>>>>>         * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>>>>>>
>>>>>>
>>>>>> PING:
>>>>>>
>>>>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>>>>>
>>>>>
>>>>> Any comments?  Any objections?
>>>>>
>>>>
>>>> Here is the patch updated for the current trunk.  OK for trunk?
>>>>
>>>
>>> PING,.
>>
>> Hi Richard,
>>
>> You commented my patch was stage 1 material:
>>
>> http://gcc.gnu.org/ml/gcc-patches/2011-01/msg01989.html
>>
>> Is my patch:
>>
>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>
>> OK for trunk?
>
> I can't approve the configury changes and would like to defer
> to target maintainers for the target specific changes.  That said,
> I'm not familiar enough with the area of the patch.  But yes,
> it's stage1 now - so if anyone else wants to approve this patch...

Microblaze change OK.

-- 
Michael Eager	 eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077

^ permalink raw reply	[flat|nested] 46+ messages in thread

* PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-06-03 12:52           ` H.J. Lu
@ 2011-06-19 20:02             ` H.J. Lu
  2011-06-19 21:31               ` Uros Bizjak
  2011-07-01 14:12               ` H.J. Lu
  0 siblings, 2 replies; 46+ messages in thread
From: H.J. Lu @ 2011-06-19 20:02 UTC (permalink / raw)
  To: Richard Guenther, Uros Bizjak; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 5768 bytes --]

On Fri, Jun 3, 2011 at 5:51 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Jun 3, 2011 at 5:31 AM, Richard Guenther
> <richard.guenther@gmail.com> wrote:
>> On Fri, Jun 3, 2011 at 6:31 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Wed, May 18, 2011 at 8:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Tue, Apr 26, 2011 at 6:05 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Thu, Mar 31, 2011 at 7:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>> On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>>> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>>>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
>>>>>>>> <richard.guenther@gmail.com> wrote:
>>>>>>>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>>>>>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>>>>>>>>> This patch uses .init_array/.fini_array sections instead of
>>>>>>>>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>>>>>>>>> .ctors/.dtors sections with init_priority works.
>>>>>>>>>>>
>>>>>>>>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>>>>>>>>> remove one function call at startup time from each executable and DSO.
>>>>>>>>>>> It should reduce image size and improve system startup time.
>>>>>>>>>>>
>>>>>>>>>>> If a platform with a working .init_array/.fini_array support needs a
>>>>>>>>>>> different .init_array/.fini_array implementation, it can set
>>>>>>>>>>> use_initfini_array to no.
>>>>>>>>>>>
>>>>>>>>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>>>>>>>>> is default to no unless the native run-time test is passed.
>>>>>>>>>>>
>>>>>>>>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>>>>>>>>> support is required.  The binutils patch is available at
>>>>>>>>>>>
>>>>>>>>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>>>>>>>>
>>>>>>>>>> Linker patch has been checked in.
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>>>>>>>>> comments?
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>>>>>>>>> Any comments?
>>>>>>>>>
>>>>>>>>> Yes.  This is stage1 material.
>>>>>>>>>
>>>>>>>>
>>>>>>>> Here is the updated patch.  OK for trunk?
>>>>>>>>
>>>>>>>> Thanks.
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> H.J.
>>>>>>>> ----
>>>>>>>> 2011-03-14  H.J. Lu  <hongjiu.lu@intel.com>
>>>>>>>>
>>>>>>>>        PR target/46770
>>>>>>>>        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>>>>>>>>
>>>>>>>>        * config.gcc (use_initfini_array): New variable.
>>>>>>>>        Use initfini-array.o if supported.
>>>>>>>>
>>>>>>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>>>>>>        NO_CTORS_DTORS_SECTIONS is defined.
>>>>>>>>
>>>>>>>>        * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>>>>>>>>        --enable-initfini-array and check if .init_array can be used with
>>>>>>>>        .ctors.
>>>>>>>>
>>>>>>>>        * configure: Regenerated.
>>>>>>>>
>>>>>>>>        * config/initfini-array.c: New.
>>>>>>>>        * config/initfini-array.h: Likewise.
>>>>>>>>        * config/t-initfini-array: Likewise.
>>>>>>>>
>>>>>>>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>>>>>>>        elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>>>>>>>>        is defined.
>>>>>>>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>>>>>>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>>>>>>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>>>>>>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>>>>>>>        Likewise.
>>>>>>>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>>>>>>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>>>>>>>        Likewise.
>>>>>>>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>>>>>>>
>>>>>>>
>>>>>>> PING:
>>>>>>>
>>>>>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>>>>>>
>>>>>>
>>>>>> Any comments?  Any objections?
>>>>>>
>>>>>
>>>>> Here is the patch updated for the current trunk.  OK for trunk?
>>>>>
>>>>
>>>> PING,.
>>>
>>> Hi Richard,
>>>
>>> You commented my patch was stage 1 material:
>>>
>>> http://gcc.gnu.org/ml/gcc-patches/2011-01/msg01989.html
>>>
>>> Is my patch:
>>>
>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>>
>>> OK for trunk?
>>
>> I can't approve the configury changes and would like to defer
>> to target maintainers for the target specific changes.  That said,
>> I'm not familiar enough with the area of the patch.  But yes,
>> it's stage1 now - so if anyone else wants to approve this patch...
>
> My first attempt:
>
> http://gcc.gnu.org/ml/gcc-patches/2010-12/msg00589.html
>
> only affects x86.  I changed it to generic based on the
> feedbacks.  But other target maintainers show no interests.
> Should I make it x86 only first?  Each target can enable it
> if needed.
>

I am enclosing 2 patches here.  One only affects Linux/x86
and the other covers all targets.  I tested both versions on
Linux/x86 without any regressions.  Since I only got OK from
one target maintainer and I have been pinging on this patch
for more than 6 months, I'd like to get it enabled for Linux/x86
soon.

Uros, can I check in Linux/x86 version if there are no full feedbacks
from the rest of target maintainers for more than 48hours.  We can
enable other targets on a target by target basis later.

Thanks.


-- 
H.J.

[-- Attachment #2: gcc-pr46770-6a.patch --]
[-- Type: text/plain, Size: 13808 bytes --]

2011-06-19  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/46770
	* config.gcc (use_initfini_array): New variable.
	Use initfini-array.o if supported.

	* crtstuff.c: Don't generate .ctors nor .dtors sections if
	NO_CTORS_DTORS_SECTIONS is defined.

	* config/initfini-array.c: New.
	* config/initfini-array.h: Likewise.
	* config/t-initfini-array: Likewise.

	* config/arm/arm.c (arm_asm_init_sections): Call
	elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
	is defined.
	* config/avr/avr.c (avr_asm_init_sections): Likewise.
	* config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
	* config/mep/mep.c (mep_asm_init_sections): Likewise.
	* config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
	Likewise.
	* config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
	* config/stormy16/stormy16.c (xstormy16_asm_init_sections):
	Likewise.
	* config/v850/v850.c (v850_asm_init_sections): Likewise.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 2cf92d2..e8aed1c 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -186,6 +186,9 @@
 #  configure_default_options
 #			Set to an initializer for configure_default_options
 #			in configargs.h, based on --with-cpu et cetera.
+#
+#  use_initfini_array	If set to yes, .init_array/.fini_array sections
+#			will be used if they work.
 
 # The following variables are used in each case-construct to build up the
 # outgoing variables:
@@ -238,6 +241,7 @@ default_gnu_indirect_function=no
 target_gtfiles=
 need_64bit_hwint=
 need_64bit_isa=
+use_initfini_array=yes
 
 # Don't carry these over build->host->target.  Please.
 xm_file=
@@ -3046,6 +3050,16 @@ if test x$with_schedule = x; then
 	esac
 fi
 
+# Support --enable-initfini-array.  Use initfini-array.h only if
+# use_initfini_array is also set to yes.  Some platforms don't need it
+# even if enable_initfini_array is yes.
+if test x$enable_initfini_array$use_initfini_array = xyesyes; then
+  tm_file="${tm_file} initfini-array.h"
+  tmake_file="${tmake_file} t-initfini-array"
+  extra_objs="$extra_objs initfini-array.o"
+  target_gtfiles="$target_gtfiles \$(srcdir)/config/initfini-array.c"
+fi
+
 # Validate and mark as valid any --with options supported
 # by this target.  In order to use a particular --with option
 # you must list it in supported_defaults; validating the value
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 547acc8..7b7308f 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -22833,6 +22833,9 @@ arm_asm_init_sections (void)
 {
   exception_section = get_unnamed_section (0, output_section_asm_op,
 					   "\t.handlerdata");
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 #endif /* ARM_UNWIND_INFO */
 
diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c
index e46ccd3..fd78e49 100644
--- a/gcc/config/avr/avr.c
+++ b/gcc/config/avr/avr.c
@@ -5271,6 +5271,10 @@ avr_asm_init_sections (void)
 					 NULL);
   readonly_data_section = data_section;
 
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
+
   data_section->unnamed.callback = avr_output_data_section_asm_op;
   bss_section->unnamed.callback = avr_output_bss_section_asm_op;
 }
diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
index 78d2441..e66f8b1 100644
--- a/gcc/config/ia64/ia64.c
+++ b/gcc/config/ia64/ia64.c
@@ -10045,6 +10045,9 @@ ia64_asm_init_sections (void)
 {
   exception_section = get_unnamed_section (0, output_section_asm_op,
 					   "\t.handlerdata");
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 
 /* Implement TARGET_DEBUG_UNWIND_INFO.  */
diff --git a/gcc/config/initfini-array.c b/gcc/config/initfini-array.c
new file mode 100644
index 0000000..c042769
--- /dev/null
+++ b/gcc/config/initfini-array.c
@@ -0,0 +1,80 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "target.h"
+#include "output.h"
+#include "tree.h"
+#include "initfini-array.h"
+#include "ggc.h"
+
+static GTY(()) section *init_array_section;
+static GTY(()) section *fini_array_section;
+
+void
+elf_initfini_array_init_sections (void)
+{
+  init_array_section = get_unnamed_section (0, output_section_asm_op,
+					    "\t.section\t.init_array");
+  fini_array_section = get_unnamed_section (0, output_section_asm_op,
+					    "\t.section\t.fini_array");
+}
+
+static section *
+get_elf_initfini_array_priority_section (int priority,
+					 bool constructor_p)
+{
+  section *sec;
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      char buf[18];
+      sprintf (buf, "%s.%.5u", 
+	       constructor_p ? ".init_array" : ".fini_array",
+	       priority);
+      sec = get_section (buf, SECTION_WRITE, NULL_TREE);
+    }
+  else
+    sec = constructor_p ? init_array_section : fini_array_section;
+  return sec;
+}
+
+/* Use .init_array section for constructors. */
+
+void
+elf_init_array_asm_out_constructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  true);
+  assemble_addr_to_section (symbol, sec);
+}
+
+/* Use .fini_array section for destructors. */
+
+void
+elf_fini_array_asm_out_destructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  false);
+  assemble_addr_to_section (symbol, sec);
+}
+
+#include "gt-initfini-array.h"
diff --git a/gcc/config/initfini-array.h b/gcc/config/initfini-array.h
new file mode 100644
index 0000000..cba7eca
--- /dev/null
+++ b/gcc/config/initfini-array.h
@@ -0,0 +1,46 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   support.
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+/* No need for .ctors/.dtors section since linker can place them in
+   .init_array/.fini_array section.  */
+#define NO_CTORS_DTORS_SECTIONS
+
+#undef INIT_SECTION_ASM_OP
+#undef FINI_SECTION_ASM_OP
+
+/* FIXME: INIT_ARRAY_SECTION_ASM_OP and FINI_ARRAY_SECTION_ASM_OP
+	  aren't used in any assembly codes.  But we have to define
+	  them to something.  */
+#define INIT_ARRAY_SECTION_ASM_OP Something
+#define FINI_ARRAY_SECTION_ASM_OP Something
+
+#ifndef TARGET_ASM_INIT_SECTIONS
+#define TARGET_ASM_INIT_SECTIONS elf_initfini_array_init_sections
+#endif
+extern void elf_initfini_array_init_sections (void);
+
+/* Use .init_array/.fini_array section for constructors and destructors. */
+#undef TARGET_ASM_CONSTRUCTOR
+#define TARGET_ASM_CONSTRUCTOR elf_init_array_asm_out_constructor
+#undef TARGET_ASM_DESTRUCTOR
+#define TARGET_ASM_DESTRUCTOR elf_fini_array_asm_out_destructor
+extern void elf_init_array_asm_out_constructor (rtx, int);
+extern void elf_fini_array_asm_out_destructor (rtx, int);
diff --git a/gcc/config/mep/mep.c b/gcc/config/mep/mep.c
index a946c93..cdfd29a 100644
--- a/gcc/config/mep/mep.c
+++ b/gcc/config/mep/mep.c
@@ -7341,6 +7341,9 @@ mep_asm_init_sections (void)
     = get_unnamed_section (SECTION_CODE, output_section_asm_op,
 			   "\t.section .ftext,\"ax\"\n\t.core");
 
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 \f
 /* Initialize the GCC target structure.  */
diff --git a/gcc/config/microblaze/microblaze.c b/gcc/config/microblaze/microblaze.c
index 288b86f..6b77e4a 100644
--- a/gcc/config/microblaze/microblaze.c
+++ b/gcc/config/microblaze/microblaze.c
@@ -2753,6 +2753,9 @@ microblaze_elf_asm_init_sections (void)
   sdata2_section
     = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
 			   SDATA2_SECTION_ASM_OP);
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 
 /*  Generate assembler code for constant parts of a trampoline.  */
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index c15c04e..83968f9 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -24828,6 +24828,10 @@ rs6000_elf_asm_init_sections (void)
   sdata2_section
     = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
 			   SDATA2_SECTION_ASM_OP);
+
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 
 /* Implement TARGET_SELECT_RTX_SECTION.  */
diff --git a/gcc/config/stormy16/stormy16.c b/gcc/config/stormy16/stormy16.c
index 9796528..b194b44 100644
--- a/gcc/config/stormy16/stormy16.c
+++ b/gcc/config/stormy16/stormy16.c
@@ -1573,6 +1573,9 @@ xstormy16_asm_init_sections (void)
     = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
 			   output_section_asm_op,
 			   "\t.section \".bss_below100\",\"aw\",@nobits");
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 
 /* Mark symbols with the "below100" attribute so that we can use the
diff --git a/gcc/config/t-initfini-array b/gcc/config/t-initfini-array
new file mode 100644
index 0000000..3824ed4
--- /dev/null
+++ b/gcc/config/t-initfini-array
@@ -0,0 +1,23 @@
+# Copyright (C) 2011
+# 2009 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+initfini-array.o: $(srcdir)/config/initfini-array.c gt-initfini-array.h \
+	$(CONFIG_H) $(SYSTEM_H) coretypes.h $(TARGET_H) output.h \
+	$(TREE_H) $(GGC_H)
+	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
diff --git a/gcc/config/v850/v850.c b/gcc/config/v850/v850.c
index 5074ebe..4e7872a 100644
--- a/gcc/config/v850/v850.c
+++ b/gcc/config/v850/v850.c
@@ -2900,6 +2900,10 @@ v850_asm_init_sections (void)
     = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
 			   output_section_asm_op,
 			   "\t.section .zbss,\"aw\"");
+
+#ifdef NO_CTORS_DTORS_SECTIONS
+  elf_initfini_array_init_sections ();
+#endif
 }
 
 static section *
diff --git a/gcc/crtstuff.c b/gcc/crtstuff.c
index b65f490..bccf44d 100644
--- a/gcc/crtstuff.c
+++ b/gcc/crtstuff.c
@@ -1,7 +1,8 @@
 /* Specialized bits of code needed to support construction and
    destruction of file-scope objects in C++ code.
    Copyright (C) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
+   Free Software Foundation, Inc.
    Contributed by Ron Guilmette (rfg@monkeys.com).
 
 This file is part of GCC.
@@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
    refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
    symbol in crtbegin.o, where they are defined.  */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef NO_CTORS_DTORS_SECTIONS
 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
    does not start with a count of elements.  */
 #ifdef CTOR_LIST_BEGIN
@@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
   __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) (-1) };
 #endif /* __DTOR_LIST__ alternatives */
+#endif /* NO_CTORS_DTORS_SECTIONS */
 
 #ifdef USE_EH_FRAME_REGISTRY
 /* Stick a label at the beginning of the frame unwind info so we can register
@@ -489,6 +494,9 @@ __do_global_ctors_1(void)
 
 #elif defined(CRT_END) /* ! CRT_BEGIN */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef NO_CTORS_DTORS_SECTIONS
 /* Put a word containing zero at the end of each of our two lists of function
    addresses.  Note that the words defined here go into the .ctors and .dtors
    sections of the crtend.o file, and since that file is always linked in
@@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
   __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) 0 };
 #endif
+#endif /* NO_CTORS_DTORS_SECTIONS */
 
 #ifdef EH_FRAME_SECTION_NAME
 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;

[-- Attachment #3: gcc-pr46770-6b.patch --]
[-- Type: text/plain, Size: 9799 bytes --]

2011-06-19  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/46770
	* config.gcc (use_initfini_array): New variable.
	Use initfini-array.o for Linux/x86 if supported.

	* crtstuff.c: Don't generate .ctors nor .dtors sections if
	NO_CTORS_DTORS_SECTIONS is defined.

	* config/initfini-array.c: New.
	* config/initfini-array.h: Likewise.
	* config/t-initfini-array: Likewise.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 2cf92d2..e0a253d 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -186,6 +186,9 @@
 #  configure_default_options
 #			Set to an initializer for configure_default_options
 #			in configargs.h, based on --with-cpu et cetera.
+#
+#  use_initfini_array	If set to yes, .init_array/.fini_array sections
+#			will be used if they work.
 
 # The following variables are used in each case-construct to build up the
 # outgoing variables:
@@ -238,6 +241,7 @@ default_gnu_indirect_function=no
 target_gtfiles=
 need_64bit_hwint=
 need_64bit_isa=
+use_initfini_array=
 
 # Don't carry these over build->host->target.  Please.
 xm_file=
@@ -2660,6 +2664,7 @@ esac
 case ${target} in
 i[34567]86-*-linux* | x86_64-*-linux*)
 	tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
+	use_initfini_array=yes
 	;;
 i[34567]86-*-* | x86_64-*-*)
 	tmake_file="${tmake_file} i386/t-gmm_malloc i386/t-i386"
@@ -3046,6 +3051,16 @@ if test x$with_schedule = x; then
 	esac
 fi
 
+# Support --enable-initfini-array.  Use initfini-array.h only if
+# use_initfini_array is also set to yes.  Some platforms don't need it
+# even if enable_initfini_array is yes.
+if test x$enable_initfini_array$use_initfini_array = xyesyes; then
+  tm_file="${tm_file} initfini-array.h"
+  tmake_file="${tmake_file} t-initfini-array"
+  extra_objs="$extra_objs initfini-array.o"
+  target_gtfiles="$target_gtfiles \$(srcdir)/config/initfini-array.c"
+fi
+
 # Validate and mark as valid any --with options supported
 # by this target.  In order to use a particular --with option
 # you must list it in supported_defaults; validating the value
diff --git a/gcc/config/initfini-array.c b/gcc/config/initfini-array.c
new file mode 100644
index 0000000..c042769
--- /dev/null
+++ b/gcc/config/initfini-array.c
@@ -0,0 +1,80 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "target.h"
+#include "output.h"
+#include "tree.h"
+#include "initfini-array.h"
+#include "ggc.h"
+
+static GTY(()) section *init_array_section;
+static GTY(()) section *fini_array_section;
+
+void
+elf_initfini_array_init_sections (void)
+{
+  init_array_section = get_unnamed_section (0, output_section_asm_op,
+					    "\t.section\t.init_array");
+  fini_array_section = get_unnamed_section (0, output_section_asm_op,
+					    "\t.section\t.fini_array");
+}
+
+static section *
+get_elf_initfini_array_priority_section (int priority,
+					 bool constructor_p)
+{
+  section *sec;
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      char buf[18];
+      sprintf (buf, "%s.%.5u", 
+	       constructor_p ? ".init_array" : ".fini_array",
+	       priority);
+      sec = get_section (buf, SECTION_WRITE, NULL_TREE);
+    }
+  else
+    sec = constructor_p ? init_array_section : fini_array_section;
+  return sec;
+}
+
+/* Use .init_array section for constructors. */
+
+void
+elf_init_array_asm_out_constructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  true);
+  assemble_addr_to_section (symbol, sec);
+}
+
+/* Use .fini_array section for destructors. */
+
+void
+elf_fini_array_asm_out_destructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  false);
+  assemble_addr_to_section (symbol, sec);
+}
+
+#include "gt-initfini-array.h"
diff --git a/gcc/config/initfini-array.h b/gcc/config/initfini-array.h
new file mode 100644
index 0000000..cba7eca
--- /dev/null
+++ b/gcc/config/initfini-array.h
@@ -0,0 +1,46 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   support.
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+/* No need for .ctors/.dtors section since linker can place them in
+   .init_array/.fini_array section.  */
+#define NO_CTORS_DTORS_SECTIONS
+
+#undef INIT_SECTION_ASM_OP
+#undef FINI_SECTION_ASM_OP
+
+/* FIXME: INIT_ARRAY_SECTION_ASM_OP and FINI_ARRAY_SECTION_ASM_OP
+	  aren't used in any assembly codes.  But we have to define
+	  them to something.  */
+#define INIT_ARRAY_SECTION_ASM_OP Something
+#define FINI_ARRAY_SECTION_ASM_OP Something
+
+#ifndef TARGET_ASM_INIT_SECTIONS
+#define TARGET_ASM_INIT_SECTIONS elf_initfini_array_init_sections
+#endif
+extern void elf_initfini_array_init_sections (void);
+
+/* Use .init_array/.fini_array section for constructors and destructors. */
+#undef TARGET_ASM_CONSTRUCTOR
+#define TARGET_ASM_CONSTRUCTOR elf_init_array_asm_out_constructor
+#undef TARGET_ASM_DESTRUCTOR
+#define TARGET_ASM_DESTRUCTOR elf_fini_array_asm_out_destructor
+extern void elf_init_array_asm_out_constructor (rtx, int);
+extern void elf_fini_array_asm_out_destructor (rtx, int);
diff --git a/gcc/config/t-initfini-array b/gcc/config/t-initfini-array
new file mode 100644
index 0000000..3824ed4
--- /dev/null
+++ b/gcc/config/t-initfini-array
@@ -0,0 +1,23 @@
+# Copyright (C) 2011
+# 2009 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+initfini-array.o: $(srcdir)/config/initfini-array.c gt-initfini-array.h \
+	$(CONFIG_H) $(SYSTEM_H) coretypes.h $(TARGET_H) output.h \
+	$(TREE_H) $(GGC_H)
+	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
diff --git a/gcc/crtstuff.c b/gcc/crtstuff.c
index b65f490..bccf44d 100644
--- a/gcc/crtstuff.c
+++ b/gcc/crtstuff.c
@@ -1,7 +1,8 @@
 /* Specialized bits of code needed to support construction and
    destruction of file-scope objects in C++ code.
    Copyright (C) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
+   Free Software Foundation, Inc.
    Contributed by Ron Guilmette (rfg@monkeys.com).
 
 This file is part of GCC.
@@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
    refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
    symbol in crtbegin.o, where they are defined.  */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef NO_CTORS_DTORS_SECTIONS
 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
    does not start with a count of elements.  */
 #ifdef CTOR_LIST_BEGIN
@@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
   __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) (-1) };
 #endif /* __DTOR_LIST__ alternatives */
+#endif /* NO_CTORS_DTORS_SECTIONS */
 
 #ifdef USE_EH_FRAME_REGISTRY
 /* Stick a label at the beginning of the frame unwind info so we can register
@@ -489,6 +494,9 @@ __do_global_ctors_1(void)
 
 #elif defined(CRT_END) /* ! CRT_BEGIN */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef NO_CTORS_DTORS_SECTIONS
 /* Put a word containing zero at the end of each of our two lists of function
    addresses.  Note that the words defined here go into the .ctors and .dtors
    sections of the crtend.o file, and since that file is always linked in
@@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
   __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) 0 };
 #endif
+#endif /* NO_CTORS_DTORS_SECTIONS */
 
 #ifdef EH_FRAME_SECTION_NAME
 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-06-19 20:02             ` H.J. Lu
@ 2011-06-19 21:31               ` Uros Bizjak
  2011-07-22 12:31                 ` H.J. Lu
  2011-07-01 14:12               ` H.J. Lu
  1 sibling, 1 reply; 46+ messages in thread
From: Uros Bizjak @ 2011-06-19 21:31 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Richard Guenther, GCC Patches

On Sun, Jun 19, 2011 at 8:39 PM, H.J. Lu <hjl.tools@gmail.com> wrote:

>>> I can't approve the configury changes and would like to defer
>>> to target maintainers for the target specific changes.  That said,
>>> I'm not familiar enough with the area of the patch.  But yes,
>>> it's stage1 now - so if anyone else wants to approve this patch...
>>
>> My first attempt:
>>
>> http://gcc.gnu.org/ml/gcc-patches/2010-12/msg00589.html
>>
>> only affects x86.  I changed it to generic based on the
>> feedbacks.  But other target maintainers show no interests.
>> Should I make it x86 only first?  Each target can enable it
>> if needed.
>>
>
> I am enclosing 2 patches here.  One only affects Linux/x86
> and the other covers all targets.  I tested both versions on
> Linux/x86 without any regressions.  Since I only got OK from
> one target maintainer and I have been pinging on this patch
> for more than 6 months, I'd like to get it enabled for Linux/x86
> soon.
>
> Uros, can I check in Linux/x86 version if there are no full feedbacks
> from the rest of target maintainers for more than 48hours.  We can
> enable other targets on a target by target basis later.

Sorry, but I don't feel confident enough to review the patch in this
part of the compiler. I would prefer if somebody else approves it.

Uros.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-06-19 20:02             ` H.J. Lu
  2011-06-19 21:31               ` Uros Bizjak
@ 2011-07-01 14:12               ` H.J. Lu
  1 sibling, 0 replies; 46+ messages in thread
From: H.J. Lu @ 2011-07-01 14:12 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: GCC Patches

On Sun, Jun 19, 2011 at 11:39 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Jun 3, 2011 at 5:51 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Fri, Jun 3, 2011 at 5:31 AM, Richard Guenther
>> <richard.guenther@gmail.com> wrote:
>>> On Fri, Jun 3, 2011 at 6:31 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Wed, May 18, 2011 at 8:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Tue, Apr 26, 2011 at 6:05 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>> On Thu, Mar 31, 2011 at 7:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>>> On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>>>> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>>>>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther
>>>>>>>>> <richard.guenther@gmail.com> wrote:
>>>>>>>>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>>>>>>>> On Tue, Dec 14, 2010 at 05:20:48PM -0800, H.J. Lu wrote:
>>>>>>>>>>>> This patch uses .init_array/.fini_array sections instead of
>>>>>>>>>>>> .ctors/.dtors sections if mixing .init_array/.fini_array and
>>>>>>>>>>>> .ctors/.dtors sections with init_priority works.
>>>>>>>>>>>>
>>>>>>>>>>>> It removes .ctors/.ctors sections from executables and DSOes, which will
>>>>>>>>>>>> remove one function call at startup time from each executable and DSO.
>>>>>>>>>>>> It should reduce image size and improve system startup time.
>>>>>>>>>>>>
>>>>>>>>>>>> If a platform with a working .init_array/.fini_array support needs a
>>>>>>>>>>>> different .init_array/.fini_array implementation, it can set
>>>>>>>>>>>> use_initfini_array to no.
>>>>>>>>>>>>
>>>>>>>>>>>> Since .init_array/.fini_array is a target feature. --enable-initfini-array
>>>>>>>>>>>> is default to no unless the native run-time test is passed.
>>>>>>>>>>>>
>>>>>>>>>>>> To pass the native run-time test, a linker with SORT_BY_INIT_PRIORITY
>>>>>>>>>>>> support is required.  The binutils patch is available at
>>>>>>>>>>>>
>>>>>>>>>>>> http://sourceware.org/ml/binutils/2010-12/msg00466.html
>>>>>>>>>>>
>>>>>>>>>>> Linker patch has been checked in.
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> This patch passed 32bit/64bit regression test on Linux/x86-64.  Any
>>>>>>>>>>>> comments?
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> This updated patch fixes build on Linux/ia64 and should work on others.
>>>>>>>>>>> Any comments?
>>>>>>>>>>
>>>>>>>>>> Yes.  This is stage1 material.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Here is the updated patch.  OK for trunk?
>>>>>>>>>
>>>>>>>>> Thanks.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> H.J.
>>>>>>>>> ----
>>>>>>>>> 2011-03-14  H.J. Lu  <hongjiu.lu@intel.com>
>>>>>>>>>
>>>>>>>>>        PR target/46770
>>>>>>>>>        * acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed.
>>>>>>>>>
>>>>>>>>>        * config.gcc (use_initfini_array): New variable.
>>>>>>>>>        Use initfini-array.o if supported.
>>>>>>>>>
>>>>>>>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>>>>>>>        NO_CTORS_DTORS_SECTIONS is defined.
>>>>>>>>>
>>>>>>>>>        * configure.ac: Remove gcc_AC_INITFINI_ARRAY.  Add
>>>>>>>>>        --enable-initfini-array and check if .init_array can be used with
>>>>>>>>>        .ctors.
>>>>>>>>>
>>>>>>>>>        * configure: Regenerated.
>>>>>>>>>
>>>>>>>>>        * config/initfini-array.c: New.
>>>>>>>>>        * config/initfini-array.h: Likewise.
>>>>>>>>>        * config/t-initfini-array: Likewise.
>>>>>>>>>
>>>>>>>>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>>>>>>>>        elf_initfini_array_init_sections if NO_CTORS_DTORS_SECTIONS
>>>>>>>>>        is defined.
>>>>>>>>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>>>>>>>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>>>>>>>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>>>>>>>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>>>>>>>>        Likewise.
>>>>>>>>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>>>>>>>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>>>>>>>>        Likewise.
>>>>>>>>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>>>>>>>>
>>>>>>>>
>>>>>>>> PING:
>>>>>>>>
>>>>>>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>>>>>>>
>>>>>>>
>>>>>>> Any comments?  Any objections?
>>>>>>>
>>>>>>
>>>>>> Here is the patch updated for the current trunk.  OK for trunk?
>>>>>>
>>>>>
>>>>> PING,.
>>>>
>>>> Hi Richard,
>>>>
>>>> You commented my patch was stage 1 material:
>>>>
>>>> http://gcc.gnu.org/ml/gcc-patches/2011-01/msg01989.html
>>>>
>>>> Is my patch:
>>>>
>>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00760.html
>>>>
>>>> OK for trunk?
>>>
>>> I can't approve the configury changes and would like to defer
>>> to target maintainers for the target specific changes.  That said,
>>> I'm not familiar enough with the area of the patch.  But yes,
>>> it's stage1 now - so if anyone else wants to approve this patch...
>>
>> My first attempt:
>>
>> http://gcc.gnu.org/ml/gcc-patches/2010-12/msg00589.html
>>
>> only affects x86.  I changed it to generic based on the
>> feedbacks.  But other target maintainers show no interests.
>> Should I make it x86 only first?  Each target can enable it
>> if needed.
>>
>
> I am enclosing 2 patches here.  One only affects Linux/x86
> and the other covers all targets.  I tested both versions on
> Linux/x86 without any regressions.  Since I only got OK from
> one target maintainer and I have been pinging on this patch
> for more than 6 months, I'd like to get it enabled for Linux/x86
> soon.
>

Hi Ian,

I'd like to get this issue resolved, at least for Linux/x86. Can you
recommend how I should proceed?

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-06-19 21:31               ` Uros Bizjak
@ 2011-07-22 12:31                 ` H.J. Lu
  2011-07-22 12:36                   ` Rainer Orth
  2011-07-22 12:37                   ` Jakub Jelinek
  0 siblings, 2 replies; 46+ messages in thread
From: H.J. Lu @ 2011-07-22 12:31 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1895 bytes --]

On Sun, Jun 19, 2011 at 1:01 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Sun, Jun 19, 2011 at 8:39 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>
>>>> I can't approve the configury changes and would like to defer
>>>> to target maintainers for the target specific changes.  That said,
>>>> I'm not familiar enough with the area of the patch.  But yes,
>>>> it's stage1 now - so if anyone else wants to approve this patch...
>>>
>>> My first attempt:
>>>
>>> http://gcc.gnu.org/ml/gcc-patches/2010-12/msg00589.html
>>>
>>> only affects x86.  I changed it to generic based on the
>>> feedbacks.  But other target maintainers show no interests.
>>> Should I make it x86 only first?  Each target can enable it
>>> if needed.
>>>
>>
>> I am enclosing 2 patches here.  One only affects Linux/x86
>> and the other covers all targets.  I tested both versions on
>> Linux/x86 without any regressions.  Since I only got OK from
>> one target maintainer and I have been pinging on this patch
>> for more than 6 months, I'd like to get it enabled for Linux/x86
>> soon.
>>
>> Uros, can I check in Linux/x86 version if there are no full feedbacks
>> from the rest of target maintainers for more than 48hours.  We can
>> enable other targets on a target by target basis later.
>
> Sorry, but I don't feel confident enough to review the patch in this
> part of the compiler. I would prefer if somebody else approves it.
>

Hi Jakub,

Can you review this change?

Thanks.

-- 
H.J.
----
2011-06-19  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/46770
	* config.gcc (use_initfini_array): New variable.
	Use initfini-array.o for Linux/x86 if supported.

	* crtstuff.c: Don't generate .ctors nor .dtors sections if
	NO_CTORS_DTORS_SECTIONS is defined.

	* config/initfini-array.c: New.
	* config/initfini-array.h: Likewise.
	* config/t-initfini-array: Likewise.

[-- Attachment #2: gcc-pr46770-6b.patch --]
[-- Type: text/plain, Size: 9799 bytes --]

2011-06-19  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/46770
	* config.gcc (use_initfini_array): New variable.
	Use initfini-array.o for Linux/x86 if supported.

	* crtstuff.c: Don't generate .ctors nor .dtors sections if
	NO_CTORS_DTORS_SECTIONS is defined.

	* config/initfini-array.c: New.
	* config/initfini-array.h: Likewise.
	* config/t-initfini-array: Likewise.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 2cf92d2..e0a253d 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -186,6 +186,9 @@
 #  configure_default_options
 #			Set to an initializer for configure_default_options
 #			in configargs.h, based on --with-cpu et cetera.
+#
+#  use_initfini_array	If set to yes, .init_array/.fini_array sections
+#			will be used if they work.
 
 # The following variables are used in each case-construct to build up the
 # outgoing variables:
@@ -238,6 +241,7 @@ default_gnu_indirect_function=no
 target_gtfiles=
 need_64bit_hwint=
 need_64bit_isa=
+use_initfini_array=
 
 # Don't carry these over build->host->target.  Please.
 xm_file=
@@ -2660,6 +2664,7 @@ esac
 case ${target} in
 i[34567]86-*-linux* | x86_64-*-linux*)
 	tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
+	use_initfini_array=yes
 	;;
 i[34567]86-*-* | x86_64-*-*)
 	tmake_file="${tmake_file} i386/t-gmm_malloc i386/t-i386"
@@ -3046,6 +3051,16 @@ if test x$with_schedule = x; then
 	esac
 fi
 
+# Support --enable-initfini-array.  Use initfini-array.h only if
+# use_initfini_array is also set to yes.  Some platforms don't need it
+# even if enable_initfini_array is yes.
+if test x$enable_initfini_array$use_initfini_array = xyesyes; then
+  tm_file="${tm_file} initfini-array.h"
+  tmake_file="${tmake_file} t-initfini-array"
+  extra_objs="$extra_objs initfini-array.o"
+  target_gtfiles="$target_gtfiles \$(srcdir)/config/initfini-array.c"
+fi
+
 # Validate and mark as valid any --with options supported
 # by this target.  In order to use a particular --with option
 # you must list it in supported_defaults; validating the value
diff --git a/gcc/config/initfini-array.c b/gcc/config/initfini-array.c
new file mode 100644
index 0000000..c042769
--- /dev/null
+++ b/gcc/config/initfini-array.c
@@ -0,0 +1,80 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "target.h"
+#include "output.h"
+#include "tree.h"
+#include "initfini-array.h"
+#include "ggc.h"
+
+static GTY(()) section *init_array_section;
+static GTY(()) section *fini_array_section;
+
+void
+elf_initfini_array_init_sections (void)
+{
+  init_array_section = get_unnamed_section (0, output_section_asm_op,
+					    "\t.section\t.init_array");
+  fini_array_section = get_unnamed_section (0, output_section_asm_op,
+					    "\t.section\t.fini_array");
+}
+
+static section *
+get_elf_initfini_array_priority_section (int priority,
+					 bool constructor_p)
+{
+  section *sec;
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      char buf[18];
+      sprintf (buf, "%s.%.5u", 
+	       constructor_p ? ".init_array" : ".fini_array",
+	       priority);
+      sec = get_section (buf, SECTION_WRITE, NULL_TREE);
+    }
+  else
+    sec = constructor_p ? init_array_section : fini_array_section;
+  return sec;
+}
+
+/* Use .init_array section for constructors. */
+
+void
+elf_init_array_asm_out_constructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  true);
+  assemble_addr_to_section (symbol, sec);
+}
+
+/* Use .fini_array section for destructors. */
+
+void
+elf_fini_array_asm_out_destructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  false);
+  assemble_addr_to_section (symbol, sec);
+}
+
+#include "gt-initfini-array.h"
diff --git a/gcc/config/initfini-array.h b/gcc/config/initfini-array.h
new file mode 100644
index 0000000..cba7eca
--- /dev/null
+++ b/gcc/config/initfini-array.h
@@ -0,0 +1,46 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   support.
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+/* No need for .ctors/.dtors section since linker can place them in
+   .init_array/.fini_array section.  */
+#define NO_CTORS_DTORS_SECTIONS
+
+#undef INIT_SECTION_ASM_OP
+#undef FINI_SECTION_ASM_OP
+
+/* FIXME: INIT_ARRAY_SECTION_ASM_OP and FINI_ARRAY_SECTION_ASM_OP
+	  aren't used in any assembly codes.  But we have to define
+	  them to something.  */
+#define INIT_ARRAY_SECTION_ASM_OP Something
+#define FINI_ARRAY_SECTION_ASM_OP Something
+
+#ifndef TARGET_ASM_INIT_SECTIONS
+#define TARGET_ASM_INIT_SECTIONS elf_initfini_array_init_sections
+#endif
+extern void elf_initfini_array_init_sections (void);
+
+/* Use .init_array/.fini_array section for constructors and destructors. */
+#undef TARGET_ASM_CONSTRUCTOR
+#define TARGET_ASM_CONSTRUCTOR elf_init_array_asm_out_constructor
+#undef TARGET_ASM_DESTRUCTOR
+#define TARGET_ASM_DESTRUCTOR elf_fini_array_asm_out_destructor
+extern void elf_init_array_asm_out_constructor (rtx, int);
+extern void elf_fini_array_asm_out_destructor (rtx, int);
diff --git a/gcc/config/t-initfini-array b/gcc/config/t-initfini-array
new file mode 100644
index 0000000..3824ed4
--- /dev/null
+++ b/gcc/config/t-initfini-array
@@ -0,0 +1,23 @@
+# Copyright (C) 2011
+# 2009 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+initfini-array.o: $(srcdir)/config/initfini-array.c gt-initfini-array.h \
+	$(CONFIG_H) $(SYSTEM_H) coretypes.h $(TARGET_H) output.h \
+	$(TREE_H) $(GGC_H)
+	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
diff --git a/gcc/crtstuff.c b/gcc/crtstuff.c
index b65f490..bccf44d 100644
--- a/gcc/crtstuff.c
+++ b/gcc/crtstuff.c
@@ -1,7 +1,8 @@
 /* Specialized bits of code needed to support construction and
    destruction of file-scope objects in C++ code.
    Copyright (C) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
+   Free Software Foundation, Inc.
    Contributed by Ron Guilmette (rfg@monkeys.com).
 
 This file is part of GCC.
@@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
    refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
    symbol in crtbegin.o, where they are defined.  */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef NO_CTORS_DTORS_SECTIONS
 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
    does not start with a count of elements.  */
 #ifdef CTOR_LIST_BEGIN
@@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
   __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) (-1) };
 #endif /* __DTOR_LIST__ alternatives */
+#endif /* NO_CTORS_DTORS_SECTIONS */
 
 #ifdef USE_EH_FRAME_REGISTRY
 /* Stick a label at the beginning of the frame unwind info so we can register
@@ -489,6 +494,9 @@ __do_global_ctors_1(void)
 
 #elif defined(CRT_END) /* ! CRT_BEGIN */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef NO_CTORS_DTORS_SECTIONS
 /* Put a word containing zero at the end of each of our two lists of function
    addresses.  Note that the words defined here go into the .ctors and .dtors
    sections of the crtend.o file, and since that file is always linked in
@@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
   __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) 0 };
 #endif
+#endif /* NO_CTORS_DTORS_SECTIONS */
 
 #ifdef EH_FRAME_SECTION_NAME
 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-07-22 12:31                 ` H.J. Lu
@ 2011-07-22 12:36                   ` Rainer Orth
  2011-07-22 12:36                     ` H.J. Lu
  2011-07-22 12:37                   ` Jakub Jelinek
  1 sibling, 1 reply; 46+ messages in thread
From: Rainer Orth @ 2011-07-22 12:36 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jakub Jelinek, GCC Patches, Joseph S. Myers

H.J.,

> Can you review this change?

as you know, I'm currently working to move all libgcc-related stuff over
to toplevel libgcc.  Can you please move all but the crtstuff.c part of
this patch over to libgcc instead?

I've got a patch almost ready to move crtstuff.c and other crt files,
and would like not to adapt this new code if you can just as well start
in libgcc.

Thanks.
        Rainer

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

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-07-22 12:36                   ` Rainer Orth
@ 2011-07-22 12:36                     ` H.J. Lu
  2011-07-22 13:20                       ` Rainer Orth
  0 siblings, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-07-22 12:36 UTC (permalink / raw)
  To: Rainer Orth; +Cc: Jakub Jelinek, GCC Patches, Joseph S. Myers

On Fri, Jul 22, 2011 at 5:22 AM, Rainer Orth
<ro@cebitec.uni-bielefeld.de> wrote:
> H.J.,
>
>> Can you review this change?
>
> as you know, I'm currently working to move all libgcc-related stuff over
> to toplevel libgcc.  Can you please move all but the crtstuff.c part of
> this patch over to libgcc instead?
>
> I've got a patch almost ready to move crtstuff.c and other crt files,
> and would like not to adapt this new code if you can just as well start
> in libgcc.
>

Most of this change isn't related to libgcc, except for crtstuff.c.  You
just need to find a way to define NO_CTORS_DTORS_SECTIONS
in libgcc when .init_array is used.

-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-07-22 12:31                 ` H.J. Lu
  2011-07-22 12:36                   ` Rainer Orth
@ 2011-07-22 12:37                   ` Jakub Jelinek
  2011-07-22 13:21                     ` Joseph S. Myers
  2011-07-22 13:29                     ` H.J. Lu
  1 sibling, 2 replies; 46+ messages in thread
From: Jakub Jelinek @ 2011-07-22 12:37 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches

On Fri, Jul 22, 2011 at 04:59:28AM -0700, H.J. Lu wrote:
> @@ -2660,6 +2664,7 @@ esac
>  case ${target} in
>  i[34567]86-*-linux* | x86_64-*-linux*)
>  	tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
> +	use_initfini_array=yes
>  	;;
>  i[34567]86-*-* | x86_64-*-*)
>  	tmake_file="${tmake_file} i386/t-gmm_malloc i386/t-i386"

What is i?86/x86_64 specific on it?  Don't most other glibc targets
want to use it too, perhaps with some arch specific tweaks?

> --- /dev/null
> +++ b/gcc/config/initfini-array.c

This is ugly.  varasm.c already has lots of ELF specific code, simply
put them there as well and only let configury set some macro which will
allow targets to choose which of the implementations in the generic code
they want to use (or if they want their own which e.g. calls the generic
routine and does something additional to it etc.).  The sections probably
can be created only the first time you actually need them.

> --- a/gcc/crtstuff.c
> +++ b/gcc/crtstuff.c
> @@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
>     refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
>     symbol in crtbegin.o, where they are defined.  */
>  
> +/* No need for .ctors/.dtors section if linker can place them in
> +   .init_array/.fini_array section.  */
> +#ifndef NO_CTORS_DTORS_SECTIONS
>  /* The -1 is a flag to __do_global_[cd]tors indicating that this table
>     does not start with a count of elements.  */
>  #ifdef CTOR_LIST_BEGIN
> @@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
>    __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
>    = { (func_ptr) (-1) };
>  #endif /* __DTOR_LIST__ alternatives */
> +#endif /* NO_CTORS_DTORS_SECTIONS */
>  
>  #ifdef USE_EH_FRAME_REGISTRY
>  /* Stick a label at the beginning of the frame unwind info so we can register
> @@ -489,6 +494,9 @@ __do_global_ctors_1(void)
>  
>  #elif defined(CRT_END) /* ! CRT_BEGIN */
>  
> +/* No need for .ctors/.dtors section if linker can place them in
> +   .init_array/.fini_array section.  */
> +#ifndef NO_CTORS_DTORS_SECTIONS
>  /* Put a word containing zero at the end of each of our two lists of function
>     addresses.  Note that the words defined here go into the .ctors and .dtors
>     sections of the crtend.o file, and since that file is always linked in
> @@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
>    __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
>    = { (func_ptr) 0 };
>  #endif
> +#endif /* NO_CTORS_DTORS_SECTIONS */
>  
>  #ifdef EH_FRAME_SECTION_NAME
>  /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;

I don't see how you can do this.  It would IMO break any time you link code
built by different gcc versions where some code emitted by the older gcc
used .ctors or .dtors.

	Jakub

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-07-22 12:36                     ` H.J. Lu
@ 2011-07-22 13:20                       ` Rainer Orth
  0 siblings, 0 replies; 46+ messages in thread
From: Rainer Orth @ 2011-07-22 13:20 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jakub Jelinek, GCC Patches, Joseph S. Myers

H.J.

> Most of this change isn't related to libgcc, except for crtstuff.c.  You
> just need to find a way to define NO_CTORS_DTORS_SECTIONS
> in libgcc when .init_array is used.

sorry, I misread: initfini-array.o goes into extra_objs, not
extra_parts.

	Rainer

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

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-07-22 12:37                   ` Jakub Jelinek
@ 2011-07-22 13:21                     ` Joseph S. Myers
  2011-07-22 13:29                     ` H.J. Lu
  1 sibling, 0 replies; 46+ messages in thread
From: Joseph S. Myers @ 2011-07-22 13:21 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: H.J. Lu, GCC Patches

On Fri, 22 Jul 2011, Jakub Jelinek wrote:

> On Fri, Jul 22, 2011 at 04:59:28AM -0700, H.J. Lu wrote:
> > @@ -2660,6 +2664,7 @@ esac
> >  case ${target} in
> >  i[34567]86-*-linux* | x86_64-*-linux*)
> >  	tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
> > +	use_initfini_array=yes
> >  	;;
> >  i[34567]86-*-* | x86_64-*-*)
> >  	tmake_file="${tmake_file} i386/t-gmm_malloc i386/t-i386"
> 
> What is i?86/x86_64 specific on it?  Don't most other glibc targets
> want to use it too, perhaps with some arch specific tweaks?

I already said in the PR that it should be enabled by default for all ELF 
targets except any for which it proves necessary to disable it.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-07-22 12:37                   ` Jakub Jelinek
  2011-07-22 13:21                     ` Joseph S. Myers
@ 2011-07-22 13:29                     ` H.J. Lu
  2011-07-22 14:17                       ` H.J. Lu
  1 sibling, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-07-22 13:29 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

On Fri, Jul 22, 2011 at 5:30 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Fri, Jul 22, 2011 at 04:59:28AM -0700, H.J. Lu wrote:
>> @@ -2660,6 +2664,7 @@ esac
>>  case ${target} in
>>  i[34567]86-*-linux* | x86_64-*-linux*)
>>       tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
>> +     use_initfini_array=yes
>>       ;;
>>  i[34567]86-*-* | x86_64-*-*)
>>       tmake_file="${tmake_file} i386/t-gmm_malloc i386/t-i386"
>
> What is i?86/x86_64 specific on it?  Don't most other glibc targets
> want to use it too, perhaps with some arch specific tweaks?

I do have a patch for all ELF targets:

http://gcc.gnu.org/ml/gcc-patches/2011-06/msg01416.html

It touches many targets. .  But I only have one feedback from one
target maintainer.  I don't know how long it will take to review it.


>> --- /dev/null
>> +++ b/gcc/config/initfini-array.c
>
> This is ugly.  varasm.c already has lots of ELF specific code, simply
> put them there as well and only let configury set some macro which will
> allow targets to choose which of the implementations in the generic code
> they want to use (or if they want their own which e.g. calls the generic
> routine and does something additional to it etc.).  The sections probably
> can be created only the first time you actually need them.

I will do that.

>> --- a/gcc/crtstuff.c
>> +++ b/gcc/crtstuff.c
>> @@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
>>     refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
>>     symbol in crtbegin.o, where they are defined.  */
>>
>> +/* No need for .ctors/.dtors section if linker can place them in
>> +   .init_array/.fini_array section.  */
>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>  /* The -1 is a flag to __do_global_[cd]tors indicating that this table
>>     does not start with a count of elements.  */
>>  #ifdef CTOR_LIST_BEGIN
>> @@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
>>    __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
>>    = { (func_ptr) (-1) };
>>  #endif /* __DTOR_LIST__ alternatives */
>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>
>>  #ifdef USE_EH_FRAME_REGISTRY
>>  /* Stick a label at the beginning of the frame unwind info so we can register
>> @@ -489,6 +494,9 @@ __do_global_ctors_1(void)
>>
>>  #elif defined(CRT_END) /* ! CRT_BEGIN */
>>
>> +/* No need for .ctors/.dtors section if linker can place them in
>> +   .init_array/.fini_array section.  */
>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>  /* Put a word containing zero at the end of each of our two lists of function
>>     addresses.  Note that the words defined here go into the .ctors and .dtors
>>     sections of the crtend.o file, and since that file is always linked in
>> @@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
>>    __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
>>    = { (func_ptr) 0 };
>>  #endif
>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>
>>  #ifdef EH_FRAME_SECTION_NAME
>>  /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
>
> I don't see how you can do this.  It would IMO break any time you link code
> built by different gcc versions where some code emitted by the older gcc
> used .ctors or .dtors.

crtstuff.c is used to generate crt*.o, which is the part of GCC.  You only use
it with the GCC you are using.  Since your GCC doesn't put anything in
.ctors/.dtors section, you don't need them.  As for .o files generated by
old GCCs, that is the linker test, use_initfini_array, is for.  The newer linker
can put input .ctors/.dtors sections in output .init_array/,fini_array sections.


-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-07-22 13:29                     ` H.J. Lu
@ 2011-07-22 14:17                       ` H.J. Lu
  2011-07-22 14:55                         ` H.J. Lu
  0 siblings, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-07-22 14:17 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 5176 bytes --]

On Fri, Jul 22, 2011 at 6:03 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Jul 22, 2011 at 5:30 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>> On Fri, Jul 22, 2011 at 04:59:28AM -0700, H.J. Lu wrote:
>>> @@ -2660,6 +2664,7 @@ esac
>>>  case ${target} in
>>>  i[34567]86-*-linux* | x86_64-*-linux*)
>>>       tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
>>> +     use_initfini_array=yes
>>>       ;;
>>>  i[34567]86-*-* | x86_64-*-*)
>>>       tmake_file="${tmake_file} i386/t-gmm_malloc i386/t-i386"
>>
>> What is i?86/x86_64 specific on it?  Don't most other glibc targets
>> want to use it too, perhaps with some arch specific tweaks?
>
> I do have a patch for all ELF targets:
>
> http://gcc.gnu.org/ml/gcc-patches/2011-06/msg01416.html
>
> It touches many targets. .  But I only have one feedback from one
> target maintainer.  I don't know how long it will take to review it.
>
>
>>> --- /dev/null
>>> +++ b/gcc/config/initfini-array.c
>>
>> This is ugly.  varasm.c already has lots of ELF specific code, simply
>> put them there as well and only let configury set some macro which will
>> allow targets to choose which of the implementations in the generic code
>> they want to use (or if they want their own which e.g. calls the generic
>> routine and does something additional to it etc.).  The sections probably
>> can be created only the first time you actually need them.
>
> I will do that.
>
>>> --- a/gcc/crtstuff.c
>>> +++ b/gcc/crtstuff.c
>>> @@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
>>>     refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
>>>     symbol in crtbegin.o, where they are defined.  */
>>>
>>> +/* No need for .ctors/.dtors section if linker can place them in
>>> +   .init_array/.fini_array section.  */
>>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>>  /* The -1 is a flag to __do_global_[cd]tors indicating that this table
>>>     does not start with a count of elements.  */
>>>  #ifdef CTOR_LIST_BEGIN
>>> @@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
>>>    __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
>>>    = { (func_ptr) (-1) };
>>>  #endif /* __DTOR_LIST__ alternatives */
>>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>>
>>>  #ifdef USE_EH_FRAME_REGISTRY
>>>  /* Stick a label at the beginning of the frame unwind info so we can register
>>> @@ -489,6 +494,9 @@ __do_global_ctors_1(void)
>>>
>>>  #elif defined(CRT_END) /* ! CRT_BEGIN */
>>>
>>> +/* No need for .ctors/.dtors section if linker can place them in
>>> +   .init_array/.fini_array section.  */
>>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>>  /* Put a word containing zero at the end of each of our two lists of function
>>>     addresses.  Note that the words defined here go into the .ctors and .dtors
>>>     sections of the crtend.o file, and since that file is always linked in
>>> @@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
>>>    __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
>>>    = { (func_ptr) 0 };
>>>  #endif
>>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>>
>>>  #ifdef EH_FRAME_SECTION_NAME
>>>  /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
>>
>> I don't see how you can do this.  It would IMO break any time you link code
>> built by different gcc versions where some code emitted by the older gcc
>> used .ctors or .dtors.
>
> crtstuff.c is used to generate crt*.o, which is the part of GCC.  You only use
> it with the GCC you are using.  Since your GCC doesn't put anything in
> .ctors/.dtors section, you don't need them.  As for .o files generated by
> old GCCs, that is the linker test, use_initfini_array, is for.  The newer linker
> can put input .ctors/.dtors sections in output .init_array/,fini_array sections.
>
>

Here is the updated patch.  Any comments?

Thanks.

-- 
H.J.
---
2011-07-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/46770
	* config.gcc (use_initfini_array): New variable.
	Use .init_arary/.fini_array if they are supported.

	* crtstuff.c: Don't generate .ctors nor .dtors sections if
	USE_INITFINI_ARRAY is defined.

	* output.h (default_initfini_array_init_sections): New.
	* 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.
	(default_initfini_array_init_sections): Likewise.

	* config/initfini-array.h: New.
	* config/t-initfini-array: Likewise.

	* config/arm/arm.c (arm_asm_init_sections): Call
	default_initfini_array_init_sections.
	* config/avr/avr.c (avr_asm_init_sections): Likewise.
	* config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
	* config/mep/mep.c (mep_asm_init_sections): Likewise.
	* config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
	Likewise.
	* config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
	* config/stormy16/stormy16.c (xstormy16_asm_init_sections):
	Likewise.
	* config/v850/v850.c (v850_asm_init_sections): Likewise.

[-- Attachment #2: gcc-pr46770-7.patch --]
[-- Type: text/plain, Size: 13294 bytes --]

2011-07-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/46770
	* config.gcc (use_initfini_array): New variable.
	Use .init_arary/.fini_array if they are supported.

	* crtstuff.c: Don't generate .ctors nor .dtors sections if
	USE_INITFINI_ARRAY is defined.

	* output.h (default_initfini_array_init_sections): New.
	* 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.
	(default_initfini_array_init_sections): Likewise.

	* config/initfini-array.h: New.
	* config/t-initfini-array: Likewise.

	* config/arm/arm.c (arm_asm_init_sections): Call
	default_initfini_array_init_sections.
	* config/avr/avr.c (avr_asm_init_sections): Likewise.
	* config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
	* config/mep/mep.c (mep_asm_init_sections): Likewise.
	* config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
	Likewise.
	* config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
	* config/stormy16/stormy16.c (xstormy16_asm_init_sections):
	Likewise.
	* config/v850/v850.c (v850_asm_init_sections): Likewise.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 4a16ff8..0eac43a 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -186,6 +186,9 @@
 #  configure_default_options
 #			Set to an initializer for configure_default_options
 #			in configargs.h, based on --with-cpu et cetera.
+#
+#  use_initfini_array	If set to yes, .init_array/.fini_array sections
+#			will be used if they work.
 
 # The following variables are used in each case-construct to build up the
 # outgoing variables:
@@ -238,6 +241,7 @@ default_gnu_indirect_function=no
 target_gtfiles=
 need_64bit_hwint=
 need_64bit_isa=
+use_initfini_array=yes
 
 # Don't carry these over build->host->target.  Please.
 xm_file=
@@ -3053,6 +3057,14 @@ if test x$with_schedule = x; then
 	esac
 fi
 
+# Support --enable-initfini-array.  Use initfini-array.h only if
+# use_initfini_array is also set to yes.  Some platforms don't need it
+# even if enable_initfini_array is yes.
+if test x$enable_initfini_array$use_initfini_array = xyesyes; then
+  tm_file="${tm_file} initfini-array.h"
+  tmake_file="${tmake_file} t-initfini-array"
+fi
+
 # Validate and mark as valid any --with options supported
 # by this target.  In order to use a particular --with option
 # you must list it in supported_defaults; validating the value
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 6e2b799..02b713e 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -23023,6 +23023,7 @@ arm_asm_init_sections (void)
 {
   exception_section = get_unnamed_section (0, output_section_asm_op,
 					   "\t.handlerdata");
+  default_initfini_array_init_sections ();
 }
 #endif /* ARM_UNWIND_INFO */
 
diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c
index 4951f56..bb72bba 100644
--- a/gcc/config/avr/avr.c
+++ b/gcc/config/avr/avr.c
@@ -5099,6 +5099,8 @@ avr_asm_init_sections (void)
   readonly_data_section->unnamed.callback = avr_output_data_section_asm_op;
   data_section->unnamed.callback = avr_output_data_section_asm_op;
   bss_section->unnamed.callback = avr_output_bss_section_asm_op;
+
+  default_initfini_array_init_sections ();
 }
 
 
diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
index fa3b93f..5b8ea01 100644
--- a/gcc/config/ia64/ia64.c
+++ b/gcc/config/ia64/ia64.c
@@ -9989,6 +9989,7 @@ ia64_asm_init_sections (void)
 {
   exception_section = get_unnamed_section (0, output_section_asm_op,
 					   "\t.handlerdata");
+  default_initfini_array_init_sections ();
 }
 
 /* Implement TARGET_DEBUG_UNWIND_INFO.  */
diff --git a/gcc/config/initfini-array.h b/gcc/config/initfini-array.h
new file mode 100644
index 0000000..914cf08
--- /dev/null
+++ b/gcc/config/initfini-array.h
@@ -0,0 +1,44 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   support.
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+#define USE_INITFINI_ARRAY
+
+#undef INIT_SECTION_ASM_OP
+#undef FINI_SECTION_ASM_OP
+
+/* FIXME: INIT_ARRAY_SECTION_ASM_OP and FINI_ARRAY_SECTION_ASM_OP
+	  aren't used in any assembly codes.  But we have to define
+	  them to something.  */
+#define INIT_ARRAY_SECTION_ASM_OP Something
+#define FINI_ARRAY_SECTION_ASM_OP Something
+
+#ifndef TARGET_ASM_INIT_SECTIONS
+#define TARGET_ASM_INIT_SECTIONS default_elf_initfini_array_init_sections
+#endif
+extern void default_elf_initfini_array_init_sections (void);
+
+/* Use .init_array/.fini_array section for constructors and destructors. */
+#undef TARGET_ASM_CONSTRUCTOR
+#define TARGET_ASM_CONSTRUCTOR default_elf_init_array_asm_out_constructor
+#undef TARGET_ASM_DESTRUCTOR
+#define TARGET_ASM_DESTRUCTOR default_elf_fini_array_asm_out_destructor
+extern void default_elf_init_array_asm_out_constructor (rtx, int);
+extern void default_elf_fini_array_asm_out_destructor (rtx, int);
diff --git a/gcc/config/mep/mep.c b/gcc/config/mep/mep.c
index c18e7b7..5a4d5a6 100644
--- a/gcc/config/mep/mep.c
+++ b/gcc/config/mep/mep.c
@@ -7336,6 +7336,7 @@ mep_asm_init_sections (void)
     = get_unnamed_section (SECTION_CODE, output_section_asm_op,
 			   "\t.section .ftext,\"ax\"\n\t.core");
 
+  default_initfini_array_init_sections ();
 }
 \f
 /* Initialize the GCC target structure.  */
diff --git a/gcc/config/microblaze/microblaze.c b/gcc/config/microblaze/microblaze.c
index 288b86f..e31296d 100644
--- a/gcc/config/microblaze/microblaze.c
+++ b/gcc/config/microblaze/microblaze.c
@@ -2753,6 +2753,7 @@ microblaze_elf_asm_init_sections (void)
   sdata2_section
     = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
 			   SDATA2_SECTION_ASM_OP);
+  default_initfini_array_init_sections ();
 }
 
 /*  Generate assembler code for constant parts of a trampoline.  */
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 20b3cb8..d81ff94 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -24766,6 +24766,8 @@ rs6000_elf_asm_init_sections (void)
   sdata2_section
     = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
 			   SDATA2_SECTION_ASM_OP);
+
+  default_initfini_array_init_sections ();
 }
 
 /* Implement TARGET_SELECT_RTX_SECTION.  */
diff --git a/gcc/config/stormy16/stormy16.c b/gcc/config/stormy16/stormy16.c
index 910dc2e..835ba2b 100644
--- a/gcc/config/stormy16/stormy16.c
+++ b/gcc/config/stormy16/stormy16.c
@@ -1573,6 +1573,7 @@ xstormy16_asm_init_sections (void)
     = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
 			   output_section_asm_op,
 			   "\t.section \".bss_below100\",\"aw\",@nobits");
+  default_initfini_array_init_sections ();
 }
 
 /* Mark symbols with the "below100" attribute so that we can use the
diff --git a/gcc/config/t-initfini-array b/gcc/config/t-initfini-array
new file mode 100644
index 0000000..3824ed4
--- /dev/null
+++ b/gcc/config/t-initfini-array
@@ -0,0 +1,23 @@
+# Copyright (C) 2011
+# 2009 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+initfini-array.o: $(srcdir)/config/initfini-array.c gt-initfini-array.h \
+	$(CONFIG_H) $(SYSTEM_H) coretypes.h $(TARGET_H) output.h \
+	$(TREE_H) $(GGC_H)
+	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
diff --git a/gcc/config/v850/v850.c b/gcc/config/v850/v850.c
index 5074ebe..6666544 100644
--- a/gcc/config/v850/v850.c
+++ b/gcc/config/v850/v850.c
@@ -2900,6 +2900,8 @@ v850_asm_init_sections (void)
     = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
 			   output_section_asm_op,
 			   "\t.section .zbss,\"aw\"");
+
+  default_initfini_array_init_sections ();
 }
 
 static section *
diff --git a/gcc/crtstuff.c b/gcc/crtstuff.c
index b65f490..010d472 100644
--- a/gcc/crtstuff.c
+++ b/gcc/crtstuff.c
@@ -1,7 +1,8 @@
 /* Specialized bits of code needed to support construction and
    destruction of file-scope objects in C++ code.
    Copyright (C) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
+   Free Software Foundation, Inc.
    Contributed by Ron Guilmette (rfg@monkeys.com).
 
 This file is part of GCC.
@@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
    refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
    symbol in crtbegin.o, where they are defined.  */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef USE_INITFINI_ARRAY
 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
    does not start with a count of elements.  */
 #ifdef CTOR_LIST_BEGIN
@@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
   __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) (-1) };
 #endif /* __DTOR_LIST__ alternatives */
+#endif /* USE_INITFINI_ARRAY */
 
 #ifdef USE_EH_FRAME_REGISTRY
 /* Stick a label at the beginning of the frame unwind info so we can register
@@ -489,6 +494,9 @@ __do_global_ctors_1(void)
 
 #elif defined(CRT_END) /* ! CRT_BEGIN */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef USE_INITFINI_ARRAY
 /* Put a word containing zero at the end of each of our two lists of function
    addresses.  Note that the words defined here go into the .ctors and .dtors
    sections of the crtend.o file, and since that file is always linked in
@@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
   __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) 0 };
 #endif
+#endif /* USE_INITFINI_ARRAY */
 
 #ifdef EH_FRAME_SECTION_NAME
 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
diff --git a/gcc/output.h b/gcc/output.h
index c668d35..92a7075 100644
--- a/gcc/output.h
+++ b/gcc/output.h
@@ -656,6 +656,8 @@ extern void default_elf_asm_output_external (FILE *file, tree,
 					     const char *);
 extern int maybe_assemble_visibility (tree);
 
+extern void default_initfini_array_init_sections (void);
+
 extern int default_address_cost (rtx, bool);
 
 /* Output stack usage information.  */
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 88aea9b..f96863b 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -7350,4 +7350,62 @@ make_debug_expr_from_rtl (const_rtx exp)
   return dval;
 }
 
+static GTY(()) section *elf_init_array_section;
+static GTY(()) section *elf_fini_array_section;
+
+void
+default_elf_initfini_array_init_sections (void)
+{
+  elf_init_array_section = get_unnamed_section (0, output_section_asm_op,
+						"\t.section\t.init_array");
+  elf_fini_array_section = get_unnamed_section (0, output_section_asm_op,
+						"\t.section\t.fini_array");
+}
+
+static section *
+get_elf_initfini_array_priority_section (int priority,
+					 bool constructor_p)
+{
+  section *sec;
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      char buf[18];
+      sprintf (buf, "%s.%.5u", 
+	       constructor_p ? ".init_array" : ".fini_array",
+	       priority);
+      sec = get_section (buf, SECTION_WRITE, NULL_TREE);
+    }
+  else
+    sec = constructor_p ? elf_init_array_section : elf_fini_array_section;
+  return sec;
+}
+
+/* Use .init_array section for constructors. */
+
+void
+default_elf_init_array_asm_out_constructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  true);
+  assemble_addr_to_section (symbol, sec);
+}
+
+/* Use .fini_array section for destructors. */
+
+void
+default_elf_fini_array_asm_out_destructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  false);
+  assemble_addr_to_section (symbol, sec);
+}
+
+void
+default_initfini_array_init_sections (void)
+{
+#ifdef USE_INITFINI_ARRAY
+  default_elf_initfini_array_init_sections ();
+#endif
+}
+
 #include "gt-varasm.h"

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-07-22 14:17                       ` H.J. Lu
@ 2011-07-22 14:55                         ` H.J. Lu
  2011-08-06 14:51                           ` H.J. Lu
  2011-08-19 10:05                           ` Jakub Jelinek
  0 siblings, 2 replies; 46+ messages in thread
From: H.J. Lu @ 2011-07-22 14:55 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 6225 bytes --]

On Fri, Jul 22, 2011 at 7:00 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Jul 22, 2011 at 6:03 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Fri, Jul 22, 2011 at 5:30 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>>> On Fri, Jul 22, 2011 at 04:59:28AM -0700, H.J. Lu wrote:
>>>> @@ -2660,6 +2664,7 @@ esac
>>>>  case ${target} in
>>>>  i[34567]86-*-linux* | x86_64-*-linux*)
>>>>       tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
>>>> +     use_initfini_array=yes
>>>>       ;;
>>>>  i[34567]86-*-* | x86_64-*-*)
>>>>       tmake_file="${tmake_file} i386/t-gmm_malloc i386/t-i386"
>>>
>>> What is i?86/x86_64 specific on it?  Don't most other glibc targets
>>> want to use it too, perhaps with some arch specific tweaks?
>>
>> I do have a patch for all ELF targets:
>>
>> http://gcc.gnu.org/ml/gcc-patches/2011-06/msg01416.html
>>
>> It touches many targets. .  But I only have one feedback from one
>> target maintainer.  I don't know how long it will take to review it.
>>
>>
>>>> --- /dev/null
>>>> +++ b/gcc/config/initfini-array.c
>>>
>>> This is ugly.  varasm.c already has lots of ELF specific code, simply
>>> put them there as well and only let configury set some macro which will
>>> allow targets to choose which of the implementations in the generic code
>>> they want to use (or if they want their own which e.g. calls the generic
>>> routine and does something additional to it etc.).  The sections probably
>>> can be created only the first time you actually need them.
>>
>> I will do that.
>>
>>>> --- a/gcc/crtstuff.c
>>>> +++ b/gcc/crtstuff.c
>>>> @@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
>>>>     refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
>>>>     symbol in crtbegin.o, where they are defined.  */
>>>>
>>>> +/* No need for .ctors/.dtors section if linker can place them in
>>>> +   .init_array/.fini_array section.  */
>>>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>>>  /* The -1 is a flag to __do_global_[cd]tors indicating that this table
>>>>     does not start with a count of elements.  */
>>>>  #ifdef CTOR_LIST_BEGIN
>>>> @@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
>>>>    __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
>>>>    = { (func_ptr) (-1) };
>>>>  #endif /* __DTOR_LIST__ alternatives */
>>>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>>>
>>>>  #ifdef USE_EH_FRAME_REGISTRY
>>>>  /* Stick a label at the beginning of the frame unwind info so we can register
>>>> @@ -489,6 +494,9 @@ __do_global_ctors_1(void)
>>>>
>>>>  #elif defined(CRT_END) /* ! CRT_BEGIN */
>>>>
>>>> +/* No need for .ctors/.dtors section if linker can place them in
>>>> +   .init_array/.fini_array section.  */
>>>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>>>  /* Put a word containing zero at the end of each of our two lists of function
>>>>     addresses.  Note that the words defined here go into the .ctors and .dtors
>>>>     sections of the crtend.o file, and since that file is always linked in
>>>> @@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
>>>>    __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
>>>>    = { (func_ptr) 0 };
>>>>  #endif
>>>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>>>
>>>>  #ifdef EH_FRAME_SECTION_NAME
>>>>  /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
>>>
>>> I don't see how you can do this.  It would IMO break any time you link code
>>> built by different gcc versions where some code emitted by the older gcc
>>> used .ctors or .dtors.
>>
>> crtstuff.c is used to generate crt*.o, which is the part of GCC.  You only use
>> it with the GCC you are using.  Since your GCC doesn't put anything in
>> .ctors/.dtors section, you don't need them.  As for .o files generated by
>> old GCCs, that is the linker test, use_initfini_array, is for.  The newer linker
>> can put input .ctors/.dtors sections in output .init_array/,fini_array sections.
>>
>>
>
> Here is the updated patch.  Any comments?
>
> Thanks.
>
> --
> H.J.
> ---
> 2011-07-22  H.J. Lu  <hongjiu.lu@intel.com>
>
>        PR target/46770
>        * config.gcc (use_initfini_array): New variable.
>        Use .init_arary/.fini_array if they are supported.
>
>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>        USE_INITFINI_ARRAY is defined.
>
>        * output.h (default_initfini_array_init_sections): New.
>        * 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.
>        (default_initfini_array_init_sections): Likewise.
>
>        * config/initfini-array.h: New.
>        * config/t-initfini-array: Likewise.
>

No need for config/t-initfini-array.  Here is the updated patch.


-- 
H.J.
----
2011-07-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/46770
	* config.gcc (use_initfini_array): New variable.
	Use .init_arary/.fini_array if they are supported.

	* crtstuff.c: Don't generate .ctors nor .dtors sections if
	USE_INITFINI_ARRAY is defined.

	* output.h (default_initfini_array_init_sections): New.
	* 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.
	(default_initfini_array_init_sections): Likewise.

	* config/initfini-array.h: New.

	* config/arm/arm.c (arm_asm_init_sections): Call
	default_initfini_array_init_sections.
	* config/avr/avr.c (avr_asm_init_sections): Likewise.
	* config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
	* config/mep/mep.c (mep_asm_init_sections): Likewise.
	* config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
	Likewise.
	* config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
	* config/stormy16/stormy16.c (xstormy16_asm_init_sections):
	Likewise.
	* config/v850/v850.c (v850_asm_init_sections): Likewise.

[-- Attachment #2: gcc-pr46770-8.patch --]
[-- Type: text/plain, Size: 12076 bytes --]

2011-07-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/46770
	* config.gcc (use_initfini_array): New variable.
	Use .init_arary/.fini_array if they are supported.

	* crtstuff.c: Don't generate .ctors nor .dtors sections if
	USE_INITFINI_ARRAY is defined.

	* output.h (default_initfini_array_init_sections): New.
	* 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.
	(default_initfini_array_init_sections): Likewise.

	* config/initfini-array.h: New.

	* config/arm/arm.c (arm_asm_init_sections): Call
	default_initfini_array_init_sections.
	* config/avr/avr.c (avr_asm_init_sections): Likewise.
	* config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
	* config/mep/mep.c (mep_asm_init_sections): Likewise.
	* config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
	Likewise.
	* config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
	* config/stormy16/stormy16.c (xstormy16_asm_init_sections):
	Likewise.
	* config/v850/v850.c (v850_asm_init_sections): Likewise.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 4a16ff8..cbcdaf7 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -186,6 +186,9 @@
 #  configure_default_options
 #			Set to an initializer for configure_default_options
 #			in configargs.h, based on --with-cpu et cetera.
+#
+#  use_initfini_array	If set to yes, .init_array/.fini_array sections
+#			will be used if they work.
 
 # The following variables are used in each case-construct to build up the
 # outgoing variables:
@@ -238,6 +241,7 @@ default_gnu_indirect_function=no
 target_gtfiles=
 need_64bit_hwint=
 need_64bit_isa=
+use_initfini_array=yes
 
 # Don't carry these over build->host->target.  Please.
 xm_file=
@@ -3053,6 +3057,13 @@ if test x$with_schedule = x; then
 	esac
 fi
 
+# Support --enable-initfini-array.  Use initfini-array.h only if
+# use_initfini_array is also set to yes.  Some platforms don't need it
+# even if enable_initfini_array is yes.
+if test x$enable_initfini_array$use_initfini_array = xyesyes; then
+  tm_file="${tm_file} initfini-array.h"
+fi
+
 # Validate and mark as valid any --with options supported
 # by this target.  In order to use a particular --with option
 # you must list it in supported_defaults; validating the value
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 6e2b799..02b713e 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -23023,6 +23023,7 @@ arm_asm_init_sections (void)
 {
   exception_section = get_unnamed_section (0, output_section_asm_op,
 					   "\t.handlerdata");
+  default_initfini_array_init_sections ();
 }
 #endif /* ARM_UNWIND_INFO */
 
diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c
index 4951f56..bb72bba 100644
--- a/gcc/config/avr/avr.c
+++ b/gcc/config/avr/avr.c
@@ -5099,6 +5099,8 @@ avr_asm_init_sections (void)
   readonly_data_section->unnamed.callback = avr_output_data_section_asm_op;
   data_section->unnamed.callback = avr_output_data_section_asm_op;
   bss_section->unnamed.callback = avr_output_bss_section_asm_op;
+
+  default_initfini_array_init_sections ();
 }
 
 
diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
index fa3b93f..5b8ea01 100644
--- a/gcc/config/ia64/ia64.c
+++ b/gcc/config/ia64/ia64.c
@@ -9989,6 +9989,7 @@ ia64_asm_init_sections (void)
 {
   exception_section = get_unnamed_section (0, output_section_asm_op,
 					   "\t.handlerdata");
+  default_initfini_array_init_sections ();
 }
 
 /* Implement TARGET_DEBUG_UNWIND_INFO.  */
diff --git a/gcc/config/initfini-array.h b/gcc/config/initfini-array.h
new file mode 100644
index 0000000..914cf08
--- /dev/null
+++ b/gcc/config/initfini-array.h
@@ -0,0 +1,44 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   support.
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+#define USE_INITFINI_ARRAY
+
+#undef INIT_SECTION_ASM_OP
+#undef FINI_SECTION_ASM_OP
+
+/* FIXME: INIT_ARRAY_SECTION_ASM_OP and FINI_ARRAY_SECTION_ASM_OP
+	  aren't used in any assembly codes.  But we have to define
+	  them to something.  */
+#define INIT_ARRAY_SECTION_ASM_OP Something
+#define FINI_ARRAY_SECTION_ASM_OP Something
+
+#ifndef TARGET_ASM_INIT_SECTIONS
+#define TARGET_ASM_INIT_SECTIONS default_elf_initfini_array_init_sections
+#endif
+extern void default_elf_initfini_array_init_sections (void);
+
+/* Use .init_array/.fini_array section for constructors and destructors. */
+#undef TARGET_ASM_CONSTRUCTOR
+#define TARGET_ASM_CONSTRUCTOR default_elf_init_array_asm_out_constructor
+#undef TARGET_ASM_DESTRUCTOR
+#define TARGET_ASM_DESTRUCTOR default_elf_fini_array_asm_out_destructor
+extern void default_elf_init_array_asm_out_constructor (rtx, int);
+extern void default_elf_fini_array_asm_out_destructor (rtx, int);
diff --git a/gcc/config/mep/mep.c b/gcc/config/mep/mep.c
index c18e7b7..5a4d5a6 100644
--- a/gcc/config/mep/mep.c
+++ b/gcc/config/mep/mep.c
@@ -7336,6 +7336,7 @@ mep_asm_init_sections (void)
     = get_unnamed_section (SECTION_CODE, output_section_asm_op,
 			   "\t.section .ftext,\"ax\"\n\t.core");
 
+  default_initfini_array_init_sections ();
 }
 \f
 /* Initialize the GCC target structure.  */
diff --git a/gcc/config/microblaze/microblaze.c b/gcc/config/microblaze/microblaze.c
index 288b86f..e31296d 100644
--- a/gcc/config/microblaze/microblaze.c
+++ b/gcc/config/microblaze/microblaze.c
@@ -2753,6 +2753,7 @@ microblaze_elf_asm_init_sections (void)
   sdata2_section
     = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
 			   SDATA2_SECTION_ASM_OP);
+  default_initfini_array_init_sections ();
 }
 
 /*  Generate assembler code for constant parts of a trampoline.  */
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 20b3cb8..d81ff94 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -24766,6 +24766,8 @@ rs6000_elf_asm_init_sections (void)
   sdata2_section
     = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
 			   SDATA2_SECTION_ASM_OP);
+
+  default_initfini_array_init_sections ();
 }
 
 /* Implement TARGET_SELECT_RTX_SECTION.  */
diff --git a/gcc/config/stormy16/stormy16.c b/gcc/config/stormy16/stormy16.c
index 910dc2e..835ba2b 100644
--- a/gcc/config/stormy16/stormy16.c
+++ b/gcc/config/stormy16/stormy16.c
@@ -1573,6 +1573,7 @@ xstormy16_asm_init_sections (void)
     = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
 			   output_section_asm_op,
 			   "\t.section \".bss_below100\",\"aw\",@nobits");
+  default_initfini_array_init_sections ();
 }
 
 /* Mark symbols with the "below100" attribute so that we can use the
diff --git a/gcc/config/v850/v850.c b/gcc/config/v850/v850.c
index 5074ebe..6666544 100644
--- a/gcc/config/v850/v850.c
+++ b/gcc/config/v850/v850.c
@@ -2900,6 +2900,8 @@ v850_asm_init_sections (void)
     = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
 			   output_section_asm_op,
 			   "\t.section .zbss,\"aw\"");
+
+  default_initfini_array_init_sections ();
 }
 
 static section *
diff --git a/gcc/crtstuff.c b/gcc/crtstuff.c
index b65f490..010d472 100644
--- a/gcc/crtstuff.c
+++ b/gcc/crtstuff.c
@@ -1,7 +1,8 @@
 /* Specialized bits of code needed to support construction and
    destruction of file-scope objects in C++ code.
    Copyright (C) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
+   Free Software Foundation, Inc.
    Contributed by Ron Guilmette (rfg@monkeys.com).
 
 This file is part of GCC.
@@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
    refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
    symbol in crtbegin.o, where they are defined.  */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef USE_INITFINI_ARRAY
 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
    does not start with a count of elements.  */
 #ifdef CTOR_LIST_BEGIN
@@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
   __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) (-1) };
 #endif /* __DTOR_LIST__ alternatives */
+#endif /* USE_INITFINI_ARRAY */
 
 #ifdef USE_EH_FRAME_REGISTRY
 /* Stick a label at the beginning of the frame unwind info so we can register
@@ -489,6 +494,9 @@ __do_global_ctors_1(void)
 
 #elif defined(CRT_END) /* ! CRT_BEGIN */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef USE_INITFINI_ARRAY
 /* Put a word containing zero at the end of each of our two lists of function
    addresses.  Note that the words defined here go into the .ctors and .dtors
    sections of the crtend.o file, and since that file is always linked in
@@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
   __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) 0 };
 #endif
+#endif /* USE_INITFINI_ARRAY */
 
 #ifdef EH_FRAME_SECTION_NAME
 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
diff --git a/gcc/output.h b/gcc/output.h
index c668d35..92a7075 100644
--- a/gcc/output.h
+++ b/gcc/output.h
@@ -656,6 +656,8 @@ extern void default_elf_asm_output_external (FILE *file, tree,
 					     const char *);
 extern int maybe_assemble_visibility (tree);
 
+extern void default_initfini_array_init_sections (void);
+
 extern int default_address_cost (rtx, bool);
 
 /* Output stack usage information.  */
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 88aea9b..f96863b 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -7350,4 +7350,62 @@ make_debug_expr_from_rtl (const_rtx exp)
   return dval;
 }
 
+static GTY(()) section *elf_init_array_section;
+static GTY(()) section *elf_fini_array_section;
+
+void
+default_elf_initfini_array_init_sections (void)
+{
+  elf_init_array_section = get_unnamed_section (0, output_section_asm_op,
+						"\t.section\t.init_array");
+  elf_fini_array_section = get_unnamed_section (0, output_section_asm_op,
+						"\t.section\t.fini_array");
+}
+
+static section *
+get_elf_initfini_array_priority_section (int priority,
+					 bool constructor_p)
+{
+  section *sec;
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      char buf[18];
+      sprintf (buf, "%s.%.5u", 
+	       constructor_p ? ".init_array" : ".fini_array",
+	       priority);
+      sec = get_section (buf, SECTION_WRITE, NULL_TREE);
+    }
+  else
+    sec = constructor_p ? elf_init_array_section : elf_fini_array_section;
+  return sec;
+}
+
+/* Use .init_array section for constructors. */
+
+void
+default_elf_init_array_asm_out_constructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  true);
+  assemble_addr_to_section (symbol, sec);
+}
+
+/* Use .fini_array section for destructors. */
+
+void
+default_elf_fini_array_asm_out_destructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  false);
+  assemble_addr_to_section (symbol, sec);
+}
+
+void
+default_initfini_array_init_sections (void)
+{
+#ifdef USE_INITFINI_ARRAY
+  default_elf_initfini_array_init_sections ();
+#endif
+}
+
 #include "gt-varasm.h"

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-07-22 14:55                         ` H.J. Lu
@ 2011-08-06 14:51                           ` H.J. Lu
  2011-08-09 14:32                             ` H.J. Lu
  2011-08-19 10:05                           ` Jakub Jelinek
  1 sibling, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-08-06 14:51 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

PING.

On Fri, Jul 22, 2011 at 7:06 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Jul 22, 2011 at 7:00 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Fri, Jul 22, 2011 at 6:03 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Fri, Jul 22, 2011 at 5:30 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>>>> On Fri, Jul 22, 2011 at 04:59:28AM -0700, H.J. Lu wrote:
>>>>> @@ -2660,6 +2664,7 @@ esac
>>>>>  case ${target} in
>>>>>  i[34567]86-*-linux* | x86_64-*-linux*)
>>>>>       tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
>>>>> +     use_initfini_array=yes
>>>>>       ;;
>>>>>  i[34567]86-*-* | x86_64-*-*)
>>>>>       tmake_file="${tmake_file} i386/t-gmm_malloc i386/t-i386"
>>>>
>>>> What is i?86/x86_64 specific on it?  Don't most other glibc targets
>>>> want to use it too, perhaps with some arch specific tweaks?
>>>
>>> I do have a patch for all ELF targets:
>>>
>>> http://gcc.gnu.org/ml/gcc-patches/2011-06/msg01416.html
>>>
>>> It touches many targets. .  But I only have one feedback from one
>>> target maintainer.  I don't know how long it will take to review it.
>>>
>>>
>>>>> --- /dev/null
>>>>> +++ b/gcc/config/initfini-array.c
>>>>
>>>> This is ugly.  varasm.c already has lots of ELF specific code, simply
>>>> put them there as well and only let configury set some macro which will
>>>> allow targets to choose which of the implementations in the generic code
>>>> they want to use (or if they want their own which e.g. calls the generic
>>>> routine and does something additional to it etc.).  The sections probably
>>>> can be created only the first time you actually need them.
>>>
>>> I will do that.
>>>
>>>>> --- a/gcc/crtstuff.c
>>>>> +++ b/gcc/crtstuff.c
>>>>> @@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
>>>>>     refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
>>>>>     symbol in crtbegin.o, where they are defined.  */
>>>>>
>>>>> +/* No need for .ctors/.dtors section if linker can place them in
>>>>> +   .init_array/.fini_array section.  */
>>>>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>>>>  /* The -1 is a flag to __do_global_[cd]tors indicating that this table
>>>>>     does not start with a count of elements.  */
>>>>>  #ifdef CTOR_LIST_BEGIN
>>>>> @@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
>>>>>    __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
>>>>>    = { (func_ptr) (-1) };
>>>>>  #endif /* __DTOR_LIST__ alternatives */
>>>>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>>>>
>>>>>  #ifdef USE_EH_FRAME_REGISTRY
>>>>>  /* Stick a label at the beginning of the frame unwind info so we can register
>>>>> @@ -489,6 +494,9 @@ __do_global_ctors_1(void)
>>>>>
>>>>>  #elif defined(CRT_END) /* ! CRT_BEGIN */
>>>>>
>>>>> +/* No need for .ctors/.dtors section if linker can place them in
>>>>> +   .init_array/.fini_array section.  */
>>>>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>>>>  /* Put a word containing zero at the end of each of our two lists of function
>>>>>     addresses.  Note that the words defined here go into the .ctors and .dtors
>>>>>     sections of the crtend.o file, and since that file is always linked in
>>>>> @@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
>>>>>    __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
>>>>>    = { (func_ptr) 0 };
>>>>>  #endif
>>>>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>>>>
>>>>>  #ifdef EH_FRAME_SECTION_NAME
>>>>>  /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
>>>>
>>>> I don't see how you can do this.  It would IMO break any time you link code
>>>> built by different gcc versions where some code emitted by the older gcc
>>>> used .ctors or .dtors.
>>>
>>> crtstuff.c is used to generate crt*.o, which is the part of GCC.  You only use
>>> it with the GCC you are using.  Since your GCC doesn't put anything in
>>> .ctors/.dtors section, you don't need them.  As for .o files generated by
>>> old GCCs, that is the linker test, use_initfini_array, is for.  The newer linker
>>> can put input .ctors/.dtors sections in output .init_array/,fini_array sections.
>>>
>>>
>>
>> Here is the updated patch.  Any comments?
>>
>> Thanks.
>>
>> --
>> H.J.
>> ---
>> 2011-07-22  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>        PR target/46770
>>        * config.gcc (use_initfini_array): New variable.
>>        Use .init_arary/.fini_array if they are supported.
>>
>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>        USE_INITFINI_ARRAY is defined.
>>
>>        * output.h (default_initfini_array_init_sections): New.
>>        * 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.
>>        (default_initfini_array_init_sections): Likewise.
>>
>>        * config/initfini-array.h: New.
>>        * config/t-initfini-array: Likewise.
>>
>
> No need for config/t-initfini-array.  Here is the updated patch.
>
>
> --
> H.J.
> ----
> 2011-07-22  H.J. Lu  <hongjiu.lu@intel.com>
>
>        PR target/46770
>        * config.gcc (use_initfini_array): New variable.
>        Use .init_arary/.fini_array if they are supported.
>
>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>        USE_INITFINI_ARRAY is defined.
>
>        * output.h (default_initfini_array_init_sections): New.
>        * 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.
>        (default_initfini_array_init_sections): Likewise.
>
>        * config/initfini-array.h: New.
>
>        * config/arm/arm.c (arm_asm_init_sections): Call
>        default_initfini_array_init_sections.
>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>        Likewise.
>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>        Likewise.
>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>



-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-06 14:51                           ` H.J. Lu
@ 2011-08-09 14:32                             ` H.J. Lu
  2011-08-14 19:20                               ` H.J. Lu
  0 siblings, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-08-09 14:32 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

PING.

On Sat, Aug 6, 2011 at 7:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> PING.
>
> On Fri, Jul 22, 2011 at 7:06 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Fri, Jul 22, 2011 at 7:00 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Fri, Jul 22, 2011 at 6:03 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Fri, Jul 22, 2011 at 5:30 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>>>>> On Fri, Jul 22, 2011 at 04:59:28AM -0700, H.J. Lu wrote:
>>>>>> @@ -2660,6 +2664,7 @@ esac
>>>>>>  case ${target} in
>>>>>>  i[34567]86-*-linux* | x86_64-*-linux*)
>>>>>>       tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
>>>>>> +     use_initfini_array=yes
>>>>>>       ;;
>>>>>>  i[34567]86-*-* | x86_64-*-*)
>>>>>>       tmake_file="${tmake_file} i386/t-gmm_malloc i386/t-i386"
>>>>>
>>>>> What is i?86/x86_64 specific on it?  Don't most other glibc targets
>>>>> want to use it too, perhaps with some arch specific tweaks?
>>>>
>>>> I do have a patch for all ELF targets:
>>>>
>>>> http://gcc.gnu.org/ml/gcc-patches/2011-06/msg01416.html
>>>>
>>>> It touches many targets. .  But I only have one feedback from one
>>>> target maintainer.  I don't know how long it will take to review it.
>>>>
>>>>
>>>>>> --- /dev/null
>>>>>> +++ b/gcc/config/initfini-array.c
>>>>>
>>>>> This is ugly.  varasm.c already has lots of ELF specific code, simply
>>>>> put them there as well and only let configury set some macro which will
>>>>> allow targets to choose which of the implementations in the generic code
>>>>> they want to use (or if they want their own which e.g. calls the generic
>>>>> routine and does something additional to it etc.).  The sections probably
>>>>> can be created only the first time you actually need them.
>>>>
>>>> I will do that.
>>>>
>>>>>> --- a/gcc/crtstuff.c
>>>>>> +++ b/gcc/crtstuff.c
>>>>>> @@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
>>>>>>     refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
>>>>>>     symbol in crtbegin.o, where they are defined.  */
>>>>>>
>>>>>> +/* No need for .ctors/.dtors section if linker can place them in
>>>>>> +   .init_array/.fini_array section.  */
>>>>>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>>>>>  /* The -1 is a flag to __do_global_[cd]tors indicating that this table
>>>>>>     does not start with a count of elements.  */
>>>>>>  #ifdef CTOR_LIST_BEGIN
>>>>>> @@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
>>>>>>    __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
>>>>>>    = { (func_ptr) (-1) };
>>>>>>  #endif /* __DTOR_LIST__ alternatives */
>>>>>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>>>>>
>>>>>>  #ifdef USE_EH_FRAME_REGISTRY
>>>>>>  /* Stick a label at the beginning of the frame unwind info so we can register
>>>>>> @@ -489,6 +494,9 @@ __do_global_ctors_1(void)
>>>>>>
>>>>>>  #elif defined(CRT_END) /* ! CRT_BEGIN */
>>>>>>
>>>>>> +/* No need for .ctors/.dtors section if linker can place them in
>>>>>> +   .init_array/.fini_array section.  */
>>>>>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>>>>>  /* Put a word containing zero at the end of each of our two lists of function
>>>>>>     addresses.  Note that the words defined here go into the .ctors and .dtors
>>>>>>     sections of the crtend.o file, and since that file is always linked in
>>>>>> @@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
>>>>>>    __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
>>>>>>    = { (func_ptr) 0 };
>>>>>>  #endif
>>>>>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>>>>>
>>>>>>  #ifdef EH_FRAME_SECTION_NAME
>>>>>>  /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
>>>>>
>>>>> I don't see how you can do this.  It would IMO break any time you link code
>>>>> built by different gcc versions where some code emitted by the older gcc
>>>>> used .ctors or .dtors.
>>>>
>>>> crtstuff.c is used to generate crt*.o, which is the part of GCC.  You only use
>>>> it with the GCC you are using.  Since your GCC doesn't put anything in
>>>> .ctors/.dtors section, you don't need them.  As for .o files generated by
>>>> old GCCs, that is the linker test, use_initfini_array, is for.  The newer linker
>>>> can put input .ctors/.dtors sections in output .init_array/,fini_array sections.
>>>>
>>>>
>>>
>>> Here is the updated patch.  Any comments?
>>>
>>> Thanks.
>>>
>>> --
>>> H.J.
>>> ---
>>> 2011-07-22  H.J. Lu  <hongjiu.lu@intel.com>
>>>
>>>        PR target/46770
>>>        * config.gcc (use_initfini_array): New variable.
>>>        Use .init_arary/.fini_array if they are supported.
>>>
>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>        USE_INITFINI_ARRAY is defined.
>>>
>>>        * output.h (default_initfini_array_init_sections): New.
>>>        * 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.
>>>        (default_initfini_array_init_sections): Likewise.
>>>
>>>        * config/initfini-array.h: New.
>>>        * config/t-initfini-array: Likewise.
>>>
>>
>> No need for config/t-initfini-array.  Here is the updated patch.
>>
>>
>> --
>> H.J.
>> ----
>> 2011-07-22  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>        PR target/46770
>>        * config.gcc (use_initfini_array): New variable.
>>        Use .init_arary/.fini_array if they are supported.
>>
>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>        USE_INITFINI_ARRAY is defined.
>>
>>        * output.h (default_initfini_array_init_sections): New.
>>        * 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.
>>        (default_initfini_array_init_sections): Likewise.
>>
>>        * config/initfini-array.h: New.
>>
>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>        default_initfini_array_init_sections.
>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>        Likewise.
>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>        Likewise.
>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>
>
>
>
> --
> H.J.
>



-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-09 14:32                             ` H.J. Lu
@ 2011-08-14 19:20                               ` H.J. Lu
  0 siblings, 0 replies; 46+ messages in thread
From: H.J. Lu @ 2011-08-14 19:20 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

PING

On Tue, Aug 9, 2011 at 6:56 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> PING.
>
> On Sat, Aug 6, 2011 at 7:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> PING.
>>
>> On Fri, Jul 22, 2011 at 7:06 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Fri, Jul 22, 2011 at 7:00 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Fri, Jul 22, 2011 at 6:03 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Fri, Jul 22, 2011 at 5:30 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>>>>>> On Fri, Jul 22, 2011 at 04:59:28AM -0700, H.J. Lu wrote:
>>>>>>> @@ -2660,6 +2664,7 @@ esac
>>>>>>>  case ${target} in
>>>>>>>  i[34567]86-*-linux* | x86_64-*-linux*)
>>>>>>>       tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
>>>>>>> +     use_initfini_array=yes
>>>>>>>       ;;
>>>>>>>  i[34567]86-*-* | x86_64-*-*)
>>>>>>>       tmake_file="${tmake_file} i386/t-gmm_malloc i386/t-i386"
>>>>>>
>>>>>> What is i?86/x86_64 specific on it?  Don't most other glibc targets
>>>>>> want to use it too, perhaps with some arch specific tweaks?
>>>>>
>>>>> I do have a patch for all ELF targets:
>>>>>
>>>>> http://gcc.gnu.org/ml/gcc-patches/2011-06/msg01416.html
>>>>>
>>>>> It touches many targets. .  But I only have one feedback from one
>>>>> target maintainer.  I don't know how long it will take to review it.
>>>>>
>>>>>
>>>>>>> --- /dev/null
>>>>>>> +++ b/gcc/config/initfini-array.c
>>>>>>
>>>>>> This is ugly.  varasm.c already has lots of ELF specific code, simply
>>>>>> put them there as well and only let configury set some macro which will
>>>>>> allow targets to choose which of the implementations in the generic code
>>>>>> they want to use (or if they want their own which e.g. calls the generic
>>>>>> routine and does something additional to it etc.).  The sections probably
>>>>>> can be created only the first time you actually need them.
>>>>>
>>>>> I will do that.
>>>>>
>>>>>>> --- a/gcc/crtstuff.c
>>>>>>> +++ b/gcc/crtstuff.c
>>>>>>> @@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
>>>>>>>     refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
>>>>>>>     symbol in crtbegin.o, where they are defined.  */
>>>>>>>
>>>>>>> +/* No need for .ctors/.dtors section if linker can place them in
>>>>>>> +   .init_array/.fini_array section.  */
>>>>>>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>>>>>>  /* The -1 is a flag to __do_global_[cd]tors indicating that this table
>>>>>>>     does not start with a count of elements.  */
>>>>>>>  #ifdef CTOR_LIST_BEGIN
>>>>>>> @@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
>>>>>>>    __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
>>>>>>>    = { (func_ptr) (-1) };
>>>>>>>  #endif /* __DTOR_LIST__ alternatives */
>>>>>>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>>>>>>
>>>>>>>  #ifdef USE_EH_FRAME_REGISTRY
>>>>>>>  /* Stick a label at the beginning of the frame unwind info so we can register
>>>>>>> @@ -489,6 +494,9 @@ __do_global_ctors_1(void)
>>>>>>>
>>>>>>>  #elif defined(CRT_END) /* ! CRT_BEGIN */
>>>>>>>
>>>>>>> +/* No need for .ctors/.dtors section if linker can place them in
>>>>>>> +   .init_array/.fini_array section.  */
>>>>>>> +#ifndef NO_CTORS_DTORS_SECTIONS
>>>>>>>  /* Put a word containing zero at the end of each of our two lists of function
>>>>>>>     addresses.  Note that the words defined here go into the .ctors and .dtors
>>>>>>>     sections of the crtend.o file, and since that file is always linked in
>>>>>>> @@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
>>>>>>>    __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
>>>>>>>    = { (func_ptr) 0 };
>>>>>>>  #endif
>>>>>>> +#endif /* NO_CTORS_DTORS_SECTIONS */
>>>>>>>
>>>>>>>  #ifdef EH_FRAME_SECTION_NAME
>>>>>>>  /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
>>>>>>
>>>>>> I don't see how you can do this.  It would IMO break any time you link code
>>>>>> built by different gcc versions where some code emitted by the older gcc
>>>>>> used .ctors or .dtors.
>>>>>
>>>>> crtstuff.c is used to generate crt*.o, which is the part of GCC.  You only use
>>>>> it with the GCC you are using.  Since your GCC doesn't put anything in
>>>>> .ctors/.dtors section, you don't need them.  As for .o files generated by
>>>>> old GCCs, that is the linker test, use_initfini_array, is for.  The newer linker
>>>>> can put input .ctors/.dtors sections in output .init_array/,fini_array sections.
>>>>>
>>>>>
>>>>
>>>> Here is the updated patch.  Any comments?
>>>>
>>>> Thanks.
>>>>
>>>> --
>>>> H.J.
>>>> ---
>>>> 2011-07-22  H.J. Lu  <hongjiu.lu@intel.com>
>>>>
>>>>        PR target/46770
>>>>        * config.gcc (use_initfini_array): New variable.
>>>>        Use .init_arary/.fini_array if they are supported.
>>>>
>>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>>        USE_INITFINI_ARRAY is defined.
>>>>
>>>>        * output.h (default_initfini_array_init_sections): New.
>>>>        * 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.
>>>>        (default_initfini_array_init_sections): Likewise.
>>>>
>>>>        * config/initfini-array.h: New.
>>>>        * config/t-initfini-array: Likewise.
>>>>
>>>
>>> No need for config/t-initfini-array.  Here is the updated patch.
>>>
>>>
>>> --
>>> H.J.
>>> ----
>>> 2011-07-22  H.J. Lu  <hongjiu.lu@intel.com>
>>>
>>>        PR target/46770
>>>        * config.gcc (use_initfini_array): New variable.
>>>        Use .init_arary/.fini_array if they are supported.
>>>
>>>        * crtstuff.c: Don't generate .ctors nor .dtors sections if
>>>        USE_INITFINI_ARRAY is defined.
>>>
>>>        * output.h (default_initfini_array_init_sections): New.
>>>        * 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.
>>>        (default_initfini_array_init_sections): Likewise.
>>>
>>>        * config/initfini-array.h: New.
>>>
>>>        * config/arm/arm.c (arm_asm_init_sections): Call
>>>        default_initfini_array_init_sections.
>>>        * config/avr/avr.c (avr_asm_init_sections): Likewise.
>>>        * config/ia64/ia64.c (ia64_asm_init_sections): Likewise.
>>>        * config/mep/mep.c (mep_asm_init_sections): Likewise.
>>>        * config/microblaze/microblaze.c (microblaze_elf_asm_init_sections):
>>>        Likewise.
>>>        * config/rs6000/rs6000.c (rs6000_elf_asm_init_sections): Likewise.
>>>        * config/stormy16/stormy16.c (xstormy16_asm_init_sections):
>>>        Likewise.
>>>        * config/v850/v850.c (v850_asm_init_sections): Likewise.
>>>
>>
>>
>>
>> --
>> H.J.
>>
>
>
>
> --
> H.J.
>



-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-07-22 14:55                         ` H.J. Lu
  2011-08-06 14:51                           ` H.J. Lu
@ 2011-08-19 10:05                           ` Jakub Jelinek
  2011-08-19 14:58                             ` H.J. Lu
  1 sibling, 1 reply; 46+ messages in thread
From: Jakub Jelinek @ 2011-08-19 10:05 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches

Sorry for the delay.

> --- a/gcc/config.gcc
> +++ b/gcc/config.gcc
> @@ -186,6 +186,9 @@
>  #  configure_default_options
>  #			Set to an initializer for configure_default_options
>  #			in configargs.h, based on --with-cpu et cetera.
> +#
> +#  use_initfini_array	If set to yes, .init_array/.fini_array sections
> +#			will be used if they work.
>  
>  # The following variables are used in each case-construct to build up the
>  # outgoing variables:
> @@ -238,6 +241,7 @@ default_gnu_indirect_function=no
>  target_gtfiles=
>  need_64bit_hwint=
>  need_64bit_isa=
> +use_initfini_array=yes

What is this for, when nothing ever sets it to anything but yes?
If the $enable_initfini_array = yes test works, then there shouldn't be
any need to override it on a per-target basis...

> --- /dev/null
> +++ b/gcc/config/initfini-array.h
> @@ -0,0 +1,44 @@
> +/* Definitions for ELF systems with .init_array/.fini_array section
> +   support.
> +   Copyright (C) 2011
> +   Free Software Foundation, Inc.
> +
> +   This file is part of GCC.
> +
> +   GCC is free software; you can redistribute it and/or modify it
> +   under the terms of the GNU General Public License as published
> +   by the Free Software Foundation; either version 3, or (at your
> +   option) any later version.
> +
> +   GCC is distributed in the hope that it will be useful, but WITHOUT
> +   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
> +   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
> +   License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with GCC; see the file COPYING3.  If not see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#define USE_INITFINI_ARRAY
> +
> +#undef INIT_SECTION_ASM_OP
> +#undef FINI_SECTION_ASM_OP
> +
> +/* FIXME: INIT_ARRAY_SECTION_ASM_OP and FINI_ARRAY_SECTION_ASM_OP
> +	  aren't used in any assembly codes.  But we have to define
> +	  them to something.  */
> +#define INIT_ARRAY_SECTION_ASM_OP Something
> +#define FINI_ARRAY_SECTION_ASM_OP Something

Can't you just define it to an empty string?  And, a couple of targets
define INIT_ARRAY_SECTION_ASM_OP/FINI_ARRAY_SECTION_ASM_OP, you either need
to undef it first, or define only if it wasn't defined.
> +
> +#ifndef TARGET_ASM_INIT_SECTIONS
> +#define TARGET_ASM_INIT_SECTIONS default_elf_initfini_array_init_sections
> +#endif
> +extern void default_elf_initfini_array_init_sections (void);

Why do you need this (and the default_initfini_array_init_sections () call
in all the backends)?  Isn't it easier to just initialize the two global
vars only when you are actually going to use them (if they are still NULL)?

> --- a/gcc/varasm.c
> +++ b/gcc/varasm.c
> @@ -7350,4 +7350,62 @@ make_debug_expr_from_rtl (const_rtx exp)
>    return dval;
>  }
>  
> +static GTY(()) section *elf_init_array_section;
> +static GTY(()) section *elf_fini_array_section;
> +
> +void
> +default_elf_initfini_array_init_sections (void)
> +{
> +  elf_init_array_section = get_unnamed_section (0, output_section_asm_op,
> +						"\t.section\t.init_array");
> +  elf_fini_array_section = get_unnamed_section (0, output_section_asm_op,
> +						"\t.section\t.fini_array");
> +}

Remove above function.

> +
> +static section *
> +get_elf_initfini_array_priority_section (int priority,
> +					 bool constructor_p)
> +{
> +  section *sec;
> +  if (priority != DEFAULT_INIT_PRIORITY)
> +    {
> +      char buf[18];
> +      sprintf (buf, "%s.%.5u", 
> +	       constructor_p ? ".init_array" : ".fini_array",
> +	       priority);
> +      sec = get_section (buf, SECTION_WRITE, NULL_TREE);
> +    }

I'd just put here
   else
     {
       if (elf_init_array_section == NULL)
         elf_init_array_section = get_unnamed_section...
       if (elf_fini_array_section == NULL)
	 elf_fini_array_section = get_unnamed_section...
> +    sec = constructor_p ? elf_init_array_section : elf_fini_array_section;
     }

> +void
> +default_initfini_array_init_sections (void)
> +{
> +#ifdef USE_INITFINI_ARRAY
> +  default_elf_initfini_array_init_sections ();
> +#endif
> +}

And remove this (and all callers etc.).

On which targets has it been tested?  Would be nice to test it at least on
targets that define their own INIT_ARRAY_SECTION_ASM_OP (pa64-hpux, arm,
m32c, rx) and on {i?86,x86_64,ia64}-linux and some solaris target.

	Jakub

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-19 10:05                           ` Jakub Jelinek
@ 2011-08-19 14:58                             ` H.J. Lu
  2011-08-19 15:54                               ` Jakub Jelinek
  0 siblings, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-08-19 14:58 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 5822 bytes --]

On Fri, Aug 19, 2011 at 1:17 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Sorry for the delay.
>
>> --- a/gcc/config.gcc
>> +++ b/gcc/config.gcc
>> @@ -186,6 +186,9 @@
>>  #  configure_default_options
>>  #                    Set to an initializer for configure_default_options
>>  #                    in configargs.h, based on --with-cpu et cetera.
>> +#
>> +#  use_initfini_array        If set to yes, .init_array/.fini_array sections
>> +#                    will be used if they work.
>>
>>  # The following variables are used in each case-construct to build up the
>>  # outgoing variables:
>> @@ -238,6 +241,7 @@ default_gnu_indirect_function=no
>>  target_gtfiles=
>>  need_64bit_hwint=
>>  need_64bit_isa=
>> +use_initfini_array=yes
>
> What is this for, when nothing ever sets it to anything but yes?
> If the $enable_initfini_array = yes test works, then there shouldn't be
> any need to override it on a per-target basis...

Done.

>> --- /dev/null
>> +++ b/gcc/config/initfini-array.h
>> @@ -0,0 +1,44 @@
>> +/* Definitions for ELF systems with .init_array/.fini_array section
>> +   support.
>> +   Copyright (C) 2011
>> +   Free Software Foundation, Inc.
>> +
>> +   This file is part of GCC.
>> +
>> +   GCC is free software; you can redistribute it and/or modify it
>> +   under the terms of the GNU General Public License as published
>> +   by the Free Software Foundation; either version 3, or (at your
>> +   option) any later version.
>> +
>> +   GCC is distributed in the hope that it will be useful, but WITHOUT
>> +   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
>> +   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
>> +   License for more details.
>> +
>> +   You should have received a copy of the GNU General Public License
>> +   along with GCC; see the file COPYING3.  If not see
>> +   <http://www.gnu.org/licenses/>.  */
>> +
>> +#define USE_INITFINI_ARRAY
>> +
>> +#undef INIT_SECTION_ASM_OP
>> +#undef FINI_SECTION_ASM_OP
>> +
>> +/* FIXME: INIT_ARRAY_SECTION_ASM_OP and FINI_ARRAY_SECTION_ASM_OP
>> +       aren't used in any assembly codes.  But we have to define
>> +       them to something.  */
>> +#define INIT_ARRAY_SECTION_ASM_OP Something
>> +#define FINI_ARRAY_SECTION_ASM_OP Something
>
> Can't you just define it to an empty string?  And, a couple of targets
> define INIT_ARRAY_SECTION_ASM_OP/FINI_ARRAY_SECTION_ASM_OP, you either need
> to undef it first, or define only if it wasn't defined.

Done.

>> +
>> +#ifndef TARGET_ASM_INIT_SECTIONS
>> +#define TARGET_ASM_INIT_SECTIONS default_elf_initfini_array_init_sections
>> +#endif
>> +extern void default_elf_initfini_array_init_sections (void);
>
> Why do you need this (and the default_initfini_array_init_sections () call
> in all the backends)?  Isn't it easier to just initialize the two global
> vars only when you are actually going to use them (if they are still NULL)?

Done.

>> --- a/gcc/varasm.c
>> +++ b/gcc/varasm.c
>> @@ -7350,4 +7350,62 @@ make_debug_expr_from_rtl (const_rtx exp)
>>    return dval;
>>  }
>>
>> +static GTY(()) section *elf_init_array_section;
>> +static GTY(()) section *elf_fini_array_section;
>> +
>> +void
>> +default_elf_initfini_array_init_sections (void)
>> +{
>> +  elf_init_array_section = get_unnamed_section (0, output_section_asm_op,
>> +                                             "\t.section\t.init_array");
>> +  elf_fini_array_section = get_unnamed_section (0, output_section_asm_op,
>> +                                             "\t.section\t.fini_array");
>> +}
>
> Remove above function.

Done.

>> +
>> +static section *
>> +get_elf_initfini_array_priority_section (int priority,
>> +                                      bool constructor_p)
>> +{
>> +  section *sec;
>> +  if (priority != DEFAULT_INIT_PRIORITY)
>> +    {
>> +      char buf[18];
>> +      sprintf (buf, "%s.%.5u",
>> +            constructor_p ? ".init_array" : ".fini_array",
>> +            priority);
>> +      sec = get_section (buf, SECTION_WRITE, NULL_TREE);
>> +    }
>
> I'd just put here
>   else
>     {
>       if (elf_init_array_section == NULL)
>         elf_init_array_section = get_unnamed_section...
>       if (elf_fini_array_section == NULL)
>         elf_fini_array_section = get_unnamed_section...
>> +    sec = constructor_p ? elf_init_array_section : elf_fini_array_section;
>     }

Done.

>> +void
>> +default_initfini_array_init_sections (void)
>> +{
>> +#ifdef USE_INITFINI_ARRAY
>> +  default_elf_initfini_array_init_sections ();
>> +#endif
>> +}
>
> And remove this (and all callers etc.).

Done.

> On which targets has it been tested?  Would be nice to test it at least on
> targets that define their own INIT_ARRAY_SECTION_ASM_OP (pa64-hpux, arm,
> m32c, rx) and on {i?86,x86_64,ia64}-linux and some solaris target.
>

Here is the updated patch. I tested it on Linux/ia32 and Linux/x86-64.
OK for trunk?

Bootstrap on Linux/ia64 has failed for a while and I don't have other
platforms. If it can't be easily tested on other affected platforms, can
we just enable it for Linux/ia32 and Linux/x86-64 first?

Thanks.

-- 
H.J.
----
2011-08-19  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/46770
	* config.gcc (tm_file): Add initfini-array.h if
	.init_arary/.fini_array supported.

	* crtstuff.c: Don't generate .ctors nor .dtors sections if
	USE_INITFINI_ARRAY is defined.

	* varasm.c (elf_init_array_section): New.
	(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.

[-- Attachment #2: gcc-pr46770-9.patch --]
[-- Type: text/plain, Size: 6499 bytes --]

2011-08-19  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/46770
	* config.gcc (tm_file): Add initfini-array.h if
	.init_arary/.fini_array supported.

	* crtstuff.c: Don't generate .ctors nor .dtors sections if
	USE_INITFINI_ARRAY is defined.

	* varasm.c (elf_init_array_section): New.
	(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.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index b92ce3d..7f29213 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3058,6 +3058,11 @@ if test x$with_schedule = x; then
 	esac
 fi
 
+# Support --enable-initfini-array.
+if test x$enable_initfini_array = xyes; then
+  tm_file="${tm_file} initfini-array.h"
+fi
+
 # Validate and mark as valid any --with options supported
 # by this target.  In order to use a particular --with option
 # you must list it in supported_defaults; validating the value
diff --git a/gcc/config/initfini-array.h b/gcc/config/initfini-array.h
new file mode 100644
index 0000000..b5b95cb
--- /dev/null
+++ b/gcc/config/initfini-array.h
@@ -0,0 +1,39 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   support.
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+#define USE_INITFINI_ARRAY
+
+#undef INIT_SECTION_ASM_OP
+#undef FINI_SECTION_ASM_OP
+
+#undef INIT_ARRAY_SECTION_ASM_OP
+#define INIT_ARRAY_SECTION_ASM_OP
+
+#undef FINI_ARRAY_SECTION_ASM_OP
+#define FINI_ARRAY_SECTION_ASM_OP
+
+/* Use .init_array/.fini_array section for constructors and destructors. */
+#undef TARGET_ASM_CONSTRUCTOR
+#define TARGET_ASM_CONSTRUCTOR default_elf_init_array_asm_out_constructor
+#undef TARGET_ASM_DESTRUCTOR
+#define TARGET_ASM_DESTRUCTOR default_elf_fini_array_asm_out_destructor
+extern void default_elf_init_array_asm_out_constructor (rtx, int);
+extern void default_elf_fini_array_asm_out_destructor (rtx, int);
diff --git a/gcc/crtstuff.c b/gcc/crtstuff.c
index b65f490..010d472 100644
--- a/gcc/crtstuff.c
+++ b/gcc/crtstuff.c
@@ -1,7 +1,8 @@
 /* Specialized bits of code needed to support construction and
    destruction of file-scope objects in C++ code.
    Copyright (C) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
+   Free Software Foundation, Inc.
    Contributed by Ron Guilmette (rfg@monkeys.com).
 
 This file is part of GCC.
@@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
    refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
    symbol in crtbegin.o, where they are defined.  */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef USE_INITFINI_ARRAY
 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
    does not start with a count of elements.  */
 #ifdef CTOR_LIST_BEGIN
@@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
   __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) (-1) };
 #endif /* __DTOR_LIST__ alternatives */
+#endif /* USE_INITFINI_ARRAY */
 
 #ifdef USE_EH_FRAME_REGISTRY
 /* Stick a label at the beginning of the frame unwind info so we can register
@@ -489,6 +494,9 @@ __do_global_ctors_1(void)
 
 #elif defined(CRT_END) /* ! CRT_BEGIN */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef USE_INITFINI_ARRAY
 /* Put a word containing zero at the end of each of our two lists of function
    addresses.  Note that the words defined here go into the .ctors and .dtors
    sections of the crtend.o file, and since that file is always linked in
@@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
   __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) 0 };
 #endif
+#endif /* USE_INITFINI_ARRAY */
 
 #ifdef EH_FRAME_SECTION_NAME
 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
diff --git a/gcc/varasm.c b/gcc/varasm.c
index ca56813..218baf3 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -7352,4 +7352,62 @@ make_debug_expr_from_rtl (const_rtx exp)
   return dval;
 }
 
+static GTY(()) section *elf_init_array_section;
+static GTY(()) section *elf_fini_array_section;
+
+static section *
+get_elf_initfini_array_priority_section (int priority,
+					 bool constructor_p)
+{
+  section *sec;
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      char buf[18];
+      sprintf (buf, "%s.%.5u", 
+	       constructor_p ? ".init_array" : ".fini_array",
+	       priority);
+      sec = get_section (buf, SECTION_WRITE, NULL_TREE);
+    }
+  else
+    {
+      if (constructor_p)
+	{
+	  if (elf_init_array_section == NULL)
+	    elf_init_array_section
+	      = get_unnamed_section (0, output_section_asm_op,
+				     "\t.section\t.init_array");
+	  sec = elf_init_array_section;
+	}
+      else
+	{
+	  if (elf_fini_array_section == NULL)
+	    elf_fini_array_section
+	      = get_unnamed_section (0, output_section_asm_op,
+				     "\t.section\t.fini_array");
+	  sec = elf_fini_array_section;
+	}
+    }
+  return sec;
+}
+
+/* Use .init_array section for constructors. */
+
+void
+default_elf_init_array_asm_out_constructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  true);
+  assemble_addr_to_section (symbol, sec);
+}
+
+/* Use .fini_array section for destructors. */
+
+void
+default_elf_fini_array_asm_out_destructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  false);
+  assemble_addr_to_section (symbol, sec);
+}
+
 #include "gt-varasm.h"

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-19 14:58                             ` H.J. Lu
@ 2011-08-19 15:54                               ` Jakub Jelinek
  2011-08-20 21:16                                 ` H.J. Lu
  0 siblings, 1 reply; 46+ messages in thread
From: Jakub Jelinek @ 2011-08-19 15:54 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches

On Fri, Aug 19, 2011 at 07:47:40AM -0700, H.J. Lu wrote:
> 2011-08-19  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	PR target/46770
> 	* config.gcc (tm_file): Add initfini-array.h if
> 	.init_arary/.fini_array supported.

s/arary/array/

Ok if nobody objects within 24 hours, but please watch for any fallouts.

	Jakub

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-19 15:54                               ` Jakub Jelinek
@ 2011-08-20 21:16                                 ` H.J. Lu
  2012-03-19 20:35                                   ` DJ Delorie
  0 siblings, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-08-20 21:16 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1396 bytes --]

On Fri, Aug 19, 2011 at 7:55 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Fri, Aug 19, 2011 at 07:47:40AM -0700, H.J. Lu wrote:
>> 2011-08-19  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>       PR target/46770
>>       * config.gcc (tm_file): Add initfini-array.h if
>>       .init_arary/.fini_array supported.
>
> s/arary/array/
>
> Ok if nobody objects within 24 hours, but please watch for any fallouts.
>
>        Jakub
>

This is the patch I checked in. I moved
default_elf_init_array_asm_out_constructor
and default_elf_fini_array_asm_out_destructor from config/initfini-array.h to
output.h so that we won't get warnings if .init_arrary/.fini_array
sections aren't
enabled.

Thanks.

-- 
H.J.
---
2011-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/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.

[-- Attachment #2: gcc-pr46770-10.patch --]
[-- Type: text/plain, Size: 6992 bytes --]

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.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index b92ce3d..7f29213 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3058,6 +3058,11 @@ if test x$with_schedule = x; then
 	esac
 fi
 
+# Support --enable-initfini-array.
+if test x$enable_initfini_array = xyes; then
+  tm_file="${tm_file} initfini-array.h"
+fi
+
 # Validate and mark as valid any --with options supported
 # by this target.  In order to use a particular --with option
 # you must list it in supported_defaults; validating the value
diff --git a/gcc/config/initfini-array.h b/gcc/config/initfini-array.h
new file mode 100644
index 0000000..8aaadf6
--- /dev/null
+++ b/gcc/config/initfini-array.h
@@ -0,0 +1,37 @@
+/* Definitions for ELF systems with .init_array/.fini_array section
+   support.
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+#define USE_INITFINI_ARRAY
+
+#undef INIT_SECTION_ASM_OP
+#undef FINI_SECTION_ASM_OP
+
+#undef INIT_ARRAY_SECTION_ASM_OP
+#define INIT_ARRAY_SECTION_ASM_OP
+
+#undef FINI_ARRAY_SECTION_ASM_OP
+#define FINI_ARRAY_SECTION_ASM_OP
+
+/* Use .init_array/.fini_array section for constructors and destructors. */
+#undef TARGET_ASM_CONSTRUCTOR
+#define TARGET_ASM_CONSTRUCTOR default_elf_init_array_asm_out_constructor
+#undef TARGET_ASM_DESTRUCTOR
+#define TARGET_ASM_DESTRUCTOR default_elf_fini_array_asm_out_destructor
diff --git a/gcc/crtstuff.c b/gcc/crtstuff.c
index b65f490..010d472 100644
--- a/gcc/crtstuff.c
+++ b/gcc/crtstuff.c
@@ -1,7 +1,8 @@
 /* Specialized bits of code needed to support construction and
    destruction of file-scope objects in C++ code.
    Copyright (C) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
+   Free Software Foundation, Inc.
    Contributed by Ron Guilmette (rfg@monkeys.com).
 
 This file is part of GCC.
@@ -189,6 +190,9 @@ typedef void (*func_ptr) (void);
    refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
    symbol in crtbegin.o, where they are defined.  */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef USE_INITFINI_ARRAY
 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
    does not start with a count of elements.  */
 #ifdef CTOR_LIST_BEGIN
@@ -219,6 +223,7 @@ STATIC func_ptr __DTOR_LIST__[1]
   __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) (-1) };
 #endif /* __DTOR_LIST__ alternatives */
+#endif /* USE_INITFINI_ARRAY */
 
 #ifdef USE_EH_FRAME_REGISTRY
 /* Stick a label at the beginning of the frame unwind info so we can register
@@ -489,6 +494,9 @@ __do_global_ctors_1(void)
 
 #elif defined(CRT_END) /* ! CRT_BEGIN */
 
+/* No need for .ctors/.dtors section if linker can place them in
+   .init_array/.fini_array section.  */
+#ifndef USE_INITFINI_ARRAY
 /* Put a word containing zero at the end of each of our two lists of function
    addresses.  Note that the words defined here go into the .ctors and .dtors
    sections of the crtend.o file, and since that file is always linked in
@@ -534,6 +542,7 @@ STATIC func_ptr __DTOR_END__[1]
   __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
   = { (func_ptr) 0 };
 #endif
+#endif /* USE_INITFINI_ARRAY */
 
 #ifdef EH_FRAME_SECTION_NAME
 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
diff --git a/gcc/output.h b/gcc/output.h
index c668d35..6b7c4b8 100644
--- a/gcc/output.h
+++ b/gcc/output.h
@@ -654,6 +654,8 @@ extern void file_end_indicate_split_stack (void);
 
 extern void default_elf_asm_output_external (FILE *file, tree,
 					     const char *);
+extern void default_elf_init_array_asm_out_constructor (rtx, int);
+extern void default_elf_fini_array_asm_out_destructor (rtx, int);
 extern int maybe_assemble_visibility (tree);
 
 extern int default_address_cost (rtx, bool);
diff --git a/gcc/varasm.c b/gcc/varasm.c
index ca56813..218baf3 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -7352,4 +7352,62 @@ make_debug_expr_from_rtl (const_rtx exp)
   return dval;
 }
 
+static GTY(()) section *elf_init_array_section;
+static GTY(()) section *elf_fini_array_section;
+
+static section *
+get_elf_initfini_array_priority_section (int priority,
+					 bool constructor_p)
+{
+  section *sec;
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      char buf[18];
+      sprintf (buf, "%s.%.5u", 
+	       constructor_p ? ".init_array" : ".fini_array",
+	       priority);
+      sec = get_section (buf, SECTION_WRITE, NULL_TREE);
+    }
+  else
+    {
+      if (constructor_p)
+	{
+	  if (elf_init_array_section == NULL)
+	    elf_init_array_section
+	      = get_unnamed_section (0, output_section_asm_op,
+				     "\t.section\t.init_array");
+	  sec = elf_init_array_section;
+	}
+      else
+	{
+	  if (elf_fini_array_section == NULL)
+	    elf_fini_array_section
+	      = get_unnamed_section (0, output_section_asm_op,
+				     "\t.section\t.fini_array");
+	  sec = elf_fini_array_section;
+	}
+    }
+  return sec;
+}
+
+/* Use .init_array section for constructors. */
+
+void
+default_elf_init_array_asm_out_constructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  true);
+  assemble_addr_to_section (symbol, sec);
+}
+
+/* Use .fini_array section for destructors. */
+
+void
+default_elf_fini_array_asm_out_destructor (rtx symbol, int priority)
+{
+  section *sec = get_elf_initfini_array_priority_section (priority,
+							  false);
+  assemble_addr_to_section (symbol, sec);
+}
+
 #include "gt-varasm.h"

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-20 21:16                                 ` H.J. Lu
@ 2012-03-19 20:35                                   ` DJ Delorie
  2012-03-19 20:40                                     ` Andrew Pinski
  0 siblings, 1 reply; 46+ messages in thread
From: DJ Delorie @ 2012-03-19 20:35 UTC (permalink / raw)
  To: H.J. Lu; +Cc: jakub, gcc-patches


This breaks constructors on pretty much every elf+newlib target,
because newlib and gcc both use HAVE_INITFINI_ARRAY (and have for many
years) but the tests don't match.  GCC puts ctors in .ctors but libgcc
is built without support for them (newlib's generated config headers
define HAVE_INITFINI_ARRAY, which causes gcc's initini-array.h to set
USE_INITFINI_ARRAY, which shuts off libgcc's ctor/dtor support), so
they don't run.

> 2011-08-20  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	PR target/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.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2012-03-19 20:35                                   ` DJ Delorie
@ 2012-03-19 20:40                                     ` Andrew Pinski
  2012-03-19 20:42                                       ` DJ Delorie
  0 siblings, 1 reply; 46+ messages in thread
From: Andrew Pinski @ 2012-03-19 20:40 UTC (permalink / raw)
  To: DJ Delorie; +Cc: H.J. Lu, jakub, gcc-patches

On Mon, Mar 19, 2012 at 1:34 PM, DJ Delorie <dj@redhat.com> wrote:
>
> This breaks constructors on pretty much every elf+newlib target,
> because newlib and gcc both use HAVE_INITFINI_ARRAY (and have for many
> years) but the tests don't match.  GCC puts ctors in .ctors but libgcc
> is built without support for them (newlib's generated config headers
> define HAVE_INITFINI_ARRAY, which causes gcc's initini-array.h to set
> USE_INITFINI_ARRAY, which shuts off libgcc's ctor/dtor support), so
> they don't run.

This should have been fixed by:
2012-02-23  Ulrich Weigand  <Ulrich.Weigand@de.ibm.com>

        * acinclude.m4: Use HAVE_INITFINI_ARRAY_SUPPORT instead of
        HAVE_INITFINI_ARRAY to work around namespace pollution in
        certain versions of newlib system headers.
        * config.in: Regenerate.
        * configure: Regenerate.
        * config/initfini-array.h: Use HAVE_INITFINI_ARRAY_SUPPORT
        instead of HAVE_INITFINI_ARRAY.

Thanks,
Andrew Pinski


>
>> 2011-08-20  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>       PR target/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.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2012-03-19 20:40                                     ` Andrew Pinski
@ 2012-03-19 20:42                                       ` DJ Delorie
  0 siblings, 0 replies; 46+ messages in thread
From: DJ Delorie @ 2012-03-19 20:42 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: hjl.tools, jakub, gcc-patches


Sweet!  Thanks!  We hadn't merged that bit into our tree yet...

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22 19:38           ` Joseph S. Myers
@ 2011-08-22 20:50             ` H.J. Lu
  0 siblings, 0 replies; 46+ messages in thread
From: H.J. Lu @ 2011-08-22 20:50 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: Jakub Jelinek, David Edelsohn, GCC Patches

On Mon, Aug 22, 2011 at 11:59 AM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> On Mon, 22 Aug 2011, H.J. Lu wrote:
>
>> > Require a good assembler on ELF targets and just enable this by default
>> > for them without trying a configure test that won't work for cross
>> > compilation (AC_RUN_IFELSE is bad).
>> >
>> > The toplevel config/elf.m4 provides a good notion of what is or is not
>> > ELF (if there are problems, we can fix that file).  Only a handful of
>> > targets support non-GNU assemblers; for the vast bulk of targets we should
>> > assume a not-too-old GNU assembler.  That way, the configure test can be
>> > used to cause a configure-time error if the assembler is defective and it
>> > doesn't matter that the test is late.
>> >
>>
>> A working .init_array support needs assembler, linker and libc.
>> That is why AC_RUN_IFELSE is used.
>
> A working .init_array is a standard part of ELF.  The correct default for
> cross compilation to an ELF target (as determined by elf.m4) is to assume
> it is present; this is not a matter of a GNU extension that could affect
> interoperation with other tools.
>

I wish we can make  .init_array support mandatory.  One problem is
to support mixing input .ctors/.init_array sections to generate
output .init_array section.  Not all linkers support it.  This is a new
feature.  I don't want to cause any more trouble.

Currently, one can force to enable .init_array support by setting
enable_initfini_array to yes.

-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22 19:19         ` H.J. Lu
@ 2011-08-22 19:38           ` Joseph S. Myers
  2011-08-22 20:50             ` H.J. Lu
  0 siblings, 1 reply; 46+ messages in thread
From: Joseph S. Myers @ 2011-08-22 19:38 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jakub Jelinek, David Edelsohn, GCC Patches

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1089 bytes --]

On Mon, 22 Aug 2011, H.J. Lu wrote:

> > Require a good assembler on ELF targets and just enable this by default
> > for them without trying a configure test that won't work for cross
> > compilation (AC_RUN_IFELSE is bad).
> >
> > The toplevel config/elf.m4 provides a good notion of what is or is not
> > ELF (if there are problems, we can fix that file).  Only a handful of
> > targets support non-GNU assemblers; for the vast bulk of targets we should
> > assume a not-too-old GNU assembler.  That way, the configure test can be
> > used to cause a configure-time error if the assembler is defective and it
> > doesn't matter that the test is late.
> >
> 
> A working .init_array support needs assembler, linker and libc.
> That is why AC_RUN_IFELSE is used.

A working .init_array is a standard part of ELF.  The correct default for 
cross compilation to an ELF target (as determined by elf.m4) is to assume 
it is present; this is not a matter of a GNU extension that could affect 
interoperation with other tools.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22 19:12       ` Joseph S. Myers
@ 2011-08-22 19:19         ` H.J. Lu
  2011-08-22 19:38           ` Joseph S. Myers
  0 siblings, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-08-22 19:19 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: Jakub Jelinek, David Edelsohn, GCC Patches

On Mon, Aug 22, 2011 at 11:53 AM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> On Mon, 22 Aug 2011, H.J. Lu wrote:
>
>> On Sun, Aug 21, 2011 at 10:37 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>> nd/or add another test to it that tests
>> > that you can actually use
>> > .section .init_array
>> > and it will use correct section flags for the section.
>> >
>>
>> We need this information in config.gcc. But config.gcc is used
>> before assembler and readelf are detected. I am running out of
>> ideas.  Any suggestions?
>
> Require a good assembler on ELF targets and just enable this by default
> for them without trying a configure test that won't work for cross
> compilation (AC_RUN_IFELSE is bad).
>
> The toplevel config/elf.m4 provides a good notion of what is or is not
> ELF (if there are problems, we can fix that file).  Only a handful of
> targets support non-GNU assemblers; for the vast bulk of targets we should
> assume a not-too-old GNU assembler.  That way, the configure test can be
> used to cause a configure-time error if the assembler is defective and it
> doesn't matter that the test is late.
>

A working .init_array support needs assembler, linker and libc.
That is why AC_RUN_IFELSE is used.

-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22 17:37     ` H.J. Lu
  2011-08-22 18:33       ` H.J. Lu
@ 2011-08-22 19:12       ` Joseph S. Myers
  2011-08-22 19:19         ` H.J. Lu
  1 sibling, 1 reply; 46+ messages in thread
From: Joseph S. Myers @ 2011-08-22 19:12 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jakub Jelinek, David Edelsohn, GCC Patches

On Mon, 22 Aug 2011, H.J. Lu wrote:

> On Sun, Aug 21, 2011 at 10:37 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> nd/or add another test to it that tests
> > that you can actually use
> > .section .init_array
> > and it will use correct section flags for the section.
> >
> 
> We need this information in config.gcc. But config.gcc is used
> before assembler and readelf are detected. I am running out of
> ideas.  Any suggestions?

Require a good assembler on ELF targets and just enable this by default 
for them without trying a configure test that won't work for cross 
compilation (AC_RUN_IFELSE is bad).

The toplevel config/elf.m4 provides a good notion of what is or is not 
ELF (if there are problems, we can fix that file).  Only a handful of 
targets support non-GNU assemblers; for the vast bulk of targets we should 
assume a not-too-old GNU assembler.  That way, the configure test can be 
used to cause a configure-time error if the assembler is defective and it 
doesn't matter that the test is late.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22 17:37     ` H.J. Lu
@ 2011-08-22 18:33       ` H.J. Lu
  2011-08-22 19:12       ` Joseph S. Myers
  1 sibling, 0 replies; 46+ messages in thread
From: H.J. Lu @ 2011-08-22 18:33 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: David Edelsohn, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 866 bytes --]

On Mon, Aug 22, 2011 at 10:09 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Sun, Aug 21, 2011 at 10:37 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> nd/or add another test to it that tests
>> that you can actually use
>> .section .init_array
>> and it will use correct section flags for the section.
>>
>
> We need this information in config.gcc. But config.gcc is used
> before assembler and readelf are detected. I am running out of
> ideas.  Any suggestions?
>
> Thanks.
>

This is a much bigger change that I like and I don't feel very comfortable
about it since I can only test it on Linux/x86.


-- 
H.J.
----
2011-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	* acinclude.m4 (gcc_AC_INITFINI_ARRAY): Check if
	".section .init_array" works.

	* configure.ac: Move binutils tests before gcc_AC_INITFINI_ARRAY.
	* configure: Regenerated.

[-- Attachment #2: gcc-init-array-1.patch --]
[-- Type: text/x-diff, Size: 16995 bytes --]

diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4
index a8ecd2d..3827046 100644
--- a/gcc/acinclude.m4
+++ b/gcc/acinclude.m4
@@ -376,6 +376,18 @@ AC_DEFUN([gcc_AC_INITFINI_ARRAY],
 AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support,
 		 gcc_cv_initfini_array, [dnl
   if test "x${build}" = "x${target}" && test "x${build}" = "x${host}"; then
+    if test x$gcc_cv_as != x -a x$gcc_cv_readelf != x ; then
+      echo ".section .init_array; .byte 0" > conftest.s
+      if $gcc_cv_as -o conftest.o conftest.s > /dev/null 2>&1; then
+	if $gcc_cv_readelf -S --wide conftest.o 2>&1 \
+	   | grep INIT_ARRAY > /dev/null 2>&1; then
+	  gcc_cv_as_init_array=yes
+	fi
+      fi
+      rm -f conftest.s conftest.o
+    fi
+  fi
+  if test "x${gcc_cv_as_init_array}" = xyes; then
     AC_RUN_IFELSE([AC_LANG_SOURCE([
 #ifndef __ELF__
 #error Not an ELF OS
diff --git a/gcc/configure.ac b/gcc/configure.ac
index ed01904..3cae58a 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1153,6 +1153,231 @@ fi
 # Restore CFLAGS from before the gcc_AC_NEED_DECLARATIONS tests.
 CFLAGS="$saved_CFLAGS"
 
+# Identify the assembler which will work hand-in-glove with the newly
+# built GCC, so that we can examine its features.  This is the assembler
+# which will be driven by the driver program.
+#
+# If build != host, and we aren't building gas in-tree, we identify a
+# build->target assembler and hope that it will have the same features
+# as the host->target assembler we'll be using.
+gcc_cv_gas_major_version=
+gcc_cv_gas_minor_version=
+gcc_cv_as_gas_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/gas
+
+m4_pattern_allow([AS_FOR_TARGET])dnl
+AS_VAR_SET_IF(gcc_cv_as,, [
+if test -x "$DEFAULT_ASSEMBLER"; then
+	gcc_cv_as="$DEFAULT_ASSEMBLER"
+elif test -f $gcc_cv_as_gas_srcdir/configure.in \
+     && test -f ../gas/Makefile \
+     && test x$build = x$host; then
+	gcc_cv_as=../gas/as-new$build_exeext
+elif test -x as$build_exeext; then
+	# Build using assembler in the current directory.
+	gcc_cv_as=./as$build_exeext
+elif ( set dummy $AS_FOR_TARGET; test -x $[2] ); then
+        gcc_cv_as="$AS_FOR_TARGET"
+else
+        AC_PATH_PROG(gcc_cv_as, $AS_FOR_TARGET)
+fi])
+
+ORIGINAL_AS_FOR_TARGET=$gcc_cv_as
+AC_SUBST(ORIGINAL_AS_FOR_TARGET)
+case "$ORIGINAL_AS_FOR_TARGET" in
+  ./as | ./as$build_exeext) ;;
+  *) AC_CONFIG_FILES(as:exec-tool.in, [chmod +x as]) ;;
+esac 
+
+AC_MSG_CHECKING(what assembler to use)
+if test "$gcc_cv_as" = ../gas/as-new$build_exeext; then
+  # Single tree build which includes gas.  We want to prefer it
+  # over whatever linker top-level may have detected, since
+  # we'll use what we're building after installation anyway.
+  AC_MSG_RESULT(newly built gas)
+  in_tree_gas=yes
+  _gcc_COMPUTE_GAS_VERSION
+  in_tree_gas_is_elf=no
+  if grep 'obj_format = elf' ../gas/Makefile > /dev/null \
+     || (grep 'obj_format = multi' ../gas/Makefile \
+         && grep 'extra_objects =.* obj-elf' ../gas/Makefile) > /dev/null
+  then
+    in_tree_gas_is_elf=yes
+  fi
+else
+  AC_MSG_RESULT($gcc_cv_as)
+  in_tree_gas=no
+fi
+
+# Identify the linker which will work hand-in-glove with the newly
+# built GCC, so that we can examine its features.  This is the linker
+# which will be driven by the driver program.
+#
+# If build != host, and we aren't building gas in-tree, we identify a
+# build->target linker and hope that it will have the same features
+# as the host->target linker we'll be using.
+gcc_cv_gld_major_version=
+gcc_cv_gld_minor_version=
+gcc_cv_ld_gld_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/ld
+gcc_cv_ld_bfd_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/bfd
+
+AS_VAR_SET_IF(gcc_cv_ld,, [
+if test -x "$DEFAULT_LINKER"; then
+	gcc_cv_ld="$DEFAULT_LINKER"
+elif test -f $gcc_cv_ld_gld_srcdir/configure.in \
+     && test -f ../ld/Makefile \
+     && test x$build = x$host; then
+	gcc_cv_ld=../ld/ld-new$build_exeext
+elif test -x collect-ld$build_exeext; then
+	# Build using linker in the current directory.
+	gcc_cv_ld=./collect-ld$build_exeext
+elif ( set dummy $LD_FOR_TARGET; test -x $[2] ); then
+        gcc_cv_ld="$LD_FOR_TARGET"
+else
+        AC_PATH_PROG(gcc_cv_ld, $LD_FOR_TARGET)
+fi])
+
+ORIGINAL_PLUGIN_LD_FOR_TARGET=$gcc_cv_ld
+PLUGIN_LD=`basename $gcc_cv_ld`
+AC_ARG_WITH(plugin-ld,
+[AS_HELP_STRING([[--with-plugin-ld=[ARG]]], [specify the plugin linker])],
+[if test x"$withval" != x; then
+   ORIGINAL_PLUGIN_LD_FOR_TARGET="$withval"
+   PLUGIN_LD="$withval"
+ fi])
+AC_SUBST(ORIGINAL_PLUGIN_LD_FOR_TARGET)
+AC_DEFINE_UNQUOTED(PLUGIN_LD, "$PLUGIN_LD", [Specify plugin linker])
+
+# Check to see if we are using gold instead of ld
+AC_MSG_CHECKING(whether we are using gold)
+ld_is_gold=no
+if test x$gcc_cv_ld != x; then
+  if $gcc_cv_ld --version 2>/dev/null | sed 1q \
+     | grep "GNU gold" > /dev/null; then
+    ld_is_gold=yes
+  fi
+fi
+AC_MSG_RESULT($ld_is_gold)
+
+ORIGINAL_LD_FOR_TARGET=$gcc_cv_ld
+AC_SUBST(ORIGINAL_LD_FOR_TARGET)
+case "$ORIGINAL_LD_FOR_TARGET" in
+  ./collect-ld | ./collect-ld$build_exeext) ;;
+  *) AC_CONFIG_FILES(collect-ld:exec-tool.in, [chmod +x collect-ld]) ;;
+esac 
+
+AC_MSG_CHECKING(what linker to use)
+if test "$gcc_cv_ld" = ../ld/ld-new$build_exeext \
+   || test "$gcc_cv_ld" = ../gold/ld-new$build_exeext; then
+	# Single tree build which includes ld.  We want to prefer it
+	# over whatever linker top-level may have detected, since
+	# we'll use what we're building after installation anyway.
+	AC_MSG_RESULT(newly built ld)
+	in_tree_ld=yes
+	in_tree_ld_is_elf=no
+	if (grep 'EMUL = .*elf' ../ld/Makefile \
+	    || grep 'EMUL = .*linux' ../ld/Makefile \
+	    || grep 'EMUL = .*lynx' ../ld/Makefile) > /dev/null; then
+	  in_tree_ld_is_elf=yes
+	elif test "$ld_is_gold" = yes; then
+	  in_tree_ld_is_elf=yes
+	fi
+	for f in $gcc_cv_ld_bfd_srcdir/configure $gcc_cv_ld_gld_srcdir/configure $gcc_cv_ld_gld_srcdir/configure.in $gcc_cv_ld_gld_srcdir/Makefile.in
+	do
+changequote(,)dnl
+		gcc_cv_gld_version=`sed -n -e 's/^[ 	]*\(VERSION=[0-9]*\.[0-9]*.*\)/\1/p' < $f`
+		if test x$gcc_cv_gld_version != x; then
+			break
+		fi
+	done
+	gcc_cv_gld_major_version=`expr "$gcc_cv_gld_version" : "VERSION=\([0-9]*\)"`
+	gcc_cv_gld_minor_version=`expr "$gcc_cv_gld_version" : "VERSION=[0-9]*\.\([0-9]*\)"`
+changequote([,])dnl
+else
+	AC_MSG_RESULT($gcc_cv_ld)
+	in_tree_ld=no
+fi
+
+# Figure out what nm we will be using.
+gcc_cv_binutils_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/binutils
+AS_VAR_SET_IF(gcc_cv_nm,, [
+if test -f $gcc_cv_binutils_srcdir/configure.in \
+     && test -f ../binutils/Makefile \
+     && test x$build = x$host; then
+	gcc_cv_nm=../binutils/nm-new$build_exeext
+elif test -x nm$build_exeext; then
+	gcc_cv_nm=./nm$build_exeext
+elif ( set dummy $NM_FOR_TARGET; test -x $[2] ); then
+        gcc_cv_nm="$NM_FOR_TARGET"
+else
+        AC_PATH_PROG(gcc_cv_nm, $NM_FOR_TARGET)
+fi])
+
+AC_MSG_CHECKING(what nm to use)
+if test "$gcc_cv_nm" = ../binutils/nm-new$build_exeext; then
+	# Single tree build which includes binutils.
+	AC_MSG_RESULT(newly built nm)
+	in_tree_nm=yes
+else
+	AC_MSG_RESULT($gcc_cv_nm)
+	in_tree_nm=no
+fi
+
+ORIGINAL_NM_FOR_TARGET=$gcc_cv_nm
+AC_SUBST(ORIGINAL_NM_FOR_TARGET)
+case "$ORIGINAL_NM_FOR_TARGET" in
+  ./nm | ./nm$build_exeext) ;;
+  *) AC_CONFIG_FILES(nm:exec-tool.in, [chmod +x nm]) ;;
+esac
+
+
+# Figure out what objdump we will be using.
+AS_VAR_SET_IF(gcc_cv_objdump,, [
+if test -f $gcc_cv_binutils_srcdir/configure.in \
+     && test -f ../binutils/Makefile \
+     && test x$build = x$host; then
+	# Single tree build which includes binutils.
+	gcc_cv_objdump=../binutils/objdump$build_exeext
+elif test -x objdump$build_exeext; then
+	gcc_cv_objdump=./objdump$build_exeext
+elif ( set dummy $OBJDUMP_FOR_TARGET; test -x $[2] ); then
+        gcc_cv_objdump="$OBJDUMP_FOR_TARGET"
+else
+        AC_PATH_PROG(gcc_cv_objdump, $OBJDUMP_FOR_TARGET)
+fi])
+
+AC_MSG_CHECKING(what objdump to use)
+if test "$gcc_cv_objdump" = ../binutils/objdump$build_exeext; then
+	# Single tree build which includes binutils.
+	AC_MSG_RESULT(newly built objdump)
+elif test x$gcc_cv_objdump = x; then
+	AC_MSG_RESULT(not found)
+else
+	AC_MSG_RESULT($gcc_cv_objdump)
+fi
+
+# Figure out what readelf we will be using.
+AS_VAR_SET_IF(gcc_cv_readelf,, [
+if test -f $gcc_cv_binutils_srcdir/configure.in \
+     && test -f ../binutils/Makefile \
+     && test x$build = x$host; then
+	# Single tree build which includes binutils.
+	gcc_cv_readelf=../binutils/readelf$build_exeext
+elif test -x readelf$build_exeext; then
+	gcc_cv_readelf=./readelf$build_exeext
+else
+        AC_PATH_PROG(gcc_cv_readelf, readelf)
+fi])
+
+AC_MSG_CHECKING(what readelf to use)
+if test "$gcc_cv_readelf" = ../binutils/readelf$build_exeext; then
+	# Single tree build which includes binutils.
+	AC_MSG_RESULT(newly built readelf)
+elif test x$gcc_cv_readelf = x; then
+	AC_MSG_RESULT(not found)
+else
+	AC_MSG_RESULT($gcc_cv_readelf)
+fi
+
 gcc_AC_INITFINI_ARRAY
 
 # mkdir takes a single argument on some systems. 
@@ -1892,231 +2117,6 @@ AC_PROG_LIBTOOL
 AC_SUBST(objdir)
 AC_SUBST(enable_fast_install)
 
-# Identify the assembler which will work hand-in-glove with the newly
-# built GCC, so that we can examine its features.  This is the assembler
-# which will be driven by the driver program.
-#
-# If build != host, and we aren't building gas in-tree, we identify a
-# build->target assembler and hope that it will have the same features
-# as the host->target assembler we'll be using.
-gcc_cv_gas_major_version=
-gcc_cv_gas_minor_version=
-gcc_cv_as_gas_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/gas
-
-m4_pattern_allow([AS_FOR_TARGET])dnl
-AS_VAR_SET_IF(gcc_cv_as,, [
-if test -x "$DEFAULT_ASSEMBLER"; then
-	gcc_cv_as="$DEFAULT_ASSEMBLER"
-elif test -f $gcc_cv_as_gas_srcdir/configure.in \
-     && test -f ../gas/Makefile \
-     && test x$build = x$host; then
-	gcc_cv_as=../gas/as-new$build_exeext
-elif test -x as$build_exeext; then
-	# Build using assembler in the current directory.
-	gcc_cv_as=./as$build_exeext
-elif ( set dummy $AS_FOR_TARGET; test -x $[2] ); then
-        gcc_cv_as="$AS_FOR_TARGET"
-else
-        AC_PATH_PROG(gcc_cv_as, $AS_FOR_TARGET)
-fi])
-
-ORIGINAL_AS_FOR_TARGET=$gcc_cv_as
-AC_SUBST(ORIGINAL_AS_FOR_TARGET)
-case "$ORIGINAL_AS_FOR_TARGET" in
-  ./as | ./as$build_exeext) ;;
-  *) AC_CONFIG_FILES(as:exec-tool.in, [chmod +x as]) ;;
-esac 
-
-AC_MSG_CHECKING(what assembler to use)
-if test "$gcc_cv_as" = ../gas/as-new$build_exeext; then
-  # Single tree build which includes gas.  We want to prefer it
-  # over whatever linker top-level may have detected, since
-  # we'll use what we're building after installation anyway.
-  AC_MSG_RESULT(newly built gas)
-  in_tree_gas=yes
-  _gcc_COMPUTE_GAS_VERSION
-  in_tree_gas_is_elf=no
-  if grep 'obj_format = elf' ../gas/Makefile > /dev/null \
-     || (grep 'obj_format = multi' ../gas/Makefile \
-         && grep 'extra_objects =.* obj-elf' ../gas/Makefile) > /dev/null
-  then
-    in_tree_gas_is_elf=yes
-  fi
-else
-  AC_MSG_RESULT($gcc_cv_as)
-  in_tree_gas=no
-fi
-
-# Identify the linker which will work hand-in-glove with the newly
-# built GCC, so that we can examine its features.  This is the linker
-# which will be driven by the driver program.
-#
-# If build != host, and we aren't building gas in-tree, we identify a
-# build->target linker and hope that it will have the same features
-# as the host->target linker we'll be using.
-gcc_cv_gld_major_version=
-gcc_cv_gld_minor_version=
-gcc_cv_ld_gld_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/ld
-gcc_cv_ld_bfd_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/bfd
-
-AS_VAR_SET_IF(gcc_cv_ld,, [
-if test -x "$DEFAULT_LINKER"; then
-	gcc_cv_ld="$DEFAULT_LINKER"
-elif test -f $gcc_cv_ld_gld_srcdir/configure.in \
-     && test -f ../ld/Makefile \
-     && test x$build = x$host; then
-	gcc_cv_ld=../ld/ld-new$build_exeext
-elif test -x collect-ld$build_exeext; then
-	# Build using linker in the current directory.
-	gcc_cv_ld=./collect-ld$build_exeext
-elif ( set dummy $LD_FOR_TARGET; test -x $[2] ); then
-        gcc_cv_ld="$LD_FOR_TARGET"
-else
-        AC_PATH_PROG(gcc_cv_ld, $LD_FOR_TARGET)
-fi])
-
-ORIGINAL_PLUGIN_LD_FOR_TARGET=$gcc_cv_ld
-PLUGIN_LD=`basename $gcc_cv_ld`
-AC_ARG_WITH(plugin-ld,
-[AS_HELP_STRING([[--with-plugin-ld=[ARG]]], [specify the plugin linker])],
-[if test x"$withval" != x; then
-   ORIGINAL_PLUGIN_LD_FOR_TARGET="$withval"
-   PLUGIN_LD="$withval"
- fi])
-AC_SUBST(ORIGINAL_PLUGIN_LD_FOR_TARGET)
-AC_DEFINE_UNQUOTED(PLUGIN_LD, "$PLUGIN_LD", [Specify plugin linker])
-
-# Check to see if we are using gold instead of ld
-AC_MSG_CHECKING(whether we are using gold)
-ld_is_gold=no
-if test x$gcc_cv_ld != x; then
-  if $gcc_cv_ld --version 2>/dev/null | sed 1q \
-     | grep "GNU gold" > /dev/null; then
-    ld_is_gold=yes
-  fi
-fi
-AC_MSG_RESULT($ld_is_gold)
-
-ORIGINAL_LD_FOR_TARGET=$gcc_cv_ld
-AC_SUBST(ORIGINAL_LD_FOR_TARGET)
-case "$ORIGINAL_LD_FOR_TARGET" in
-  ./collect-ld | ./collect-ld$build_exeext) ;;
-  *) AC_CONFIG_FILES(collect-ld:exec-tool.in, [chmod +x collect-ld]) ;;
-esac 
-
-AC_MSG_CHECKING(what linker to use)
-if test "$gcc_cv_ld" = ../ld/ld-new$build_exeext \
-   || test "$gcc_cv_ld" = ../gold/ld-new$build_exeext; then
-	# Single tree build which includes ld.  We want to prefer it
-	# over whatever linker top-level may have detected, since
-	# we'll use what we're building after installation anyway.
-	AC_MSG_RESULT(newly built ld)
-	in_tree_ld=yes
-	in_tree_ld_is_elf=no
-	if (grep 'EMUL = .*elf' ../ld/Makefile \
-	    || grep 'EMUL = .*linux' ../ld/Makefile \
-	    || grep 'EMUL = .*lynx' ../ld/Makefile) > /dev/null; then
-	  in_tree_ld_is_elf=yes
-	elif test "$ld_is_gold" = yes; then
-	  in_tree_ld_is_elf=yes
-	fi
-	for f in $gcc_cv_ld_bfd_srcdir/configure $gcc_cv_ld_gld_srcdir/configure $gcc_cv_ld_gld_srcdir/configure.in $gcc_cv_ld_gld_srcdir/Makefile.in
-	do
-changequote(,)dnl
-		gcc_cv_gld_version=`sed -n -e 's/^[ 	]*\(VERSION=[0-9]*\.[0-9]*.*\)/\1/p' < $f`
-		if test x$gcc_cv_gld_version != x; then
-			break
-		fi
-	done
-	gcc_cv_gld_major_version=`expr "$gcc_cv_gld_version" : "VERSION=\([0-9]*\)"`
-	gcc_cv_gld_minor_version=`expr "$gcc_cv_gld_version" : "VERSION=[0-9]*\.\([0-9]*\)"`
-changequote([,])dnl
-else
-	AC_MSG_RESULT($gcc_cv_ld)
-	in_tree_ld=no
-fi
-
-# Figure out what nm we will be using.
-gcc_cv_binutils_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/binutils
-AS_VAR_SET_IF(gcc_cv_nm,, [
-if test -f $gcc_cv_binutils_srcdir/configure.in \
-     && test -f ../binutils/Makefile \
-     && test x$build = x$host; then
-	gcc_cv_nm=../binutils/nm-new$build_exeext
-elif test -x nm$build_exeext; then
-	gcc_cv_nm=./nm$build_exeext
-elif ( set dummy $NM_FOR_TARGET; test -x $[2] ); then
-        gcc_cv_nm="$NM_FOR_TARGET"
-else
-        AC_PATH_PROG(gcc_cv_nm, $NM_FOR_TARGET)
-fi])
-
-AC_MSG_CHECKING(what nm to use)
-if test "$gcc_cv_nm" = ../binutils/nm-new$build_exeext; then
-	# Single tree build which includes binutils.
-	AC_MSG_RESULT(newly built nm)
-	in_tree_nm=yes
-else
-	AC_MSG_RESULT($gcc_cv_nm)
-	in_tree_nm=no
-fi
-
-ORIGINAL_NM_FOR_TARGET=$gcc_cv_nm
-AC_SUBST(ORIGINAL_NM_FOR_TARGET)
-case "$ORIGINAL_NM_FOR_TARGET" in
-  ./nm | ./nm$build_exeext) ;;
-  *) AC_CONFIG_FILES(nm:exec-tool.in, [chmod +x nm]) ;;
-esac
-
-
-# Figure out what objdump we will be using.
-AS_VAR_SET_IF(gcc_cv_objdump,, [
-if test -f $gcc_cv_binutils_srcdir/configure.in \
-     && test -f ../binutils/Makefile \
-     && test x$build = x$host; then
-	# Single tree build which includes binutils.
-	gcc_cv_objdump=../binutils/objdump$build_exeext
-elif test -x objdump$build_exeext; then
-	gcc_cv_objdump=./objdump$build_exeext
-elif ( set dummy $OBJDUMP_FOR_TARGET; test -x $[2] ); then
-        gcc_cv_objdump="$OBJDUMP_FOR_TARGET"
-else
-        AC_PATH_PROG(gcc_cv_objdump, $OBJDUMP_FOR_TARGET)
-fi])
-
-AC_MSG_CHECKING(what objdump to use)
-if test "$gcc_cv_objdump" = ../binutils/objdump$build_exeext; then
-	# Single tree build which includes binutils.
-	AC_MSG_RESULT(newly built objdump)
-elif test x$gcc_cv_objdump = x; then
-	AC_MSG_RESULT(not found)
-else
-	AC_MSG_RESULT($gcc_cv_objdump)
-fi
-
-# Figure out what readelf we will be using.
-AS_VAR_SET_IF(gcc_cv_readelf,, [
-if test -f $gcc_cv_binutils_srcdir/configure.in \
-     && test -f ../binutils/Makefile \
-     && test x$build = x$host; then
-	# Single tree build which includes binutils.
-	gcc_cv_readelf=../binutils/readelf$build_exeext
-elif test -x readelf$build_exeext; then
-	gcc_cv_readelf=./readelf$build_exeext
-else
-        AC_PATH_PROG(gcc_cv_readelf, readelf)
-fi])
-
-AC_MSG_CHECKING(what readelf to use)
-if test "$gcc_cv_readelf" = ../binutils/readelf$build_exeext; then
-	# Single tree build which includes binutils.
-	AC_MSG_RESULT(newly built readelf)
-elif test x$gcc_cv_readelf = x; then
-	AC_MSG_RESULT(not found)
-else
-	AC_MSG_RESULT($gcc_cv_readelf)
-fi
-
 # Figure out what assembler alignment features are present.
 gcc_GAS_CHECK_FEATURE([.balign and .p2align], gcc_cv_as_balign_and_p2align,
  [2,6,0],,

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22  7:46   ` Jakub Jelinek
  2011-08-22 14:23     ` H.J. Lu
@ 2011-08-22 17:37     ` H.J. Lu
  2011-08-22 18:33       ` H.J. Lu
  2011-08-22 19:12       ` Joseph S. Myers
  1 sibling, 2 replies; 46+ messages in thread
From: H.J. Lu @ 2011-08-22 17:37 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: David Edelsohn, GCC Patches

On Sun, Aug 21, 2011 at 10:37 PM, Jakub Jelinek <jakub@redhat.com> wrote:
nd/or add another test to it that tests
> that you can actually use
> .section .init_array
> and it will use correct section flags for the section.
>

We need this information in config.gcc. But config.gcc is used
before assembler and readelf are detected. I am running out of
ideas.  Any suggestions?

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22  7:39 David Edelsohn
  2011-08-22  7:44 ` H.J. Lu
@ 2011-08-22 16:26 ` H.J. Lu
  1 sibling, 0 replies; 46+ messages in thread
From: H.J. Lu @ 2011-08-22 16:26 UTC (permalink / raw)
  To: David Edelsohn; +Cc: Jakub Jelinek, GCC Patches

On Sun, Aug 21, 2011 at 4:19 PM, David Edelsohn <dje.gcc@gmail.com> wrote:
> This patch broke bootstrap on AIX.  It emits a ".section" op in
> assembly but ".section" is an ELF syntax op not AIX XCOFF.
>
> FE..initialize_critical:
>        .section        .init_array
>
> varasm.c should not be generating ELF ops for non-ELF targets.
>
> config.log shows:
>
> gcc_cv_initfini_array=yes
> tm_file_list includes initfini-array.h
> tm_include_list includes initfini-array.h
>
> Why is the patch affecting non-ELF targets?  Please fix or revert immediately.
>

David, I checked in the fix for AIX.  Please verify it.

Thanks.


-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22 15:27       ` H.J. Lu
@ 2011-08-22 15:46         ` Paolo Bonzini
  0 siblings, 0 replies; 46+ messages in thread
From: Paolo Bonzini @ 2011-08-22 15:46 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jakub Jelinek, David Edelsohn, GCC Patches

On 08/22/2011 04:45 PM, H.J. Lu wrote:
> Can I check in this patch to address AIX issue first?
> I will submit a patch to test ".section .init_array" later?
>
> Thanks.

Yes.

Paolo

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22 14:23     ` H.J. Lu
@ 2011-08-22 15:27       ` H.J. Lu
  2011-08-22 15:46         ` Paolo Bonzini
  0 siblings, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-08-22 15:27 UTC (permalink / raw)
  To: Jakub Jelinek, Paolo Bonzini; +Cc: David Edelsohn, GCC Patches

On Mon, Aug 22, 2011 at 7:06 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Sun, Aug 21, 2011 at 10:37 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>> On Sun, Aug 21, 2011 at 05:09:59PM -0700, H.J. Lu wrote:
>>> I didn't know .init_array section was enabled for AIX.  Does this patch
>>> work for you?
>>
>> Some ELF targets (e.g. arm*-linux*) don't use elfos.h.  IMHO you should
>> instead add
>> #ifndef __ELF__
>> #error NonELF
>> #endif
>> to gcc_AC_INITFINI_ARRAY test.  And/or add another test to it that tests
>> that you can actually use
>> .section .init_array
>> and it will use correct section flags for the section.
>>
>
> I will update the test.

Can I check in this patch to address AIX issue first?
I will submit a patch to test ".section .init_array" later?

Thanks.

-- 
H.J.
---
2011-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	* acinclude.m4 (gcc_AC_INITFINI_ARRAY): Error if __ELF__ isn't
	defined.

diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4
index 74c86db..a8ecd2d 100644
--- a/gcc/acinclude.m4
+++ b/gcc/acinclude.m4
@@ -377,6 +377,9 @@ AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array su
pport,
 		 gcc_cv_initfini_array, [dnl
   if test "x${build}" = "x${target}" && test "x${build}" = "x${host}"; then
     AC_RUN_IFELSE([AC_LANG_SOURCE([
+#ifndef __ELF__
+#error Not an ELF OS
+#endif
 #ifdef __ia64__
 /* We turn on .preinit_array/.init_array/.fini_array support for ia64
    if it can be used.  */

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22  7:46   ` Jakub Jelinek
@ 2011-08-22 14:23     ` H.J. Lu
  2011-08-22 15:27       ` H.J. Lu
  2011-08-22 17:37     ` H.J. Lu
  1 sibling, 1 reply; 46+ messages in thread
From: H.J. Lu @ 2011-08-22 14:23 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: David Edelsohn, GCC Patches

On Sun, Aug 21, 2011 at 10:37 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Sun, Aug 21, 2011 at 05:09:59PM -0700, H.J. Lu wrote:
>> I didn't know .init_array section was enabled for AIX.  Does this patch
>> work for you?
>
> Some ELF targets (e.g. arm*-linux*) don't use elfos.h.  IMHO you should
> instead add
> #ifndef __ELF__
> #error NonELF
> #endif
> to gcc_AC_INITFINI_ARRAY test.  And/or add another test to it that tests
> that you can actually use
> .section .init_array
> and it will use correct section flags for the section.
>

I will update the test.

-- 
H.J.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22  7:44 ` H.J. Lu
@ 2011-08-22  7:46   ` Jakub Jelinek
  2011-08-22 14:23     ` H.J. Lu
  2011-08-22 17:37     ` H.J. Lu
  2011-08-22  7:46   ` David Edelsohn
  1 sibling, 2 replies; 46+ messages in thread
From: Jakub Jelinek @ 2011-08-22  7:46 UTC (permalink / raw)
  To: H.J. Lu; +Cc: David Edelsohn, GCC Patches

On Sun, Aug 21, 2011 at 05:09:59PM -0700, H.J. Lu wrote:
> I didn't know .init_array section was enabled for AIX.  Does this patch
> work for you?

Some ELF targets (e.g. arm*-linux*) don't use elfos.h.  IMHO you should
instead add
#ifndef __ELF__
#error NonELF
#endif
to gcc_AC_INITFINI_ARRAY test.  And/or add another test to it that tests
that you can actually use
.section .init_array
and it will use correct section flags for the section.

	Jakub

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22  7:44 ` H.J. Lu
  2011-08-22  7:46   ` Jakub Jelinek
@ 2011-08-22  7:46   ` David Edelsohn
  1 sibling, 0 replies; 46+ messages in thread
From: David Edelsohn @ 2011-08-22  7:46 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jakub Jelinek, GCC Patches

On Sun, Aug 21, 2011 at 8:09 PM, H.J. Lu <hjl.tools@gmail.com> wrote:

> I didn't know .init_array section was enabled for AIX.  Does this patch
> work for you?
>
> Sorry about the breakage.

I am not exactly sure why .init_array sections are enabled for AIX.
The configure test succeeds.  Is the problem with the configure test
or with initfini-array.h?

Thanks, David

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
  2011-08-22  7:39 David Edelsohn
@ 2011-08-22  7:44 ` H.J. Lu
  2011-08-22  7:46   ` Jakub Jelinek
  2011-08-22  7:46   ` David Edelsohn
  2011-08-22 16:26 ` H.J. Lu
  1 sibling, 2 replies; 46+ messages in thread
From: H.J. Lu @ 2011-08-22  7:44 UTC (permalink / raw)
  To: David Edelsohn; +Cc: Jakub Jelinek, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 706 bytes --]

On Sun, Aug 21, 2011 at 4:19 PM, David Edelsohn <dje.gcc@gmail.com> wrote:
> This patch broke bootstrap on AIX.  It emits a ".section" op in
> assembly but ".section" is an ELF syntax op not AIX XCOFF.
>
> FE..initialize_critical:
>        .section        .init_array
>
> varasm.c should not be generating ELF ops for non-ELF targets.
>
> config.log shows:
>
> gcc_cv_initfini_array=yes
> tm_file_list includes initfini-array.h
> tm_include_list includes initfini-array.h
>
> Why is the patch affecting non-ELF targets?  Please fix or revert immediately.
>

I didn't know .init_array section was enabled for AIX.  Does this patch
work for you?

Sorry about the breakage.

-- 
H.J.

[-- Attachment #2: gcc-elfos-1.patch --]
[-- Type: text/plain, Size: 516 bytes --]

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 7f29213..843b382 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3058,9 +3058,13 @@ if test x$with_schedule = x; then
 	esac
 fi
 
-# Support --enable-initfini-array.
+# Support --enable-initfini-array for ELF OSes.
 if test x$enable_initfini_array = xyes; then
-  tm_file="${tm_file} initfini-array.h"
+	case "${tm_file}" in
+	*elfos.h*)
+		tm_file="${tm_file} initfini-array.h"
+		;;
+  	esac
 fi
 
 # Validate and mark as valid any --with options supported

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections
@ 2011-08-22  7:39 David Edelsohn
  2011-08-22  7:44 ` H.J. Lu
  2011-08-22 16:26 ` H.J. Lu
  0 siblings, 2 replies; 46+ messages in thread
From: David Edelsohn @ 2011-08-22  7:39 UTC (permalink / raw)
  To: H.J. Lu, Jakub Jelinek; +Cc: GCC Patches

This patch broke bootstrap on AIX.  It emits a ".section" op in
assembly but ".section" is an ELF syntax op not AIX XCOFF.

FE..initialize_critical:
        .section        .init_array

varasm.c should not be generating ELF ops for non-ELF targets.

config.log shows:

gcc_cv_initfini_array=yes
tm_file_list includes initfini-array.h
tm_include_list includes initfini-array.h

Why is the patch affecting non-ELF targets?  Please fix or revert immediately.

Thanks, David

^ permalink raw reply	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2012-03-19 20:42 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-21 18:40 PING: PATCH: PR target/46770: Use .init_array/.fini_array sections H.J. Lu
2011-03-31 15:15 ` H.J. Lu
2011-04-14 19:11   ` H.J. Lu
2011-04-26 13:08   ` H.J. Lu
2011-05-18 17:30     ` H.J. Lu
2011-06-01 23:30       ` Carrot Wei
2011-06-03  4:31       ` H.J. Lu
2011-06-03 12:31         ` Richard Guenther
2011-06-03 12:52           ` H.J. Lu
2011-06-19 20:02             ` H.J. Lu
2011-06-19 21:31               ` Uros Bizjak
2011-07-22 12:31                 ` H.J. Lu
2011-07-22 12:36                   ` Rainer Orth
2011-07-22 12:36                     ` H.J. Lu
2011-07-22 13:20                       ` Rainer Orth
2011-07-22 12:37                   ` Jakub Jelinek
2011-07-22 13:21                     ` Joseph S. Myers
2011-07-22 13:29                     ` H.J. Lu
2011-07-22 14:17                       ` H.J. Lu
2011-07-22 14:55                         ` H.J. Lu
2011-08-06 14:51                           ` H.J. Lu
2011-08-09 14:32                             ` H.J. Lu
2011-08-14 19:20                               ` H.J. Lu
2011-08-19 10:05                           ` Jakub Jelinek
2011-08-19 14:58                             ` H.J. Lu
2011-08-19 15:54                               ` Jakub Jelinek
2011-08-20 21:16                                 ` H.J. Lu
2012-03-19 20:35                                   ` DJ Delorie
2012-03-19 20:40                                     ` Andrew Pinski
2012-03-19 20:42                                       ` DJ Delorie
2011-07-01 14:12               ` H.J. Lu
2011-06-03 17:13           ` Michael Eager
2011-08-22  7:39 David Edelsohn
2011-08-22  7:44 ` H.J. Lu
2011-08-22  7:46   ` Jakub Jelinek
2011-08-22 14:23     ` H.J. Lu
2011-08-22 15:27       ` H.J. Lu
2011-08-22 15:46         ` Paolo Bonzini
2011-08-22 17:37     ` H.J. Lu
2011-08-22 18:33       ` H.J. Lu
2011-08-22 19:12       ` Joseph S. Myers
2011-08-22 19:19         ` H.J. Lu
2011-08-22 19:38           ` Joseph S. Myers
2011-08-22 20:50             ` H.J. Lu
2011-08-22  7:46   ` David Edelsohn
2011-08-22 16:26 ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).