[lld] r319404 - Don't crash on invalid.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 22:18:31 PST 2017


Author: rafael
Date: Wed Nov 29 22:18:31 2017
New Revision: 319404

URL: http://llvm.org/viewvc/llvm-project?rev=319404&view=rev
Log:
Don't crash on invalid.

Added:
    lld/trunk/test/ELF/invalid-undef-section-symbol.test
Modified:
    lld/trunk/ELF/InputSection.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=319404&r1=319403&r2=319404&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Nov 29 22:18:31 2017
@@ -400,7 +400,12 @@ void InputSection::copyRelocations(uint8
       // avoid having to parse and recreate .eh_frame, we just replace any
       // relocation in it pointing to discarded sections with R_*_NONE, which
       // hopefully creates a frame that is ignored at runtime.
-      SectionBase *Section = cast<Defined>(Sym).Section;
+      auto *D = dyn_cast<Defined>(&Sym);
+      if (!D) {
+        error("STT_SECTION symbol should be defined");
+        continue;
+      }
+      SectionBase *Section = D->Section;
       if (Section == &InputSection::Discarded) {
         P->setSymbolAndType(0, 0, false);
         continue;

Added: lld/trunk/test/ELF/invalid-undef-section-symbol.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid-undef-section-symbol.test?rev=319404&view=auto
==============================================================================
--- lld/trunk/test/ELF/invalid-undef-section-symbol.test (added)
+++ lld/trunk/test/ELF/invalid-undef-section-symbol.test Wed Nov 29 22:18:31 2017
@@ -0,0 +1,27 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: not ld.lld -r %t.o -o %2.o 2>&1 | FileCheck %s
+
+# We used to crash at this.
+# CHECK: STT_SECTION symbol should be defined
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+  - Name:            .rela.text
+    Type:            SHT_RELA
+    AddressAlign:    0x0000000000000008
+    Info:            .text
+    Relocations:
+      - Offset:          0x0000000000000000
+        Symbol:          .text
+        Type:            R_X86_64_NONE
+Symbols:
+  Local:
+    - Name:            .text
+      Type:            STT_SECTION




More information about the llvm-commits mailing list