[lld] 5ad2aae - [ELF] SharedFile::parse: move verdefIndex assignment outside of ctor. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 5 20:43:55 PST 2022
Author: Fangrui Song
Date: 2022-02-05T20:43:51-08:00
New Revision: 5ad2aae24474bb5366e84bfe27a5052185d856ce
URL: https://github.com/llvm/llvm-project/commit/5ad2aae24474bb5366e84bfe27a5052185d856ce
DIFF: https://github.com/llvm/llvm-project/commit/5ad2aae24474bb5366e84bfe27a5052185d856ce.diff
LOG: [ELF] SharedFile::parse: move verdefIndex assignment outside of ctor. NFC
SharedSymbol::SharedSymbol initializes verdefIndex and Symbol::replace
copies verdefIndex.
By move verdefIndex assignment outside of ctor, Symbol::replace can be changed
to not copy verdefIndex. This can be used to decrease work for for
ObjKind/BitcodeKind.
Added:
Modified:
lld/ELF/InputFiles.cpp
lld/ELF/Symbols.h
Removed:
################################################################################
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 7b25617e52505..ebe4f99e84d0e 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1530,9 +1530,11 @@ template <class ELFT> void SharedFile::parse() {
uint32_t alignment = getAlignment<ELFT>(sections, sym);
if (!(versyms[i] & VERSYM_HIDDEN)) {
- symtab.addSymbol(SharedSymbol{*this, name, sym.getBinding(), sym.st_other,
- sym.getType(), sym.st_value, sym.st_size,
- alignment, idx});
+ auto *s = symtab.addSymbol(
+ SharedSymbol{*this, name, sym.getBinding(), sym.st_other,
+ sym.getType(), sym.st_value, sym.st_size, alignment});
+ if (s->file == this)
+ s->verdefIndex = idx;
}
// Also add the symbol with the versioned name to handle undefined symbols
@@ -1552,9 +1554,11 @@ template <class ELFT> void SharedFile::parse() {
reinterpret_cast<const Elf_Verdef *>(verdefs[idx])->getAux()->vda_name;
versionedNameBuffer.clear();
name = (name + "@" + verName).toStringRef(versionedNameBuffer);
- symtab.addSymbol(SharedSymbol{*this, saver().save(name), sym.getBinding(),
- sym.st_other, sym.getType(), sym.st_value,
- sym.st_size, alignment, idx});
+ auto *s = symtab.addSymbol(
+ SharedSymbol{*this, saver().save(name), sym.getBinding(), sym.st_other,
+ sym.getType(), sym.st_value, sym.st_size, alignment});
+ if (s->file == this)
+ s->verdefIndex = idx;
}
}
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index d5946bd0271cf..271b0fadae23c 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -140,7 +140,7 @@ class Symbol {
// True if the name contains '@'.
uint8_t hasVersionSuffix : 1;
- inline void replace(const Symbol &newSym);
+ inline void replace(const Symbol &other);
bool includeInDynsym() const;
uint8_t computeBinding() const;
@@ -388,10 +388,9 @@ class SharedSymbol : public Symbol {
SharedSymbol(InputFile &file, StringRef name, uint8_t binding,
uint8_t stOther, uint8_t type, uint64_t value, uint64_t size,
- uint32_t alignment, uint16_t verdefIndex)
+ uint32_t alignment)
: Symbol(SharedKind, &file, name, binding, stOther, type), value(value),
size(size), alignment(alignment) {
- this->verdefIndex = verdefIndex;
exportDynamic = true;
// GNU ifunc is a mechanism to allow user-supplied functions to
// resolve PLT slot values at load-time. This is contrary to the
@@ -559,7 +558,7 @@ size_t Symbol::getSymbolSize() const {
// replace() replaces "this" object with a given symbol by memcpy'ing
// it over to "this". This function is called as a result of name
// resolution, e.g. to replace an undefind symbol with a defined symbol.
-void Symbol::replace(const Symbol &newSym) {
+void Symbol::replace(const Symbol &other) {
using llvm::ELF::STT_TLS;
// st_value of STT_TLS represents the assigned offset, not the actual address
@@ -569,14 +568,14 @@ void Symbol::replace(const Symbol &newSym) {
// exceptions: (a) a STT_NOTYPE lazy/undefined symbol can be replaced by a
// STT_TLS symbol, (b) a STT_TLS undefined symbol can be replaced by a
// STT_NOTYPE lazy symbol.
- if (symbolKind != PlaceholderKind && !newSym.isLazy() &&
- (type == STT_TLS) != (newSym.type == STT_TLS) &&
+ if (symbolKind != PlaceholderKind && !other.isLazy() &&
+ (type == STT_TLS) != (other.type == STT_TLS) &&
type != llvm::ELF::STT_NOTYPE)
error("TLS attribute mismatch: " + toString(*this) + "\n>>> defined in " +
- toString(newSym.file) + "\n>>> defined in " + toString(file));
+ toString(other.file) + "\n>>> defined in " + toString(file));
Symbol old = *this;
- memcpy(this, &newSym, newSym.getSymbolSize());
+ memcpy(this, &other, other.getSymbolSize());
// old may be a placeholder. The referenced fields must be initialized in
// SymbolTable::insert.
More information about the llvm-commits
mailing list