[lld] r339765 - [LLD][ELF] - Handle SHT_GROUP more carefully. NFCI.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 15 05:20:39 PDT 2018


Author: grimar
Date: Wed Aug 15 05:20:38 2018
New Revision: 339765

URL: http://llvm.org/viewvc/llvm-project?rev=339765&view=rev
Log:
[LLD][ELF] - Handle SHT_GROUP more carefully. NFCI.

This patch solves 2 problems:
1) It adds a test to check the line below:
https://github.com/llvm-mirror/lld/blob/master/ELF/InputFiles.cpp#L334
Test case contains SHT_GROUP section with a broken (0xFF) flag.

2) The patch fixes the case when we silently accepted such broken groups
in the case when there were no other objects with the same group signature.

Added:
    lld/trunk/test/ELF/invalid/comdat-broken.test
Modified:
    lld/trunk/ELF/InputFiles.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=339765&r1=339764&r2=339765&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Aug 15 05:20:38 2018
@@ -442,6 +442,10 @@ void ObjFile<ELFT>::initializeSections(
       bool IsNew = ComdatGroups.insert(CachedHashStringRef(Signature)).second;
       this->Sections[I] = &InputSection::Discarded;
 
+      // We only support GRP_COMDAT type of group. Get the all entries of the
+      // section here to let getShtGroupEntries to check the type early for us.
+      ArrayRef<Elf_Word> Entries = getShtGroupEntries(Sec);
+
       // If it is a new section group, we want to keep group members.
       // Group leader sections, which contain indices of group members, are
       // discarded because they are useless beyond this point. The only
@@ -454,7 +458,7 @@ void ObjFile<ELFT>::initializeSections(
       }
 
       // Otherwise, discard group members.
-      for (uint32_t SecIndex : getShtGroupEntries(Sec)) {
+      for (uint32_t SecIndex : Entries) {
         if (SecIndex >= Size)
           fatal(toString(this) +
                 ": invalid section index in group: " + Twine(SecIndex));

Added: lld/trunk/test/ELF/invalid/comdat-broken.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/comdat-broken.test?rev=339765&view=auto
==============================================================================
--- lld/trunk/test/ELF/invalid/comdat-broken.test (added)
+++ lld/trunk/test/ELF/invalid/comdat-broken.test Wed Aug 15 05:20:38 2018
@@ -0,0 +1,25 @@
+# REQUIRES: x86
+
+# RUN: yaml2obj %s -o %t.o
+# RUN: not ld.lld %t.o -o %t.exe 2>&1 | FileCheck %s
+# RUN: not ld.lld %t.o %t.o -o %t.exe 2>&1 | FileCheck %s
+
+# CHECK: error: {{.*}}.o: unsupported SHT_GROUP format
+
+--- !ELF
+FileHeader:
+  Class:               ELFCLASS64
+  Data:                ELFDATA2LSB
+  Type:                ET_REL
+  Machine:             EM_X86_64
+Sections:
+  - Name:              .group
+    Type:              SHT_GROUP
+    Link:              .symtab
+    Info:              foo
+    Members:
+      - SectionOrType: 0xFF
+      - SectionOrType: 3
+Symbols:
+  Global:
+    - Name:            foo




More information about the llvm-commits mailing list