forked from OSchip/llvm-project
[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.
This commit is contained in:
parent
0719c43735
commit
5ad2aae244
|
@ -1530,9 +1530,11 @@ template <class ELFT> void SharedFile::parse() {
|
||||||
|
|
||||||
uint32_t alignment = getAlignment<ELFT>(sections, sym);
|
uint32_t alignment = getAlignment<ELFT>(sections, sym);
|
||||||
if (!(versyms[i] & VERSYM_HIDDEN)) {
|
if (!(versyms[i] & VERSYM_HIDDEN)) {
|
||||||
symtab.addSymbol(SharedSymbol{*this, name, sym.getBinding(), sym.st_other,
|
auto *s = symtab.addSymbol(
|
||||||
sym.getType(), sym.st_value, sym.st_size,
|
SharedSymbol{*this, name, sym.getBinding(), sym.st_other,
|
||||||
alignment, idx});
|
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
|
// 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;
|
reinterpret_cast<const Elf_Verdef *>(verdefs[idx])->getAux()->vda_name;
|
||||||
versionedNameBuffer.clear();
|
versionedNameBuffer.clear();
|
||||||
name = (name + "@" + verName).toStringRef(versionedNameBuffer);
|
name = (name + "@" + verName).toStringRef(versionedNameBuffer);
|
||||||
symtab.addSymbol(SharedSymbol{*this, saver().save(name), sym.getBinding(),
|
auto *s = symtab.addSymbol(
|
||||||
sym.st_other, sym.getType(), sym.st_value,
|
SharedSymbol{*this, saver().save(name), sym.getBinding(), sym.st_other,
|
||||||
sym.st_size, alignment, idx});
|
sym.getType(), sym.st_value, sym.st_size, alignment});
|
||||||
|
if (s->file == this)
|
||||||
|
s->verdefIndex = idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ public:
|
||||||
// True if the name contains '@'.
|
// True if the name contains '@'.
|
||||||
uint8_t hasVersionSuffix : 1;
|
uint8_t hasVersionSuffix : 1;
|
||||||
|
|
||||||
inline void replace(const Symbol &newSym);
|
inline void replace(const Symbol &other);
|
||||||
|
|
||||||
bool includeInDynsym() const;
|
bool includeInDynsym() const;
|
||||||
uint8_t computeBinding() const;
|
uint8_t computeBinding() const;
|
||||||
|
@ -388,10 +388,9 @@ public:
|
||||||
|
|
||||||
SharedSymbol(InputFile &file, StringRef name, uint8_t binding,
|
SharedSymbol(InputFile &file, StringRef name, uint8_t binding,
|
||||||
uint8_t stOther, uint8_t type, uint64_t value, uint64_t size,
|
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),
|
: Symbol(SharedKind, &file, name, binding, stOther, type), value(value),
|
||||||
size(size), alignment(alignment) {
|
size(size), alignment(alignment) {
|
||||||
this->verdefIndex = verdefIndex;
|
|
||||||
exportDynamic = true;
|
exportDynamic = true;
|
||||||
// GNU ifunc is a mechanism to allow user-supplied functions to
|
// GNU ifunc is a mechanism to allow user-supplied functions to
|
||||||
// resolve PLT slot values at load-time. This is contrary to the
|
// 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
|
// replace() replaces "this" object with a given symbol by memcpy'ing
|
||||||
// it over to "this". This function is called as a result of name
|
// 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.
|
// 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;
|
using llvm::ELF::STT_TLS;
|
||||||
|
|
||||||
// st_value of STT_TLS represents the assigned offset, not the actual address
|
// 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
|
// 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_TLS symbol, (b) a STT_TLS undefined symbol can be replaced by a
|
||||||
// STT_NOTYPE lazy symbol.
|
// STT_NOTYPE lazy symbol.
|
||||||
if (symbolKind != PlaceholderKind && !newSym.isLazy() &&
|
if (symbolKind != PlaceholderKind && !other.isLazy() &&
|
||||||
(type == STT_TLS) != (newSym.type == STT_TLS) &&
|
(type == STT_TLS) != (other.type == STT_TLS) &&
|
||||||
type != llvm::ELF::STT_NOTYPE)
|
type != llvm::ELF::STT_NOTYPE)
|
||||||
error("TLS attribute mismatch: " + toString(*this) + "\n>>> defined in " +
|
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;
|
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
|
// old may be a placeholder. The referenced fields must be initialized in
|
||||||
// SymbolTable::insert.
|
// SymbolTable::insert.
|
||||||
|
|
Loading…
Reference in New Issue