[lld] r301447 - Merge r298569: Force @{init, fini}_array if section name starts with ".{init, fini}_array.".

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 26 12:29:40 PDT 2017


Author: ruiu
Date: Wed Apr 26 14:29:40 2017
New Revision: 301447

URL: http://llvm.org/viewvc/llvm-project?rev=301447&view=rev
Log:
Merge r298569: Force @{init,fini}_array if section name starts with ".{init,fini}_array.".

Related bug: http://bugs.llvm.org/show_bug.cgi?id=32599


Added:
    lld/branches/release_40/test/ELF/init-fini-progbits.s
      - copied unchanged from r298569, lld/trunk/test/ELF/init-fini-progbits.s
Modified:
    lld/branches/release_40/   (props changed)
    lld/branches/release_40/ELF/InputSection.cpp

Propchange: lld/branches/release_40/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Apr 26 14:29:40 2017
@@ -1 +1 @@
-/lld/trunk:292878,292909,293078
+/lld/trunk:292878,292909,293078,298569

Modified: lld/branches/release_40/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/ELF/InputSection.cpp?rev=301447&r1=301446&r2=301447&view=diff
==============================================================================
--- lld/branches/release_40/ELF/InputSection.cpp (original)
+++ lld/branches/release_40/ELF/InputSection.cpp Wed Apr 26 14:29:40 2017
@@ -84,14 +84,32 @@ InputSectionBase<ELFT>::InputSectionBase
     this->Flags &= ~(SHF_MERGE | SHF_STRINGS);
 }
 
+// GNU assembler 2.24 and LLVM 4.0.0's MC (the newest release as of
+// March 2017) fail to infer section types for sections starting with
+// ".init_array." or ".fini_array.". They set SHT_PROGBITS instead of
+// SHF_INIT_ARRAY. As a result, the following assembler directive
+// creates ".init_array.100" with SHT_PROGBITS, for example.
+//
+//   .section .init_array.100, "aw"
+//
+// This function forces SHT_{INIT,FINI}_ARRAY so that we can handle
+// incorrect inputs as if they were correct from the beginning.
+static uint64_t getType(uint64_t Type, StringRef Name) {
+  if (Type == SHT_PROGBITS && Name.startswith(".init_array."))
+    return SHT_INIT_ARRAY;
+  if (Type == SHT_PROGBITS && Name.startswith(".fini_array."))
+    return SHT_FINI_ARRAY;
+  return Type;
+}
+
 template <class ELFT>
 InputSectionBase<ELFT>::InputSectionBase(elf::ObjectFile<ELFT> *File,
                                          const Elf_Shdr *Hdr, StringRef Name,
                                          Kind SectionKind)
-    : InputSectionBase(File, Hdr->sh_flags & ~SHF_INFO_LINK, Hdr->sh_type,
-                       Hdr->sh_entsize, Hdr->sh_link, Hdr->sh_info,
-                       Hdr->sh_addralign, getSectionContents(File, Hdr), Name,
-                       SectionKind) {
+    : InputSectionBase(File, Hdr->sh_flags & ~SHF_INFO_LINK,
+                       getType(Hdr->sh_type, Name), Hdr->sh_entsize,
+                       Hdr->sh_link, Hdr->sh_info, Hdr->sh_addralign,
+                       getSectionContents(File, Hdr), Name, SectionKind) {
   this->Offset = Hdr->sh_offset;
 }
 




More information about the llvm-commits mailing list