[PATCH] D55215: [LLD][ELF] - Support discarding .dynstr section.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 10 01:10:48 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348746: [LLD][ELF] - Support discarding .dynstr section. (authored by grimar, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D55215?vs=176379&id=177466#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D55215/new/
https://reviews.llvm.org/D55215
Files:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/test/ELF/linkerscript/discard-section-err.s
Index: lld/trunk/test/ELF/linkerscript/discard-section-err.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/discard-section-err.s
+++ lld/trunk/test/ELF/linkerscript/discard-section-err.s
@@ -17,10 +17,9 @@
# RUN: FileCheck -check-prefix=DYNSYM %s
# DYNSYM: discarding .dynsym section is not allowed
+## We allow discarding .dynstr, check we don't crash.
# RUN: echo "SECTIONS { /DISCARD/ : { *(.dynstr) } }" > %t.script
-# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \
-# RUN: FileCheck -check-prefix=DYNSTR %s
-# DYNSTR: discarding .dynstr section is not allowed
+# RUN: ld.lld -pie -o %t --script %t.script %t.o
# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.dyn) } }" > %t.script
# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \
Index: lld/trunk/ELF/SyntheticSections.cpp
===================================================================
--- lld/trunk/ELF/SyntheticSections.cpp
+++ lld/trunk/ELF/SyntheticSections.cpp
@@ -1313,7 +1313,9 @@
if (!Config->Shared && !Config->Relocatable && !Config->ZRodynamic)
addInt(DT_DEBUG, 0);
- this->Link = In.DynStrTab->getParent()->SectionIndex;
+ if (OutputSection *Sec = In.DynStrTab->getParent())
+ this->Link = Sec->SectionIndex;
+
if (!In.RelaDyn->empty()) {
addInSec(In.RelaDyn->DynamicTag, In.RelaDyn);
addSize(In.RelaDyn->SizeDynamicTag, In.RelaDyn->getParent());
@@ -1863,7 +1865,8 @@
}
void SymbolTableBaseSection::finalizeContents() {
- getParent()->Link = StrTabSec.getParent()->SectionIndex;
+ if (OutputSection *Sec = StrTabSec.getParent())
+ getParent()->Link = Sec->SectionIndex;
if (this->Type != SHT_DYNSYM) {
sortSymTabSymbols();
@@ -2685,7 +2688,8 @@
for (VersionDefinition &V : Config->VersionDefinitions)
V.NameOff = In.DynStrTab->addString(V.Name);
- getParent()->Link = In.DynStrTab->getParent()->SectionIndex;
+ if (OutputSection *Sec = In.DynStrTab->getParent())
+ getParent()->Link = Sec->SectionIndex;
// sh_info should be set to the number of definitions. This fact is missed in
// documentation, but confirmed by binutils community:
@@ -2829,7 +2833,8 @@
}
template <class ELFT> void VersionNeedSection<ELFT>::finalizeContents() {
- getParent()->Link = In.DynStrTab->getParent()->SectionIndex;
+ if (OutputSection *Sec = In.DynStrTab->getParent())
+ getParent()->Link = Sec->SectionIndex;
getParent()->Info = Needed.size();
}
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -416,7 +416,7 @@
void LinkerScript::discard(ArrayRef<InputSection *> V) {
for (InputSection *S : V) {
if (S == In.ShStrTab || S == In.Dynamic || S == In.DynSymTab ||
- S == In.DynStrTab || S == In.RelaDyn || S == In.RelrDyn)
+ S == In.RelaDyn || S == In.RelrDyn)
error("discarding " + S->Name + " section is not allowed");
// You can discard .hash and .gnu.hash sections by linker scripts. Since
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55215.177466.patch
Type: text/x-patch
Size: 3094 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181210/49380eb1/attachment.bin>
More information about the llvm-commits
mailing list