[PATCH] D30188: [ELF] - Do not segfault when using --gc-sections with linker script

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 04:48:06 PST 2017


grimar updated this revision to Diff 89191.
grimar added a comment.

- Addressed review comments


https://reviews.llvm.org/D30188

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


Index: test/ELF/linkerscript/sections-gc.s
===================================================================
--- test/ELF/linkerscript/sections-gc.s
+++ test/ELF/linkerscript/sections-gc.s
@@ -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, "a"
+.global foo
+foo:
+  nop
+
+.section .text.bar
+.global bar
+bar:
+  nop
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -499,6 +499,8 @@
         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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30188.89191.patch
Type: text/x-patch
Size: 1045 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170221/d61598bb/attachment.bin>


More information about the llvm-commits mailing list