[lld] r295332 - [ELF] - Do not crash when discarding sections that are referenced by others.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 16 08:06:13 PST 2017
Author: grimar
Date: Thu Feb 16 10:06:13 2017
New Revision: 295332
URL: http://llvm.org/viewvc/llvm-project?rev=295332&view=rev
Log:
[ELF] - Do not crash when discarding sections that are referenced by others.
SHF_LINK_ORDER sections adds special ordering requirements.
Such sections references other sections. Previously we would crash
if section that other were referenced to was discarded by script.
Patch fixes that by discarding all dependent sections in that case.
It supports chained dependencies, testcase is provided.
Differential revision: https://reviews.llvm.org/D30033
Added:
lld/trunk/test/ELF/linkerscript/discard-section-metadata.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=295332&r1=295331&r2=295332&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Feb 16 10:06:13 2017
@@ -277,6 +277,11 @@ void LinkerScript<ELFT>::discard(ArrayRe
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);
}
}
Added: lld/trunk/test/ELF/linkerscript/discard-section-metadata.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/discard-section-metadata.s?rev=295332&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/discard-section-metadata.s (added)
+++ lld/trunk/test/ELF/linkerscript/discard-section-metadata.s Thu Feb 16 10:06:13 2017
@@ -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
More information about the llvm-commits
mailing list