From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9044 invoked by alias); 6 May 2015 23:00:06 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 8945 invoked by uid 89); 6 May 2015 23:00:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 06 May 2015 23:00:05 +0000 Received: from gcc1-power7.osuosl.org (localhost [127.0.0.1]) by gcc1-power7.osuosl.org (8.14.6/8.14.6) with ESMTP id t46N01BO054844; Wed, 6 May 2015 16:00:01 -0700 Received: (from segher@localhost) by gcc1-power7.osuosl.org (8.14.6/8.14.6/Submit) id t46MxxgL054531; Wed, 6 May 2015 15:59:59 -0700 From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH] Make mergeable read-only sections per-function, if requested. Date: Wed, 06 May 2015 23:00:00 -0000 Message-Id: <8f67f9aad3d5b98cb428dea0316a86615b89adb9.1430937961.git.segher@kernel.crashing.org> X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg00509.txt.bz2 Currently GCC does not put mergeable read-only data in a per-function section, so the -gc-sections linker option does not do much for such data. Fix that. Bootstrapped and tested on powerpc64-linux; no regressions. Is this okay for trunk? Segher 2015-05-06 Segher Boessenkool PR middle-end/192 PR middle-end/54303 * varasm.c (function_mergeable_rodata_prefix): New function. (mergeable_string_section): Use it. (mergeable_constant_section): Use it. --- gcc/varasm.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gcc/varasm.c b/gcc/varasm.c index 62d5163..d8f077d 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -783,6 +783,16 @@ default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED) return readonly_data_section; } +const char * +function_mergeable_rodata_prefix (void) +{ + section *s = targetm.asm_out.function_rodata_section (current_function_decl); + if (SECTION_STYLE (s) == SECTION_NAMED) + return s->named.name; + else + return targetm.asm_out.mergeable_rodata_prefix; +} + /* Return the section to use for string merging. */ static section * @@ -804,7 +814,7 @@ mergeable_string_section (tree decl ATTRIBUTE_UNUSED, const char *str; HOST_WIDE_INT i; int j, unit; - const char *prefix = targetm.asm_out.mergeable_rodata_prefix; + const char *prefix = function_mergeable_rodata_prefix (); char *name = (char *) alloca (strlen (prefix) + 30); mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl))); @@ -857,7 +867,7 @@ mergeable_constant_section (machine_mode mode ATTRIBUTE_UNUSED, && align <= 256 && (align & (align - 1)) == 0) { - const char *prefix = targetm.asm_out.mergeable_rodata_prefix; + const char *prefix = function_mergeable_rodata_prefix (); char *name = (char *) alloca (strlen (prefix) + 30); sprintf (name, "%s.cst%d", prefix, (int) (align / 8)); -- 1.8.1.4