tstellar / rpms / lld

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