summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2022-01-12 12:47:07 -0800
committerFangrui Song <i@maskray.me>2022-01-12 12:47:07 -0800
commit43d927984c262aa403cc404846a496b7d64c1c67 (patch)
treee7edc31beda43865698607dfc43fd8e579e3cc27
parentb592cbf329eafcb1402df8bd1840694a1955683a (diff)
[ELF] Refactor how .gnu.hash and .hash are discarded
Switch to the D114180 approach which is simpler and allows gnuHashTab/hashTab to switch to unique_ptr.
-rw-r--r--lld/ELF/LinkerScript.cpp8
-rw-r--r--lld/ELF/SyntheticSections.cpp4
2 files changed, 2 insertions, 10 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 00a5492031bf..fa41f4d5c50e 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -564,14 +564,6 @@ void LinkerScript::discard(InputSectionBase &s) {
if (&s == in.shStrTab.get())
error("discarding " + s.name + " section is not allowed");
- // You can discard .hash and .gnu.hash sections by linker scripts.
- // Since they are synthesized sections, we need to handle them differently
- // than other regular sections.
- if (&s == mainPart->gnuHashTab)
- mainPart->gnuHashTab = nullptr;
- else if (&s == mainPart->hashTab)
- mainPart->hashTab = nullptr;
-
s.markDead();
s.parent = nullptr;
for (InputSection *sec : s.dependentSections)
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 680281f3315e..f41459dc70d4 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1464,9 +1464,9 @@ DynamicSection<ELFT>::computeContents() {
addInt(DT_STRSZ, part.dynStrTab->getSize());
if (!config->zText)
addInt(DT_TEXTREL, 0);
- if (part.gnuHashTab)
+ if (part.gnuHashTab && part.gnuHashTab->getParent())
addInSec(DT_GNU_HASH, *part.gnuHashTab);
- if (part.hashTab)
+ if (part.hashTab && part.hashTab->getParent())
addInSec(DT_HASH, *part.hashTab);
if (isMain) {