This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[google] Add function name to function_patch_* sections (issue9025045)


Adding function name to the function_patch_* sections when -ffunction-sections is provided. Helps in garbage collecting dead functions with the help of linker.

Tested:
  Tested using 'make -k check-gcc RUNTESTFLAGS="i386.exp=patch* --target_board=unix\{-m32,,-m64\}"'.

2013-04-30  Harshit Chopra  <harshit@google.com>

	* gcc/config/i386/i386.c (ix86_output_function_nops_prologue_epilogue):
	(ix86_elf_asm_named_section):

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index aa6ec82..7cb832b 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -11285,6 +11285,8 @@ ix86_output_function_nops_prologue_epilogue (FILE *file,
   unsigned int section_flags = SECTION_RELRO;
   char *section_name_comdat = NULL;
   const char *decl_section_name = NULL;
+  const char *func_name = NULL;
+  char *section_name_function_sections = NULL;
   size_t len;
 
   gcc_assert (num_remaining_nops >= 0);
@@ -11336,12 +11338,24 @@ ix86_output_function_nops_prologue_epilogue (FILE *file,
     {
       decl_section_name =
           TREE_STRING_POINTER (DECL_SECTION_NAME (current_function_decl));
-      len = strlen (decl_section_name) + strlen (section_name) + 1;
+      len = strlen (decl_section_name) + strlen (section_name) + 2;
       section_name_comdat = (char *) alloca (len);
       sprintf (section_name_comdat, "%s.%s", section_name, decl_section_name);
       section_name = section_name_comdat;
       section_flags |= SECTION_LINKONCE;
     }
+  else if (flag_function_sections)
+    {
+      func_name = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
+      if (func_name)
+        {
+          len = strlen (func_name) + strlen (section_name) + 2;
+          section_name_function_sections = (char *) alloca (len);
+          sprintf (section_name_function_sections, "%s.%s", section_name,
+                   func_name);
+          section_name = section_name_function_sections;
+        }
+    }
   section = get_section (section_name, section_flags, current_function_decl);
   switch_to_section (section);
   /* Align the section to 8-byte boundary.  */
@@ -11369,7 +11383,7 @@ ix86_elf_asm_named_section (const char *name, unsigned int flags,
                             tree decl)
 {
   const char *section_name = name;
-  if (HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE)
+  if (!flag_function_sections && HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE)
     {
       const int prologue_section_name_length =
           sizeof(FUNCTION_PATCH_PROLOGUE_SECTION) - 1;

--
This patch is available for review at http://codereview.appspot.com/9025045


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]