[lld] 9e6840c - [ELF] Remove resolve => resolve{Defined,Common,Shared,Lazy,Undefined} indirection. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 28 20:01:50 PDT 2022


Author: Fangrui Song
Date: 2022-09-28T20:01:41-07:00
New Revision: 9e6840ccbae5c8e34e6aaa417b8e6cf4a60facf3

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

LOG: [ELF] Remove resolve => resolve{Defined,Common,Shared,Lazy,Undefined} indirection. NFC

Added: 
    

Modified: 
    lld/ELF/Driver.cpp
    lld/ELF/SymbolTable.cpp
    lld/ELF/SymbolTable.h
    lld/ELF/Symbols.cpp
    lld/ELF/Symbols.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index fddc7af4a4d7..74b16e016791 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -2269,9 +2269,14 @@ static void combineVersionedSymbol(Symbol &sym,
     map.try_emplace(&sym, sym2);
     // If both foo at v1 and foo@@v1 are defined and non-weak, report a
     // duplicate definition error.
-    if (sym.isDefined())
+    if (sym.isDefined()) {
       sym2->checkDuplicate(cast<Defined>(sym));
-    sym2->resolve(sym);
+      sym2->resolve(cast<Defined>(sym));
+    } else if (sym.isUndefined()) {
+      sym2->resolve(cast<Undefined>(sym));
+    } else {
+      sym2->resolve(cast<SharedSymbol>(sym));
+    }
     // Eliminate foo at v1 from the symbol table.
     sym.symbolKind = Symbol::PlaceholderKind;
     sym.isUsedInRegularObj = false;

diff  --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index e481a4ea31ce..baa085c9c713 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -99,12 +99,6 @@ Symbol *SymbolTable::insert(StringRef name) {
   return sym;
 }
 
-Symbol *SymbolTable::addSymbol(const Symbol &newSym) {
-  Symbol *sym = insert(newSym.getName());
-  sym->resolve(newSym);
-  return sym;
-}
-
 // This variant of addSymbol is used by BinaryFile::parse to check duplicate
 // symbol errors.
 Symbol *SymbolTable::addAndCheckDuplicate(const Defined &newSym) {

diff  --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h
index 77d8ded0b011..7d6ab93585e6 100644
--- a/lld/ELF/SymbolTable.h
+++ b/lld/ELF/SymbolTable.h
@@ -38,7 +38,11 @@ class SymbolTable {
 
   Symbol *insert(StringRef name);
 
-  Symbol *addSymbol(const Symbol &newSym);
+  template <typename T> Symbol *addSymbol(const T &newSym) {
+    Symbol *sym = insert(newSym.getName());
+    sym->resolve(newSym);
+    return sym;
+  }
   Symbol *addAndCheckDuplicate(const Defined &newSym);
 
   void scanVersionScript();

diff  --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index a5e814e04f09..90ce5048ea72 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -383,31 +383,11 @@ void Symbol::mergeProperties(const Symbol &other) {
   }
 }
 
-void Symbol::resolve(const Symbol &other) {
-  mergeProperties(other);
-
-  switch (other.kind()) {
-  case Symbol::UndefinedKind:
-    resolveUndefined(cast<Undefined>(other));
-    break;
-  case Symbol::CommonKind:
-    resolveCommon(cast<CommonSymbol>(other));
-    break;
-  case Symbol::DefinedKind:
-    resolveDefined(cast<Defined>(other));
-    break;
-  case Symbol::LazyObjectKind:
-    resolveLazy(cast<LazyObject>(other));
-    break;
-  case Symbol::SharedKind:
-    resolveShared(cast<SharedSymbol>(other));
-    break;
-  case Symbol::PlaceholderKind:
-    llvm_unreachable("bad symbol kind");
+void Symbol::resolve(const Undefined &other) {
+  if (other.visibility() != STV_DEFAULT) {
+    uint8_t v = visibility(), ov = other.visibility();
+    setVisibility(v == STV_DEFAULT ? ov : std::min(v, ov));
   }
-}
-
-void Symbol::resolveUndefined(const Undefined &other) {
   // An undefined symbol with non default visibility must be satisfied
   // in the same DSO.
   //
@@ -583,7 +563,13 @@ void Symbol::checkDuplicate(const Defined &other) const {
                     other.value);
 }
 
-void Symbol::resolveCommon(const CommonSymbol &other) {
+void Symbol::resolve(const CommonSymbol &other) {
+  if (other.exportDynamic)
+    exportDynamic = true;
+  if (other.visibility() != STV_DEFAULT) {
+    uint8_t v = visibility(), ov = other.visibility();
+    setVisibility(v == STV_DEFAULT ? ov : std::min(v, ov));
+  }
   if (isDefined() && !isWeak()) {
     if (config->warnCommon)
       warn("common " + getName() + " is overridden");
@@ -615,12 +601,18 @@ void Symbol::resolveCommon(const CommonSymbol &other) {
   }
 }
 
-void Symbol::resolveDefined(const Defined &other) {
+void Symbol::resolve(const Defined &other) {
+  if (other.exportDynamic)
+    exportDynamic = true;
+  if (other.visibility() != STV_DEFAULT) {
+    uint8_t v = visibility(), ov = other.visibility();
+    setVisibility(v == STV_DEFAULT ? ov : std::min(v, ov));
+  }
   if (shouldReplace(other))
     other.overwrite(*this);
 }
 
-void Symbol::resolveLazy(const LazyObject &other) {
+void Symbol::resolve(const LazyObject &other) {
   if (isPlaceholder()) {
     other.overwrite(*this);
     return;
@@ -659,7 +651,8 @@ void Symbol::resolveLazy(const LazyObject &other) {
     recordWhyExtract(oldFile, *file, *this);
 }
 
-void Symbol::resolveShared(const SharedSymbol &other) {
+void Symbol::resolve(const SharedSymbol &other) {
+  exportDynamic = true;
   if (isPlaceholder()) {
     other.overwrite(*this);
     return;

diff  --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index e4ec63ac50e9..6e8f0a0414e3 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -241,7 +241,11 @@ class Symbol {
   // For example, if "this" is an undefined symbol and a new symbol is
   // a defined symbol, "this" is replaced with the new symbol.
   void mergeProperties(const Symbol &other);
-  void resolve(const Symbol &other);
+  void resolve(const Undefined &other);
+  void resolve(const CommonSymbol &other);
+  void resolve(const Defined &other);
+  void resolve(const LazyObject &other);
+  void resolve(const SharedSymbol &other);
 
   // If this is a lazy symbol, extract an input file and add the symbol
   // in the file to the symbol table. Calling this function on
@@ -251,12 +255,6 @@ class Symbol {
   void checkDuplicate(const Defined &other) const;
 
 private:
-  void resolveUndefined(const Undefined &other);
-  void resolveCommon(const CommonSymbol &other);
-  void resolveDefined(const Defined &other);
-  void resolveLazy(const LazyObject &other);
-  void resolveShared(const SharedSymbol &other);
-
   bool shouldReplace(const Defined &other) const;
 
 protected:


        


More information about the llvm-commits mailing list