Blame SOURCES/0001-Partial-support-of-SHT_GROUP-without-flag.patch

074ff8
diff -r -u --new-file lld-7.0.1.src.orig/ELF/InputFiles.cpp lld-7.0.1.src/ELF/InputFiles.cpp
074ff8
--- lld-7.0.1.src.orig/ELF/InputFiles.cpp	2019-01-25 10:12:56.412850573 +0000
074ff8
+++ lld-7.0.1.src/ELF/InputFiles.cpp	2019-01-25 10:14:50.557726268 +0000
074ff8
@@ -324,17 +324,6 @@
074ff8
   return Signature;
074ff8
 }
074ff8
 
074ff8
-template <class ELFT>
074ff8
-ArrayRef<typename ObjFile<ELFT>::Elf_Word>
074ff8
-ObjFile<ELFT>::getShtGroupEntries(const Elf_Shdr &Sec) {
074ff8
-  const ELFFile<ELFT> &Obj = this->getObj();
074ff8
-  ArrayRef<Elf_Word> Entries =
074ff8
-      CHECK(Obj.template getSectionContentsAsArray<Elf_Word>(&Sec), this);
074ff8
-  if (Entries.empty() || Entries[0] != GRP_COMDAT)
074ff8
-    fatal(toString(this) + ": unsupported SHT_GROUP format");
074ff8
-  return Entries.slice(1);
074ff8
-}
074ff8
-
074ff8
 template <class ELFT> bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &Sec) {
074ff8
   // On a regular link we don't merge sections if -O0 (default is -O1). This
074ff8
   // sometimes makes the linker significantly faster, although the output will
074ff8
@@ -439,22 +428,33 @@
074ff8
     case SHT_GROUP: {
074ff8
       // De-duplicate section groups by their signatures.
074ff8
       StringRef Signature = getShtGroupSignature(ObjSections, Sec);
074ff8
-      bool IsNew = ComdatGroups.insert(CachedHashStringRef(Signature)).second;
074ff8
       this->Sections[I] = &InputSection::Discarded;
074ff8
 
074ff8
-      // If it is a new section group, we want to keep group members.
074ff8
-      // Group leader sections, which contain indices of group members, are
074ff8
-      // discarded because they are useless beyond this point. The only
074ff8
-      // exception is the -r option because in order to produce re-linkable
074ff8
-      // object files, we want to pass through basically everything.
074ff8
+      ArrayRef<Elf_Word> Entries =
074ff8
+          CHECK(Obj.template getSectionContentsAsArray<Elf_Word>(&Sec), this);
074ff8
+      if (Entries.empty())
074ff8
+        fatal(toString(this) + ": empty SHT_GROUP");
074ff8
+
074ff8
+      // The first word of a SHT_GROUP section contains flags. Currently,
074ff8
+      // the standard defines only "GRP_COMDAT" flag for the COMDAT group.
074ff8
+      // An group with the empty flag doesn't define anything; such sections
074ff8
+      // are just skipped.
074ff8
+      if (Entries[0] == 0)
074ff8
+        continue;
074ff8
+
074ff8
+      if (Entries[0] != GRP_COMDAT)
074ff8
+        fatal(toString(this) + ": unsupported SHT_GROUP format");
074ff8
+
074ff8
+      bool IsNew = ComdatGroups.insert(CachedHashStringRef(Signature)).second;
074ff8
       if (IsNew) {
074ff8
         if (Config->Relocatable)
074ff8
           this->Sections[I] = createInputSection(Sec);
074ff8
         continue;
074ff8
       }
074ff8
 
074ff8
+
074ff8
       // Otherwise, discard group members.
074ff8
-      for (uint32_t SecIndex : getShtGroupEntries(Sec)) {
074ff8
+      for (uint32_t SecIndex : Entries.slice(1)) {
074ff8
         if (SecIndex >= Size)
074ff8
           fatal(toString(this) +
074ff8
                 ": invalid section index in group: " + Twine(SecIndex));
074ff8
diff -r -u --new-file lld-7.0.1.src.orig/test/ELF/sht-group-empty.test lld-7.0.1.src/test/ELF/sht-group-empty.test
074ff8
--- lld-7.0.1.src.orig/test/ELF/sht-group-empty.test	1970-01-01 00:00:00.000000000 +0000
074ff8
+++ lld-7.0.1.src/test/ELF/sht-group-empty.test	2019-01-25 10:13:19.312026250 +0000
074ff8
@@ -0,0 +1,55 @@
074ff8
+# RUN: yaml2obj %s -o %t.o
074ff8
+# RUN: ld.lld %t.o %t.o -o %t -r
074ff8
+# RUN: llvm-readobj -s %t | FileCheck %s
074ff8
+
074ff8
+# CHECK:     Name: .text.foo
074ff8
+# CHECK:     Name: .rela.text.foo
074ff8
+
074ff8
+--- !ELF
074ff8
+FileHeader:
074ff8
+  Class:           ELFCLASS64
074ff8
+  Data:            ELFDATA2LSB
074ff8
+  Type:            ET_REL
074ff8
+  Machine:         EM_X86_64
074ff8
+Sections:
074ff8
+  - Name:            .group
074ff8
+    Type:            SHT_GROUP
074ff8
+    Link:            .symtab
074ff8
+    Info:            foo
074ff8
+    Members:
074ff8
+      - SectionOrType:    GRP_COMDAT
074ff8
+      - SectionOrType:    .text.foo
074ff8
+      - SectionOrType:    .text.bar
074ff8
+      - SectionOrType:    .note
074ff8
+  - Name:            .note
074ff8
+    Type:            SHT_NOTE
074ff8
+    Flags:           [ SHF_GROUP ]
074ff8
+  - Name:            .text.foo
074ff8
+    Type:            SHT_PROGBITS
074ff8
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ]
074ff8
+  - Name:            .text.bar
074ff8
+    Type:            SHT_PROGBITS
074ff8
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ]
074ff8
+  - Name:            .rela.text.foo
074ff8
+    Type:            SHT_RELA
074ff8
+    Flags:           [ SHF_INFO_LINK, SHF_GROUP ]
074ff8
+    Link:            .symtab
074ff8
+    Info:            .text.foo
074ff8
+    Relocations:
074ff8
+      - Offset:          0x0000000000000000
074ff8
+        Symbol:          foo
074ff8
+        Type:            R_X86_64_64
074ff8
+  - Name:            .rela.text.bar
074ff8
+    Type:            SHT_RELA
074ff8
+    Flags:           [ SHF_INFO_LINK, SHF_GROUP ]
074ff8
+    Link:            .symtab
074ff8
+    Info:            .text.bar
074ff8
+    Relocations:
074ff8
+      - Offset:          0x0000000000000000
074ff8
+        Symbol:          bar
074ff8
+        Type:            R_X86_64_64
074ff8
+Symbols:
074ff8
+  Global:
074ff8
+    - Name:            foo
074ff8
+    - Name:            bar
074ff8
+