Skip to content

Commit

Permalink
[ELF] Refactor how .gnu.hash and .hash are discarded
Browse files Browse the repository at this point in the history
Switch to the D114180 approach which is simpler and allows gnuHashTab/hashTab to
switch to unique_ptr.
  • Loading branch information
MaskRay committed Jan 12, 2022
1 parent b592cbf commit 43d9279
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
8 changes: 0 additions & 8 deletions lld/ELF/LinkerScript.cpp
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/SyntheticSections.cpp
Expand Up @@ -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) {
Expand Down

0 comments on commit 43d9279

Please sign in to comment.