[lld] 43d9279 - [ELF] Refactor how .gnu.hash and .hash are discarded

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 12 12:47:12 PST 2022


Author: Fangrui Song
Date: 2022-01-12T12:47:07-08:00
New Revision: 43d927984c262aa403cc404846a496b7d64c1c67

URL: https://github.com/llvm/llvm-project/commit/43d927984c262aa403cc404846a496b7d64c1c67
DIFF: https://github.com/llvm/llvm-project/commit/43d927984c262aa403cc404846a496b7d64c1c67.diff

LOG: [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.

Added: 
    

Modified: 
    lld/ELF/LinkerScript.cpp
    lld/ELF/SyntheticSections.cpp

Removed: 
    


################################################################################
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 
diff erently
-  // 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) {


        


More information about the llvm-commits mailing list