summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2018-12-10 09:07:30 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2018-12-10 09:07:30 +0000
commit4af28e46ca8db0a0abc76a613871972597e48e5c (patch)
tree84a7a5b9d4b6f5d8f4cebb894f5d0dd4303e601b
parent50bd2ec19818fd41feb310467b660a4e52db6dd6 (diff)
downloadbcm5719-llvm-4af28e46ca8db0a0abc76a613871972597e48e5c.tar.gz
bcm5719-llvm-4af28e46ca8db0a0abc76a613871972597e48e5c.zip
[LLD][ELF] - Support discarding .dynstr section.
This is a part of https://bugs.llvm.org/show_bug.cgi?id=39810. The patch allows discarding the .dynstr section using linker script. Differential revision: https://reviews.llvm.org/D55215 llvm-svn: 348746
-rw-r--r--lld/ELF/LinkerScript.cpp2
-rw-r--r--lld/ELF/SyntheticSections.cpp13
-rw-r--r--lld/test/ELF/linkerscript/discard-section-err.s5
3 files changed, 12 insertions, 8 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 66ce07a2119..dad43d5b537 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -416,7 +416,7 @@ LinkerScript::computeInputSections(const InputSectionDescription *Cmd) {
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
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index a0dab238b4b..d3a7a273bef 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1313,7 +1313,9 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
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 @@ static bool sortMipsSymbols(const SymbolTableEntry &L,
}
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 @@ void VersionDefinitionSection::finalizeContents() {
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>::writeTo(uint8_t *Buf) {
}
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();
}
diff --git a/lld/test/ELF/linkerscript/discard-section-err.s b/lld/test/ELF/linkerscript/discard-section-err.s
index 4238b0982f2..13dd688cf16 100644
--- a/lld/test/ELF/linkerscript/discard-section-err.s
+++ b/lld/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 | \
OpenPOWER on IntegriCloud