[lld] 8b01b63 - [ELF] demoteSharedSymbols: make binding more appropriate for lazy symbols. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 12 20:43:44 PST 2022


Author: Fangrui Song
Date: 2022-02-12T20:43:40-08:00
New Revision: 8b01b638d0145473d27a0dd99ded48cc5a8b85a1

URL: https://github.com/llvm/llvm-project/commit/8b01b638d0145473d27a0dd99ded48cc5a8b85a1
DIFF: https://github.com/llvm/llvm-project/commit/8b01b638d0145473d27a0dd99ded48cc5a8b85a1.diff

LOG: [ELF] demoteSharedSymbols: make binding more appropriate for lazy symbols. NFC

The binding will matter if we remove the `sym->replace(und)` kludge from
initializeSymbols.
While here, rename the function to be more appropriate.

Added: 
    

Modified: 
    lld/ELF/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index d9d9911987654..f586d012df727 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1822,20 +1822,21 @@ static void replaceCommonSymbols() {
   }
 }
 
-// If all references to a DSO happen to be weak, the DSO is not added
-// to DT_NEEDED. If that happens, we need to eliminate shared symbols
-// created from the DSO. Otherwise, they become dangling references
-// that point to a non-existent DSO.
-static void demoteSharedSymbols() {
-  llvm::TimeTraceScope timeScope("Demote shared symbols");
+// If all references to a DSO happen to be weak, the DSO is not added to
+// DT_NEEDED. If that happens, replace ShardSymbol with Undefined to avoid
+// dangling references to an unneeded DSO. Use a weak binding to avoid
+// --no-allow-shlib-undefined diagnostics. Similarly, demote lazy symbols.
+static void demoteSharedAndLazySymbols() {
+  llvm::TimeTraceScope timeScope("Demote shared and lazy symbols");
   for (Symbol *sym : symtab->symbols()) {
     auto *s = dyn_cast<SharedSymbol>(sym);
     if (!(s && !s->getFile().isNeeded) && !sym->isLazy())
       continue;
 
     bool used = sym->used;
+    uint8_t binding = sym->isLazy() ? sym->binding : uint8_t(STB_WEAK);
     sym->replace(
-        Undefined{nullptr, sym->getName(), STB_WEAK, sym->stOther, sym->type});
+        Undefined{nullptr, sym->getName(), binding, sym->stOther, sym->type});
     sym->used = used;
     sym->versionId = VER_NDX_GLOBAL;
   }
@@ -2502,7 +2503,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
 
   // Garbage collection and removal of shared symbols from unused shared objects.
   invokeELFT(markLive);
-  demoteSharedSymbols();
+  demoteSharedAndLazySymbols();
 
   // Make copies of any input sections that need to be copied into each
   // partition.


        


More information about the llvm-commits mailing list