[lld] r304189 - [ELF] Filter out non InputSection members from InputSections
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Mon May 29 22:17:59 PDT 2017
Author: phosek
Date: Tue May 30 00:17:58 2017
New Revision: 304189
URL: http://llvm.org/viewvc/llvm-project?rev=304189&view=rev
Log:
[ELF] Filter out non InputSection members from InputSections
InputSections may contain MergeInputSection members which trigger
a segmentation fault when trying to cast them to InputSection.
Differential Revision: https://reviews.llvm.org/D33628
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/test/ELF/linkerscript/merge-sections.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=304189&r1=304188&r2=304189&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue May 30 00:17:58 2017
@@ -291,6 +291,9 @@ LinkerScript::computeInputSections(const
size_t SizeBefore = Ret.size();
for (InputSectionBase *Sec : InputSections) {
+ if (!isa<InputSection>(Sec))
+ continue;
+
if (Sec->Assigned)
continue;
Modified: lld/trunk/test/ELF/linkerscript/merge-sections.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/merge-sections.s?rev=304189&r1=304188&r2=304189&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/merge-sections.s (original)
+++ lld/trunk/test/ELF/linkerscript/merge-sections.s Tue May 30 00:17:58 2017
@@ -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"
More information about the llvm-commits
mailing list