diff mbox series

[3/3,MSP430] Use default_elf_select_section to select sections for data where possible

Message ID 20190830111411.2b258770@jozef-kubuntu
State New
Headers show
Series MSP430: Improve attribute handling | expand

Commit Message

Jozef Lawrynowicz Aug. 30, 2019, 10:14 a.m. UTC
With the "noinit" attribute now handled generically, direct assignment of
data with the "noinit" attribute to the ".noinit" attribute can be removed from
the msp430 back end, and default_elf_select_section can be used instead.

default_elf_select_section can also be used for SECCAT_RODATA_MERGE_* sections,
to enable the linker to merge constant data.

Comments

Jeff Law Sept. 3, 2019, 7:40 p.m. UTC | #1
On 8/30/19 4:14 AM, Jozef Lawrynowicz wrote:
> With the "noinit" attribute now handled generically, direct assignment of
> data with the "noinit" attribute to the ".noinit" attribute can be removed from
> the msp430 back end, and default_elf_select_section can be used instead.
> 
> default_elf_select_section can also be used for SECCAT_RODATA_MERGE_* sections,
> to enable the linker to merge constant data.
> 
> 
> 0003-MSP430-Use-default_elf_select_section-to-determine-s.patch
> 
> From 2d2bc7f11b7d5bfc918351a5963b041f69aac673 Mon Sep 17 00:00:00 2001
> From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> Date: Wed, 28 Aug 2019 17:54:22 +0100
> Subject: [PATCH 3/3] MSP430: Use default_elf_select_section to determine
>  sections for data where possible
> 
> gcc/ChangeLog:
> 
> 2019-08-29  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
> 
> 	* config/msp430/msp430.c (msp430_init_sections): Remove handling of the
> 	noinit section.
> 	(msp430_select_section): Handle decls with the "noinit" attribute with
> 	default_elf_select_section.
> 	Handle SECCAT_RODATA_MERGE_* section types with
> 	default_elf_select_section.
> 	Add comments about handling of unsupported section types.
> 	(msp430_section_type_flags): Remove handling of the noinit section.
And OK as well.

jeff
diff mbox series

Patch

From 2d2bc7f11b7d5bfc918351a5963b041f69aac673 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Wed, 28 Aug 2019 17:54:22 +0100
Subject: [PATCH 3/3] MSP430: Use default_elf_select_section to determine
 sections for data where possible

gcc/ChangeLog:

2019-08-29  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* config/msp430/msp430.c (msp430_init_sections): Remove handling of the
	noinit section.
	(msp430_select_section): Handle decls with the "noinit" attribute with
	default_elf_select_section.
	Handle SECCAT_RODATA_MERGE_* section types with
	default_elf_select_section.
	Add comments about handling of unsupported section types.
	(msp430_section_type_flags): Remove handling of the noinit section.

---
 gcc/config/msp430/msp430.c | 81 +++++++++++++++++++++++---------------
 1 file changed, 50 insertions(+), 31 deletions(-)

diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
index 1b2e9683a94..d409ea15df2 100644
--- a/gcc/config/msp430/msp430.c
+++ b/gcc/config/msp430/msp430.c
@@ -1785,7 +1785,6 @@  gen_prefix (tree decl)
   return NULL;
 }
 
-static section * noinit_section;
 static section * persist_section;
 
 #undef  TARGET_ASM_INIT_SECTIONS
@@ -1794,8 +1793,6 @@  static section * persist_section;
 static void
 msp430_init_sections (void)
 {
-  noinit_section = get_unnamed_section (0, output_section_asm_op,
-					".section .noinit,\"aw\"");
   persist_section = get_unnamed_section (0, output_section_asm_op,
 					 ".section .persistent,\"aw\"");
 }
