summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <mcgrathr@google.com>2018-02-27 16:25:03 -0800
committerRoland McGrath <mcgrathr@google.com>2018-02-27 16:25:03 -0800
commit7e635af31c4c5caf25fc103bcc96f0e4970fb2da (patch)
tree785bc72c55a8f252e13245ab07e5c67e2de5a665
parent141db77d3600f6792cfab77fd58fcd89e4778612 (diff)
downloadgcc-roland/pr77609.tar.gz
PR other/77609: Let the assembler choose ELF section types for miscellaneous named sectionsroland/pr77609
gcc/ PR other/77609 * varasm.c (default_section_type_flags): Set SECTION_NOTYPE for any section for which we don't know a specific type it should have, regardless of name. Previously this was done only for the exact names ".init_array", ".fini_array", and ".preinit_array". (default_elf_asm_named_section): Add comment about relationship with default_section_type_flags and SECTION_NOTYPE. (get_section): Don't consider it a type conflict if one side has SECTION_NOTYPE and the other doesn't, as long as neither has the SECTION_BSS et al used in the default_section_type_flags logic.
-rw-r--r--gcc/ChangeLog13
-rw-r--r--gcc/varasm.c40
2 files changed, 44 insertions, 9 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d56af0f7363..0a2891b090d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,16 @@
+2018-02-27 Roland McGrath <mcgrathr@google.com>
+
+ PR other/77609
+ * varasm.c (default_section_type_flags): Set SECTION_NOTYPE for
+ any section for which we don't know a specific type it should have,
+ regardless of name. Previously this was done only for the exact
+ names ".init_array", ".fini_array", and ".preinit_array".
+ (default_elf_asm_named_section): Add comment about
+ relationship with default_section_type_flags and SECTION_NOTYPE.
+ (get_section): Don't consider it a type conflict if one side has
+ SECTION_NOTYPE and the other doesn't, as long as neither has the
+ SECTION_BSS et al used in the default_section_type_flags logic.
+
2018-02-27 Richard Biener <rguenther@suse.de>
PR tree-optimization/84512
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 6e345d39d31..84dd6e3d7fe 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -296,6 +296,16 @@ get_section (const char *name, unsigned int flags, tree decl)
else
{
sect = *slot;
+ /* It is fine if one of the sections has SECTION_NOTYPE as long
+ as the other has none of the contrary flags. */
+ if (((sect->common.flags ^ flags) & SECTION_NOTYPE)
+ && !((sect->common.flags | flags)
+ & (SECTION_CODE | SECTION_BSS | SECTION_TLS | SECTION_ENTSIZE
+ | (HAVE_COMDAT_GROUP ? SECTION_LINKONCE : 0))))
+ {
+ sect->common.flags |= SECTION_NOTYPE;
+ flags |= SECTION_NOTYPE;
+ }
if ((sect->common.flags & ~SECTION_DECLARED) != flags
&& ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
{
@@ -6361,15 +6371,23 @@ default_section_type_flags (tree decl, const char *name, int reloc)
|| strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
flags |= SECTION_TLS | SECTION_BSS;
- /* These three sections have special ELF types. They are neither
- SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
- want to print a section type (@progbits or @nobits). If someone
- is silly enough to emit code or TLS variables to one of these
- sections, then don't handle them specially. */
- if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
- && (strcmp (name, ".init_array") == 0
- || strcmp (name, ".fini_array") == 0
- || strcmp (name, ".preinit_array") == 0))
+ /* Various sections have special ELF types that the assembler will
+ assign by default based on the name. They are neither SHT_PROGBITS
+ nor SHT_NOBITS, so when changing sections we don't want to print a
+ section type (@progbits or @nobits). Rather than duplicating the
+ assembler's knowledge of what those special name patterns are, just
+ let the assembler choose the type if we don't know a specific
+ reason to set it to something other than the default. SHT_PROGBITS
+ is the default for sections whose name is not specially known to
+ the assembler, so it does no harm to leave the choice to the
+ assembler when @progbits is the best thing we know to use. If
+ someone is silly enough to emit code or TLS variables to one of
+ these sections, then don't handle them specially.
+
+ default_elf_asm_named_section (below) handles the BSS, TLS, ENTSIZE, and
+ LINKONCE cases when NOTYPE is not set, so leave those to its logic. */
+ if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS | SECTION_ENTSIZE))
+ && !(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)))
flags |= SECTION_NOTYPE;
return flags;
@@ -6455,6 +6473,10 @@ default_elf_asm_named_section (const char *name, unsigned int flags,
fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
+ /* default_section_type_flags (above) knows which flags need special
+ handling here, and sets NOTYPE when none of these apply so that the
+ assembler's logic for default types can apply to user-chosen
+ section names. */
if (!(flags & SECTION_NOTYPE))
{
const char *type;