diff mbox

Make mergeable read-only sections per-function, if requested.

Message ID 8f67f9aad3d5b98cb428dea0316a86615b89adb9.1430937961.git.segher@kernel.crashing.org
State New
Headers show

Commit Message

Segher Boessenkool May 6, 2015, 10:59 p.m. UTC
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  <segher@kernel.crashing.org>

	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(-)

Comments

Marek Polacek May 7, 2015, 8:15 a.m. UTC | #1
On Wed, May 06, 2015 at 03:59:33PM -0700, Segher Boessenkool wrote:
> 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.

Dunno if it is a good idea, but...

> 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)

This function needs a comment.

> +{
> +  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;

else is wrongly formatted.

	Marek
Jeff Law May 7, 2015, 1:29 p.m. UTC | #2
On 05/07/2015 02:15 AM, Marek Polacek wrote:
> On Wed, May 06, 2015 at 03:59:33PM -0700, Segher Boessenkool wrote:
>> 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.
>
> Dunno if it is a good idea, but...
Why not?  In a static build it gives the linker a chance to remove 
unreferenced data or to reorder the data to be more tlb or dcache 
friendly.  That's the whole purpose behind -f{function,data}-sections.

Jeff
diff mbox

Patch

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));