@@ -1806,6 +1803,10 @@  msp430_init_sections (void)
 static section *
 msp430_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
 {
+  const char * prefix;
+  const char * sec_name;
+  const char * base_sec_name;
+
   gcc_assert (decl != NULL_TREE);
 
   if (TREE_CODE (decl) == STRING_CST
@@ -1821,51 +1822,71 @@  msp430_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
       && is_interrupt_func (decl))
     return get_section (".lowtext", SECTION_CODE | SECTION_WRITE , decl);
 
-  const char * prefix = gen_prefix (decl);
-  if (prefix == NULL)
-    {
-      if (TREE_CODE (decl) == FUNCTION_DECL)
-	return text_section;
-      /* FIXME: ATTR_NOINIT is handled generically in
-	 default_elf_select_section.  */
-      else if (has_attr (ATTR_NOINIT, decl))
-	return noinit_section;
-      else if (has_attr (ATTR_PERSIST, decl))
-	return persist_section;
-      else
-	return default_select_section (decl, reloc, align);
-    }
+  if (has_attr (ATTR_PERSIST, decl))
+    return persist_section;
+
+  /* ATTR_NOINIT is handled generically.  */
+  if (has_attr (ATTR_NOINIT, decl))
+    return default_elf_select_section (decl, reloc, align);
+
+  prefix = gen_prefix (decl);
 
-  const char * sec;
   switch (categorize_decl_for_section (decl, reloc))
     {
-    case SECCAT_TEXT:   sec = ".text";   break;
-    case SECCAT_DATA:   sec = ".data";   break;
-    case SECCAT_BSS:    sec = ".bss";    break;
-    case SECCAT_RODATA: sec = ".rodata"; break;
+    case SECCAT_TEXT:
+      if (!prefix)
+	return text_section;
+      base_sec_name = ".text";
+      break;
+    case SECCAT_DATA:
+      if (!prefix)
+	return data_section;
+      base_sec_name = ".data";
+      break;
+    case SECCAT_BSS:
+      if (!prefix)
+	return bss_section;
+      base_sec_name = ".bss";
+      break;
+    case SECCAT_RODATA:
+      if (!prefix)
+	return readonly_data_section;
+      base_sec_name = ".rodata";
+      break;
 
+    /* Enable merging of constant data by the GNU linker using
+       default_elf_select_section and therefore enabling creation of
+       sections with the SHF_MERGE flag.  */
     case SECCAT_RODATA_MERGE_STR:
     case SECCAT_RODATA_MERGE_STR_INIT:
     case SECCAT_RODATA_MERGE_CONST:
+      return default_elf_select_section (decl, reloc, align);
+
+    /* The sections listed below are are not supported for MSP430.
+       They should not be generated, but in case they are, we use
+       default_select_section so they get placed in sections
+       the msp430 assembler and linker understand.  */
+    /* "small data" sections are not supported.  */
     case SECCAT_SRODATA:
-    case SECCAT_DATA_REL:
-    case SECCAT_DATA_REL_LOCAL:
-    case SECCAT_DATA_REL_RO:
-    case SECCAT_DATA_REL_RO_LOCAL:
     case SECCAT_SDATA:
     case SECCAT_SBSS:
+    /* Thread-local storage (TLS) is not supported.  */
     case SECCAT_TDATA:
     case SECCAT_TBSS:
+    /* Sections used by a dynamic linker are not supported.  */
+    case SECCAT_DATA_REL:
+    case SECCAT_DATA_REL_LOCAL:
+    case SECCAT_DATA_REL_RO:
+    case SECCAT_DATA_REL_RO_LOCAL:
       return default_select_section (decl, reloc, align);
 
     default:
       gcc_unreachable ();
     }
 
-  const char * dec_name = DECL_SECTION_NAME (decl);
-  char * name = ACONCAT ((prefix, sec, dec_name, NULL));
+  sec_name = ACONCAT ((prefix, base_sec_name, DECL_SECTION_NAME (decl), NULL));
 
-  return get_named_section (decl, name, 0);
+  return get_named_section (decl, sec_name, 0);
 }
 
 #undef  TARGET_ASM_FUNCTION_SECTION
@@ -1901,8 +1922,6 @@  msp430_section_type_flags (tree decl, const char * name, int reloc)
     name += strlen (upper_prefix);
   else if (strncmp (name, either_prefix, strlen (either_prefix)) == 0)
     name += strlen (either_prefix);
-  else if (strcmp (name, ".noinit") == 0)
-    return SECTION_WRITE | SECTION_BSS | SECTION_NOTYPE;
   else if (strcmp (name, ".persistent") == 0)
     return SECTION_WRITE | SECTION_NOTYPE;
 
-- 
2.17.1