[lld] r295727 - [ELF] - Do not segfault when using --gc-sections with linker script
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 21 07:46:44 PST 2017
Author: grimar
Date: Tue Feb 21 09:46:43 2017
New Revision: 295727
URL: http://llvm.org/viewvc/llvm-project?rev=295727&view=rev
Log:
[ELF] - Do not segfault when using --gc-sections with linker script
Patch fixes PR32024.
Sections that were not marked as Live has null output section.
Previously we tried to access that field and segfaulted.
Differential revision: https://reviews.llvm.org/D30188
Added:
lld/trunk/test/ELF/linkerscript/sections-gc.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=295727&r1=295726&r2=295727&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Feb 21 09:46:43 2017
@@ -503,6 +503,8 @@ template <class ELFT> void LinkerScript<
continue;
auto *IB = static_cast<InputSectionBase<ELFT> *>(ID);
+ if (!IB->Live)
+ continue;
switchTo(IB->OutSec);
if (auto *I = dyn_cast<InputSection<ELFT>>(IB))
output(I);
Added: lld/trunk/test/ELF/linkerscript/sections-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/sections-gc.s?rev=295727&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/sections-gc.s (added)
+++ lld/trunk/test/ELF/linkerscript/sections-gc.s Tue Feb 21 09:46:43 2017
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "SECTIONS { .text : { *(.text*) } }" > %t.script
+# RUN: ld.lld %t --gc-sections --script %t.script -o %t1
+# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
+
+# CHECK: Sections:
+# CHECK-NEXT: Name Size
+# CHECK: .text 00000001
+
+.section .text.foo, "ax"
+.global _start
+_start:
+ nop
+
+.section .text.bar, "ax"
+.global bar
+bar:
+ nop
More information about the llvm-commits
mailing list