From patchwork Sun Jun 19 18:39:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 100980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 025E5B6FCD for ; Mon, 20 Jun 2011 04:39:25 +1000 (EST) Received: (qmail 1126 invoked by alias); 19 Jun 2011 18:39:23 -0000 Received: (qmail 1113 invoked by uid 22791); 19 Jun 2011 18:39:19 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL, BAYES_05, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RFC_ABUSE_POST, TW_GM, TW_PM X-Spam-Check-By: sourceware.org Received: from mail-qy0-f182.google.com (HELO mail-qy0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 19 Jun 2011 18:39:02 +0000 Received: by qyk38 with SMTP id 38so544877qyk.20 for ; Sun, 19 Jun 2011 11:39:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.131.32 with SMTP id v32mr3366091qcs.35.1308508740456; Sun, 19 Jun 2011 11:39:00 -0700 (PDT) Received: by 10.229.47.78 with HTTP; Sun, 19 Jun 2011 11:39:00 -0700 (PDT) In-Reply-To: References: Date: Sun, 19 Jun 2011 11:39:00 -0700 Message-ID: Subject: PING: PATCH: PR target/46770: Use .init_array/.fini_array sections From: "H.J. Lu" To: Richard Guenther , Uros Bizjak Cc: GCC Patches X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On Fri, Jun 3, 2011 at 5:51 AM, H.J. Lu wrote: > On Fri, Jun 3, 2011 at 5:31 AM, Richard Guenther > wrote: >> On Fri, Jun 3, 2011 at 6:31 AM, H.J. Lu wrote: >>> On Wed, May 18, 2011 at 8:57 AM, H.J. Lu wrote: >>>> On Tue, Apr 26, 2011 at 6:05 AM, H.J. Lu wrote: >>>>> On Thu, Mar 31, 2011 at 7:57 AM, H.J. Lu wrote: >>>>>> On Mon, Mar 21, 2011 at 11:40 AM, H.J. Lu wrote: >>>>>>> On Mon, Mar 14, 2011 at 12:28 PM, H.J. Lu wrote: >>>>>>>> On Thu, Jan 27, 2011 at 2:40 AM, Richard Guenther >>>>>>>> wrote: >>>>>>>>> On Thu, Jan 27, 2011 at 12:12 AM, H.J. Lu 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   >>>>>>>> >>>>>>>>        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. 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 +. */ + +#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 + . */ + +/* 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 } /* 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 +# . + +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;