[lld] bf9c863 - [ELF] Support discarding .relr.dyn
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 12 11:55:27 PST 2022
Author: Fangrui Song
Date: 2022-01-12T11:55:22-08:00
New Revision: bf9c8636f2cd1c5e6338402b67de06f9ce74cdd9
URL: https://github.com/llvm/llvm-project/commit/bf9c8636f2cd1c5e6338402b67de06f9ce74cdd9
DIFF: https://github.com/llvm/llvm-project/commit/bf9c8636f2cd1c5e6338402b67de06f9ce74cdd9.diff
LOG: [ELF] Support discarding .relr.dyn
db08df0570b6dfaf00d7b1b8555c1d2d4effb224 does not work because part.relrDyn is
a unique_ptr and `reset` destroys the object which may still be referenced.
This commit uses the D114180 approach. Also improve the test to check that there
is no R_X86_64_RELATIVE.
Added:
Modified:
lld/ELF/LinkerScript.cpp
lld/ELF/SyntheticSections.cpp
lld/test/ELF/linkerscript/discard-section-err.s
Removed:
################################################################################
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 8870db771fa7f..00a5492031bff 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -564,15 +564,13 @@ void LinkerScript::discard(InputSectionBase &s) {
if (&s == in.shStrTab.get())
error("discarding " + s.name + " section is not allowed");
- // You can discard .hash, .gnu.hash, and .relr.dyn sections by linker scripts.
+ // You can discard .hash and .gnu.hash sections by linker scripts.
// Since they are synthesized sections, we need to handle them
diff erently
// than other regular sections.
if (&s == mainPart->gnuHashTab)
mainPart->gnuHashTab = nullptr;
else if (&s == mainPart->hashTab)
mainPart->hashTab = nullptr;
- else if (&s == mainPart->relrDyn.get())
- mainPart->relrDyn.reset();
s.markDead();
s.parent = nullptr;
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index d0f3c87ac8c7f..680281f3315ea 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1412,7 +1412,8 @@ DynamicSection<ELFT>::computeContents() {
addInt(isRela ? DT_RELACOUNT : DT_RELCOUNT, numRelativeRels);
}
}
- if (part.relrDyn && !part.relrDyn->relocs.empty()) {
+ if (part.relrDyn && part.relrDyn->getParent() &&
+ !part.relrDyn->relocs.empty()) {
addInSec(config->useAndroidRelrTags ? DT_ANDROID_RELR : DT_RELR,
*part.relrDyn);
addInt(config->useAndroidRelrTags ? DT_ANDROID_RELRSZ : DT_RELRSZ,
diff --git a/lld/test/ELF/linkerscript/discard-section-err.s b/lld/test/ELF/linkerscript/discard-section-err.s
index c186ba00af411..592c33fdd5cc0 100644
--- a/lld/test/ELF/linkerscript/discard-section-err.s
+++ b/lld/test/ELF/linkerscript/discard-section-err.s
@@ -27,6 +27,8 @@
# RUN: llvm-readobj -S %t | FileCheck /dev/null --implicit-check-not='Name: .rela.dyn'
# RUN: echo "SECTIONS { /DISCARD/ : { *(.relr.dyn) } }" > %t.script
+# RUN: ld.lld -pie --pack-dyn-relocs=relr -T %t.script %t.o -o %t
+# RUN: llvm-readobj -S -r %t | FileCheck /dev/null --implicit-check-not='Name: .relr.dyn' --implicit-check-not=R_X86_64_RELATIVE
.data
.align 8
More information about the llvm-commits
mailing list