summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>2011-08-20 20:02:17 +0000
committerhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>2011-08-20 20:02:17 +0000
commitef1da8054ee3090992170a0b0e2b69983347a1af (patch)
tree3906273c1671420742bbbcd2e6b652c9b3f19c95
parent61bc1860cb0921581b1e23bf22f11c02e765512e (diff)
downloadgcc-ef1da8054ee3090992170a0b0e2b69983347a1af.tar.gz
Use .init_arrary/.fini_array sections if possible.
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@177933 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog19
-rw-r--r--gcc/config.gcc5
-rw-r--r--gcc/config/initfini-array.h37
-rw-r--r--gcc/crtstuff.c11
-rw-r--r--gcc/output.h2
-rw-r--r--gcc/varasm.c58
6 files changed, 131 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4ca6298dc1f..be56639748b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,22 @@
+2011-08-20 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR other/46770
+ * config.gcc (tm_file): Add initfini-array.h if
+ .init_arrary/.fini_array are supported.
+
+ * crtstuff.c: Don't generate .ctors nor .dtors sections if
+ USE_INITFINI_ARRAY is defined.
+
+ * output.h (default_elf_init_array_asm_out_constructor): New.
+ (default_elf_fini_array_asm_out_destructor): Likewise.
+ * varasm.c (elf_init_array_section): Likewise.
+ (elf_fini_array_section): Likewise.
+ (get_elf_initfini_array_priority_section): Likewise.
+ (default_elf_init_array_asm_out_constructor): Likewise.
+ (default_elf_fini_array_asm_out_destructor): Likewise.
+
+ * config/initfini-array.h: New.
+
2011-08-20 Richard Sandiford <rdsandiford@googlemail.com>
* config/mips/mips.c (mips_class_max_nregs): Check that the mode is
diff --git a/gcc/config.gcc b/gcc/config.gcc
index b92ce3d4fb6..7f29213b74d 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 00000000000..8aaadf686af
--- /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 b65f490da66..010d472765d 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 c668d352112..6b7c4b8781c 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 ca568136cb3..218baf3bcf2 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"