From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 94173 invoked by alias); 7 May 2015 15:51:59 -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 94154 invoked by uid 89); 7 May 2015 15:51:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: gate.crashing.org Received: from gate.crashing.org (HELO gate.crashing.org) (63.228.1.57) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 07 May 2015 15:51:57 +0000 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id t47FprJR011849; Thu, 7 May 2015 10:51:54 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id t47Fprb6011848; Thu, 7 May 2015 10:51:53 -0500 Date: Thu, 07 May 2015 15:51:00 -0000 From: Segher Boessenkool To: Jeff Law Cc: Marek Polacek , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Make mergeable read-only sections per-function, if requested. Message-ID: <20150507155153.GB23850@gate.crashing.org> References: <8f67f9aad3d5b98cb428dea0316a86615b89adb9.1430937961.git.segher@kernel.crashing.org> <20150507081507.GA3384@redhat.com> <20150507123058.GA23850@gate.crashing.org> <554B6935.9040300@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <554B6935.9040300@redhat.com> User-Agent: Mutt/1.4.2.3i X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg00563.txt.bz2 On Thu, May 07, 2015 at 07:31:33AM -0600, Jeff Law wrote: > If you could cobble together a little test (ppc specific is fine with > me) it'd be appreciated. > > With that, approved for the trunk. I did one for *-*-linux*. Tested on powerpc64-linux and x86_64-linux. Committed. Segher 2015-05-07 Segher Boessenkool gcc/ 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/testsuite/ PR middle-end/192 PR middle-end/54303 * gcc.dg/fdata-sections-2.c: New file. --- gcc/testsuite/gcc.dg/fdata-sections-2.c | 18 ++++++++++++++++++ gcc/varasm.c | 16 ++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/fdata-sections-2.c diff --git a/gcc/testsuite/gcc.dg/fdata-sections-2.c b/gcc/testsuite/gcc.dg/fdata-sections-2.c new file mode 100644 index 0000000..dda90ba7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fdata-sections-2.c @@ -0,0 +1,18 @@ +/* PR middle-end/192 */ +/* PR middle-end/54303 */ + +/* This checks that string constants are put in per-function rodata + sections, so that they can be garbage collected. */ + +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O -ffunction-sections -fdata-sections" } */ + +const char *f1(void) { return "falderalde"; } +const char *f2(void) { return "a"; } +const char *f3(void) { return "falderalde"; } +const char *f4(void) { return "eralde"; } + +/* { dg-final { scan-assembler {\.rodata\.f1\.str} } } */ +/* { dg-final { scan-assembler {\.rodata\.f2\.str} } } */ +/* { dg-final { scan-assembler-not {\.rodata\.f3\.str} } } */ +/* { dg-final { scan-assembler {\.rodata\.f4\.str} } } */ diff --git a/gcc/varasm.c b/gcc/varasm.c index 62d5163..11cb2c5 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -783,6 +783,18 @@ default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED) return readonly_data_section; } +/* A subroutine of mergeable_string_section and mergeable_constant_section. */ + +static 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 +816,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 +869,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