From: Segher Boessenkool Date: Thu, 7 May 2015 15:51:01 +0000 (+0200) Subject: re PR middle-end/192 (String literals don't obey -fdata-sections) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a3facd7c6cdc2d72a001603170a1602743b11803;p=gcc.git re PR middle-end/192 (String literals don't obey -fdata-sections) 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/ * gcc.dg/fdata-sections-2.c: New file. From-SVN: r222880 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 78ba4b2eac3..500f537d845 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2015-05-07 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. + 2015-05-07 Jeff Law * match.pd (bit_and (plus/minus (convert @0) (convert @1) mask): New diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5d2b0a9267a..1bacc3e6d8e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2015-05-07 Segher Boessenkool + + PR middle-end/192 + PR middle-end/54303 + * gcc.dg/fdata-sections-2.c: New file. + 2015-05-07 Marek Polacek PR testsuite/66046 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 00000000000..dda90ba7cc3 --- /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 62d516303c2..11cb2c5ee20 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));