[lld] f1dccda - [ELF] Pass Ctx & to Symbols

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 6 17:05:48 PDT 2024


Author: Fangrui Song
Date: 2024-10-06T17:05:43-07:00
New Revision: f1dccda1b51c77fcac22b75c535e8620d7544ab3

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

LOG: [ELF] Pass Ctx & to Symbols

Added: 
    

Modified: 
    lld/ELF/Driver.cpp
    lld/ELF/ICF.cpp
    lld/ELF/InputFiles.cpp
    lld/ELF/Symbols.cpp
    lld/ELF/Symbols.h
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index b6aae97dbc249f..c1132ff81f9bc1 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -2951,7 +2951,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
   }
   ctx.nonPrevailingSyms.clear();
   for (const DuplicateSymbol &d : ctx.duplicates)
-    reportDuplicate(*d.sym, d.file, d.section, d.value);
+    reportDuplicate(ctx, *d.sym, d.file, d.section, d.value);
   ctx.duplicates.clear();
 
   // Return if there were name resolution errors.
@@ -3033,7 +3033,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
   });
   parallelForEach(newObjectFiles, postParseObjectFile);
   for (const DuplicateSymbol &d : ctx.duplicates)
-    reportDuplicate(*d.sym, d.file, d.section, d.value);
+    reportDuplicate(ctx, *d.sym, d.file, d.section, d.value);
 
   // ELF dependent libraries may have introduced new input files after LTO has
   // completed. This is an error if the files haven't already been parsed, since

diff  --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index 09582b8af8248f..48d287a0980178 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -471,7 +471,7 @@ template <class ELFT> void ICF<ELFT>::run() {
   // by scanRelocations().
   if (ctx.arg.hasDynSymTab)
     for (Symbol *sym : ctx.symtab->getSymbols())
-      sym->isPreemptible = computeIsPreemptible(*sym);
+      sym->isPreemptible = computeIsPreemptible(ctx, *sym);
 
   // Two text sections may have identical content and relocations but 
diff erent
   // LSDA, e.g. the two functions may have catch blocks of 
diff erent types. If a

diff  --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 7a451f38ba794c..dc107c2d0caede 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1830,7 +1830,7 @@ void BitcodeFile::postParse() {
     int c = irSym.getComdatIndex();
     if (c != -1 && !keptComdats[c])
       continue;
-    reportDuplicate(sym, this, nullptr, 0);
+    reportDuplicate(ctx, sym, this, nullptr, 0);
   }
 }
 

diff  --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 580317c601973d..be04f9776bcd60 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -334,7 +334,7 @@ void elf::maybeWarnUnorderableSymbol(const Symbol *sym) {
 
 // Returns true if a symbol can be replaced at load-time by a symbol
 // with the same name defined in other ELF executable or DSO.
-bool elf::computeIsPreemptible(const Symbol &sym) {
+bool elf::computeIsPreemptible(Ctx &ctx, const Symbol &sym) {
   assert(!sym.isLocal() || sym.isPlaceholder());
 
   // Only symbols with default visibility that appear in dynsym can be
@@ -511,7 +511,7 @@ bool Symbol::shouldReplace(const Defined &other) const {
   return !isGlobal() && other.isGlobal();
 }
 
-void elf::reportDuplicate(const Symbol &sym, const InputFile *newFile,
+void elf::reportDuplicate(Ctx &ctx, const Symbol &sym, const InputFile *newFile,
                           InputSectionBase *errSec, uint64_t errOffset) {
   if (ctx.arg.allowMultipleDefinition)
     return;
@@ -555,7 +555,7 @@ void elf::reportDuplicate(const Symbol &sym, const InputFile *newFile,
 
 void Symbol::checkDuplicate(const Defined &other) const {
   if (isDefined() && !isWeak() && !other.isWeak())
-    reportDuplicate(*this, other.file,
+    reportDuplicate(ctx, *this, other.file,
                     dyn_cast_or_null<InputSectionBase>(other.section),
                     other.value);
 }

diff  --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index f11136fb04c11e..424305233ec862 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -525,10 +525,10 @@ template <typename... T> Defined *makeDefined(T &&...args) {
   return &s;
 }
 
-void reportDuplicate(const Symbol &sym, const InputFile *newFile,
+void reportDuplicate(Ctx &, const Symbol &sym, const InputFile *newFile,
                      InputSectionBase *errSec, uint64_t errOffset);
 void maybeWarnUnorderableSymbol(const Symbol *sym);
-bool computeIsPreemptible(const Symbol &sym);
+bool computeIsPreemptible(Ctx &, const Symbol &sym);
 
 } // namespace elf
 } // namespace lld

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index e10585d7adb8b6..6519cfbd08b3fb 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -290,7 +290,7 @@ static void demoteSymbolsAndComputeIsPreemptible(Ctx &ctx) {
     }
 
     if (ctx.arg.hasDynSymTab)
-      sym->isPreemptible = computeIsPreemptible(*sym);
+      sym->isPreemptible = computeIsPreemptible(ctx, *sym);
   }
 }
 


        


More information about the llvm-commits mailing list