[lld] fc5d815 - [ELF] Merge demoteSymbols and isPreemptible computation. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 17 13:52:13 PDT 2023


Author: Fangrui Song
Date: 2023-10-17T13:52:08-07:00
New Revision: fc5d815d547e534df8fdb997899e0cffc65b9e35

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

LOG: [ELF] Merge demoteSymbols and isPreemptible computation. NFC

Remove one iteration of symtab and slightly improve the performance.

Added: 
    

Modified: 
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 5fc4412aa49f13c..1b63a5c20c0bfbc 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -255,16 +255,19 @@ void elf::addReservedSymbols() {
 // 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 demoteSymbols() {
+static void demoteSymbolsAndComputeIsPreemptible() {
   llvm::TimeTraceScope timeScope("Demote symbols");
   for (Symbol *sym : symtab.getSymbols()) {
     auto *s = dyn_cast<SharedSymbol>(sym);
-    if (!(s && !cast<SharedFile>(s->file)->isNeeded) && !sym->isLazy())
-      continue;
-    uint8_t binding = sym->isLazy() ? sym->binding : uint8_t(STB_WEAK);
-    Undefined(nullptr, sym->getName(), binding, sym->stOther, sym->type)
-        .overwrite(*sym);
-    sym->versionId = VER_NDX_GLOBAL;
+    if (sym->isLazy() || (s && !cast<SharedFile>(s->file)->isNeeded)) {
+      uint8_t binding = sym->isLazy() ? sym->binding : uint8_t(STB_WEAK);
+      Undefined(nullptr, sym->getName(), binding, sym->stOther, sym->type)
+          .overwrite(*sym);
+      sym->versionId = VER_NDX_GLOBAL;
+    }
+
+    if (config->hasDynSymTab)
+      sym->isPreemptible = computeIsPreemptible(*sym);
   }
 }
 
@@ -1954,12 +1957,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
     }
   }
 
-  demoteSymbols();
-  if (config->hasDynSymTab) {
-    parallelForEach(symtab.getSymbols(), [](Symbol *sym) {
-      sym->isPreemptible = computeIsPreemptible(*sym);
-    });
-  }
+  demoteSymbolsAndComputeIsPreemptible();
 
   // Change values of linker-script-defined symbols from placeholders (assigned
   // by declareSymbols) to actual definitions.


        


More information about the llvm-commits mailing list