mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-15 12:39:19 +00:00
[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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ public:
|
||||
// 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 @@ public:
|
||||
|
||||
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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user