From patchwork Sat Feb 18 01:20:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 142027 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 D626DB6F98 for ; Sat, 18 Feb 2012 12:20:22 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1330132824; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version: Content-Type:Content-Disposition:User-Agent:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=tNc2FZJ4lPIEHCGJSoCE4LYjQOk=; b=fZTbFwq9Hl5jItZDReX8ZzHn8gKbvEa/Sy9ZYJH5FfUwJwp5ApmBJBC0fzOlxG HCcm9T70P1SpSSUq2Ct3jg8g9+S+Ix1ot/xMGdef41r92ktjZ/kzkLWa6PntGwSv gzH9g71pnbBI6mafVacAY3Ph0hIDtyTDX8HJmn+E25tbg= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-ExtLoop1:Received:Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=NHruJbvpCDw6Acv2HdaDwhG5logcTR6QUGKOSFPHOcsbv1utn56My4lmj4ul1T LowuXvguf3E4xg4XiO0VEkDx64N2lnoF1HIbj6XdYllMegHnXdDrh5eVn13B7jak JI9D68+Bm8+kQGTQh+b1i4iHcvQ2jv2wZb7rCCnxEJtzE=; Received: (qmail 9564 invoked by alias); 18 Feb 2012 01:20:19 -0000 Received: (qmail 9553 invoked by uid 22791); 18 Feb 2012 01:20:17 -0000 X-SWARE-Spam-Status: No, hits=-4.1 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, RCVD_IN_DNSWL_HI, TW_SV, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mga14.intel.com (HELO mga14.intel.com) (143.182.124.37) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 18 Feb 2012 01:20:03 +0000 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga102.ch.intel.com with ESMTP; 17 Feb 2012 17:20:02 -0800 X-ExtLoop1: 1 Received: from gnu-6.sc.intel.com ([10.3.194.135]) by azsmga001.ch.intel.com with ESMTP; 17 Feb 2012 17:20:02 -0800 Received: by gnu-6.sc.intel.com (Postfix, from userid 500) id 33020C185F; Fri, 17 Feb 2012 17:20:02 -0800 (PST) Date: Fri, 17 Feb 2012 17:20:02 -0800 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: [google/gcc-4_6_2-mobile] PATCH: PR other/46770: Replace .ctors/.dtors with .init_array/.fini_array on targets supporting them Message-ID: <20120218012001.GA19585@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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 Hi, This patch backports the fix from trunk: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46770 for google/gcc-4_6_2-mobile branch. This is needed to support C++ global constructors/destructiors on Android/x86. OK for google/gcc-4_6_2-mobile branch? Thanks. H.J. --- 2011-08-20 H.J. Lu 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 Conflicts: gcc/ChangeLog --- gcc/ChangeLog.hjl | 21 +++++++++++++++ gcc/config.gcc | 5 +++ gcc/config/initfini-array.h | 37 +++++++++++++++++++++++++++ gcc/crtstuff.c | 11 +++++++- gcc/output.h | 2 + gcc/varasm.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 1 deletions(-) create mode 100644 gcc/ChangeLog.hjl create mode 100644 gcc/config/initfini-array.h diff --git a/gcc/ChangeLog.hjl b/gcc/ChangeLog.hjl new file mode 100644 index 0000000..3527b27 --- /dev/null +++ b/gcc/ChangeLog.hjl @@ -0,0 +1,21 @@ +2011-12-07 H.J. Lu + + Backport from mainline + 2011-08-20 H.J. Lu + + 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 d9ac0fa..b386424 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -3176,6 +3176,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 + . */ + +#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 7031b08..661b623 100644 --- a/gcc/output.h +++ b/gcc/output.h @@ -655,6 +655,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 40a8567..d15c278 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -7397,4 +7397,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"