diff mbox

PATCH: PR target/46770: Use .init_array/.fini_array sections

Message ID AANLkTikw43BPQPLS6SEZ98-Ah0PV02V3nCoZhAHJgNBv@mail.gmail.com
State New
Headers show

Commit Message

H.J. Lu Dec. 7, 2010, 4:57 p.m. UTC
On Tue, Dec 7, 2010 at 8:31 AM, Joseph S. Myers <joseph@codesourcery.com> wrote:
> On Tue, 7 Dec 2010, H.J. Lu wrote:
>
>> @@ -2698,6 +2698,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
>
> Please update the comment at the top of config.gcc listing the variables
> it sets, and put a default (empty or "no") setting of this variable along
> with the other defaults as well.

Done.

>> +#include "tree.h"
>
> What is tree.h needed for here?

DEFAULT_INIT_PRIORITY is defined in tree.h.

>> +     $(TREE_H) $(GCC_H)
>
> I think you mean $(GGC_H) not $(GCC_H) (which is gcc.h, the header for the
> driver).
>

Fixed.

 Here is the updated patch. OK for trunk?

Thanks.

Comments

H.J. Lu Dec. 9, 2010, 6:44 p.m. UTC | #1
On Tue, Dec 7, 2010 at 8:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Dec 7, 2010 at 8:31 AM, Joseph S. Myers <joseph@codesourcery.com> wrote:
>> On Tue, 7 Dec 2010, H.J. Lu wrote:
>>
>>> @@ -2698,6 +2698,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
>>
>> Please update the comment at the top of config.gcc listing the variables
>> it sets, and put a default (empty or "no") setting of this variable along
>> with the other defaults as well.
>
> Done.
>
>>> +#include "tree.h"
>>
>> What is tree.h needed for here?
>
> DEFAULT_INIT_PRIORITY is defined in tree.h.
>
>>> +     $(TREE_H) $(GCC_H)
>>
>> I think you mean $(GGC_H) not $(GCC_H) (which is gcc.h, the header for the
>> driver).
>>
>
> Fixed.
>
>  Here is the updated patch. OK for trunk?
>
> Thanks.
>
> --
> H.J.
> ---
> 2010-12-07  H.J. Lu  <hongjiu.lu@intel.com>
>
>        PR target/46770
>        * config.gcc (use_initfini_array): New variable.
>        Use initfini-array.o if supported.
>
>        * config/initfini-array.c: New.
>        * config/initfini-array.h: Likewise.
>        * config/t-initfini-array: Likewise.
>

This is a platform feature. I helped put this into gABI and implemented
it in as/ld/glibc 10 years ago.  It is the time to enable it on Linux/x86 now.
Any objections to check it in if there are no further comments in 48hours?

Thanks.
Richard Biener Dec. 10, 2010, 9:40 a.m. UTC | #2
On Thu, Dec 9, 2010 at 7:44 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Dec 7, 2010 at 8:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Tue, Dec 7, 2010 at 8:31 AM, Joseph S. Myers <joseph@codesourcery.com> wrote:
>>> On Tue, 7 Dec 2010, H.J. Lu wrote:
>>>
>>>> @@ -2698,6 +2698,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
>>>
>>> Please update the comment at the top of config.gcc listing the variables
>>> it sets, and put a default (empty or "no") setting of this variable along
>>> with the other defaults as well.
>>
>> Done.
>>
>>>> +#include "tree.h"
>>>
>>> What is tree.h needed for here?
>>
>> DEFAULT_INIT_PRIORITY is defined in tree.h.
>>
>>>> +     $(TREE_H) $(GCC_H)
>>>
>>> I think you mean $(GGC_H) not $(GCC_H) (which is gcc.h, the header for the
>>> driver).
>>>
>>
>> Fixed.
>>
>>  Here is the updated patch. OK for trunk?
>>
>> Thanks.
>>
>> --
>> H.J.
>> ---
>> 2010-12-07  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>        PR target/46770
>>        * config.gcc (use_initfini_array): New variable.
>>        Use initfini-array.o if supported.
>>
>>        * config/initfini-array.c: New.
>>        * config/initfini-array.h: Likewise.
>>        * config/t-initfini-array: Likewise.
>>
>
> This is a platform feature. I helped put this into gABI and implemented
> it in as/ld/glibc 10 years ago.  It is the time to enable it on Linux/x86 now.
> Any objections to check it in if there are no further comments in 48hours?

I don't see any approval.

Do you really think it is an appropriate change at this stage?

Thanks,
Richard.

> Thanks.
>
>
> --
> H.J.
>
H.J. Lu Dec. 10, 2010, 12:26 p.m. UTC | #3
On Fri, Dec 10, 2010 at 1:40 AM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Thu, Dec 9, 2010 at 7:44 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Tue, Dec 7, 2010 at 8:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Tue, Dec 7, 2010 at 8:31 AM, Joseph S. Myers <joseph@codesourcery.com> wrote:
>>>> On Tue, 7 Dec 2010, H.J. Lu wrote:
>>>>
>>>>> @@ -2698,6 +2698,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
>>>>
>>>> Please update the comment at the top of config.gcc listing the variables
>>>> it sets, and put a default (empty or "no") setting of this variable along
>>>> with the other defaults as well.
>>>
>>> Done.
>>>
>>>>> +#include "tree.h"
>>>>
>>>> What is tree.h needed for here?
>>>
>>> DEFAULT_INIT_PRIORITY is defined in tree.h.
>>>
>>>>> +     $(TREE_H) $(GCC_H)
>>>>
>>>> I think you mean $(GGC_H) not $(GCC_H) (which is gcc.h, the header for the
>>>> driver).
>>>>
>>>
>>> Fixed.
>>>
>>>  Here is the updated patch. OK for trunk?
>>>
>>> Thanks.
>>>
>>> --
>>> H.J.
>>> ---
>>> 2010-12-07  H.J. Lu  <hongjiu.lu@intel.com>
>>>
>>>        PR target/46770
>>>        * config.gcc (use_initfini_array): New variable.
>>>        Use initfini-array.o if supported.
>>>
>>>        * config/initfini-array.c: New.
>>>        * config/initfini-array.h: Likewise.
>>>        * config/t-initfini-array: Likewise.
>>>
>>
>> This is a platform feature. I helped put this into gABI and implemented
>> it in as/ld/glibc 10 years ago.  It is the time to enable it on Linux/x86 now.
>> Any objections to check it in if there are no further comments in 48hours?
>
> I don't see any approval.
>
> Do you really think it is an appropriate change at this stage?
>

Yes, 10 years is long enough,
diff mbox

Patch

diff --git a/gcc/config.gcc b/gcc/config.gcc
index dfbf2c5..917c1ce 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:
@@ -219,6 +222,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=
@@ -2698,6 +2702,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"
@@ -3050,6 +3055,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..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..115996e
--- /dev/null
+++ b/gcc/config/initfini-array.h
@@ -0,0 +1,33 @@ 
+/* 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/>.  */
+
+#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..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) $<