Fix GCC handling of special sections so .note* come out SHT_NOTE
This fix is posted upstream but still waiting for review:
PR other/77609: Let the assembler choose ELF section types for miscellaneous named sections
Change-Id: Ibcd1b24b15d643e8b65032c1cc63d5c0ce68b586
diff --git a/patches/gcc-patch.txt b/patches/gcc-patch.txt
index b90aebb..9a12526 100644
--- a/patches/gcc-patch.txt
+++ b/patches/gcc-patch.txt
@@ -80,3 +80,47 @@
tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h"
;;
i[34567]86-*-rdos*)
+
+gcc/
+2016-09-27 Roland McGrath <roland@hack.frob.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".
+
+diff --git a/gcc/varasm.c b/gcc/varasm.c
+index b0f2af0..dcc9976 100644
+--- a/gcc/varasm.c
++++ b/gcc/varasm.c
+@@ -6193,15 +6193,20 @@ 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. */
++ if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS | SECTION_ENTSIZE))
++ && !(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)))
+ flags |= SECTION_NOTYPE;
+
+ return flags;