[PATCH] D33628: [ELF] Filter out non InputSection members from InputSections

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 29 22:17:31 PDT 2017


phosek updated this revision to Diff 100661.
phosek added a comment.

Added a test case.


https://reviews.llvm.org/D33628

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript/merge-sections.s


Index: test/ELF/linkerscript/merge-sections.s
===================================================================
--- test/ELF/linkerscript/merge-sections.s
+++ test/ELF/linkerscript/merge-sections.s
@@ -31,6 +31,16 @@
 # 0x19E = begin + sizeof(.foo) = 0x190 + 0xE
 # CHECK-NEXT: Value: 0x19E
 
+# Check that we don't crash with --gc-sections
+# RUN: ld.lld -gc-sections -o %t2 --script %t.script %t -shared
+# RUN: llvm-readobj -s -t %t2 | FileCheck %s --check-prefix=GC
+
+# GC:        Name: .foo
+# GC-NEXT:   Type: SHT_PROGBITS
+# GC-NEXT:   Flags [
+# GC-NEXT:     SHF_ALLOC
+# GC-NEXT:   ]
+
 .section        .foo.1a,"aMS", at progbits,1
 .asciz "foo"
 
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -291,6 +291,9 @@
     size_t SizeBefore = Ret.size();
 
     for (InputSectionBase *Sec : InputSections) {
+      if (!isa<InputSection>(Sec))
+        continue;
+
       if (Sec->Assigned)
         continue;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33628.100661.patch
Type: text/x-patch
Size: 1017 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170530/4c3d35a6/attachment.bin>


More information about the llvm-commits mailing list