[PATCH] D30033: [ELF] - Do not crash when discarding sections that are referenced by others.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 16 08:17:52 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL295332: [ELF] - Do not crash when discarding sections that are referenced by others. (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D30033?vs=88702&id=88739#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30033

Files:
  lld/trunk/ELF/LinkerScript.cpp
  lld/trunk/test/ELF/linkerscript/discard-section-metadata.s


Index: lld/trunk/test/ELF/linkerscript/discard-section-metadata.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/discard-section-metadata.s
+++ lld/trunk/test/ELF/linkerscript/discard-section-metadata.s
@@ -0,0 +1,32 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "SECTIONS { /DISCARD/ : { *(.foo) } }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
+
+# CHECK-NOT: .foo
+# CHECK-NOT: .bar
+# CHECK-NOT: .zed
+# CHECK-NOT: .moo
+
+## Sections dependency tree for testcase is:
+## (.foo)
+##   | |
+##   | --(.bar)
+##   |
+##   --(.zed)
+##       |
+##       --(.moo)
+##
+
+.section .foo,"a"
+.quad 0
+
+.section .bar,"am", at progbits,.foo
+.quad 0
+
+.section .zed,"am", at progbits,.foo
+.quad 0
+
+.section .moo,"am", at progbits,.zed
+.quad 0
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -277,6 +277,11 @@
   for (InputSectionBase<ELFT> *S : V) {
     S->Live = false;
     reportDiscarded(S);
+
+    InputSection<ELFT> *IS = dyn_cast<InputSection<ELFT>>(S);
+    if (!IS || IS->DependentSections.empty())
+      continue;
+    discard(IS->DependentSections);
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30033.88739.patch
Type: text/x-patch
Size: 1378 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170216/3e54c4ec/attachment.bin>


More information about the llvm-commits mailing list