Move copy function from Symbol to SymbolBody.

We could have add this function either Symbol or SymbolBody. I added it
to Symbol at first. But I noticed that if I've added it to SymbolBody,
we could've removed SymbolBody::setName(). So I'll do that in this patch.

llvm-svn: 306590
This commit is contained in:
Rui Ueyama 2017-06-28 19:43:02 +00:00
parent 6f61e237cc
commit b2269ec4d3
3 changed files with 17 additions and 18 deletions

View File

@ -195,7 +195,7 @@ template <class ELFT> void SymbolTable<ELFT>::applySymbolRenames() {
for (auto &KV : Config->RenamedSymbols) {
Symbol *Dst = KV.first;
Symbol *Src = KV.second.Target;
Dst->copyBody(Src);
Dst->body()->copy(Src->body());
Dst->Binding = KV.second.OriginalBinding;
}
}

View File

@ -159,6 +159,21 @@ bool SymbolBody::isPreemptible() const {
return true;
}
// Overwrites all attributes except symbol name with Other's so that
// this symbol becomes an alias to Other. This is useful for handling
// some options such as --wrap.
//
// The reason why we want to keep the symbol name is because, if we
// copy symbol names, we'll end up having symbol tables in resulting
// executables or DSOs containing two or more identical symbols, which
// is just inconvenient.
void SymbolBody::copy(SymbolBody *Other) {
StringRef S = Name;
memcpy(symbol()->Body.buffer, Other->symbol()->Body.buffer,
sizeof(Symbol::Body));
Name = S;
}
uint64_t SymbolBody::getVA(int64_t Addend) const {
uint64_t OutVA = getSymVA(*this, Addend);
return OutVA + Addend;
@ -348,20 +363,6 @@ bool Symbol::includeInDynsym() const {
(body()->isUndefined() && Config->Shared);
}
// copyBody overwrites all attributes except symbol name with Other's
// so that this symbol becomes an alias to Other. This is useful for
// handling some options such as --wrap.
//
// The reason why we want to keep the symbol name is because, if we
// copy symbol names, we'll end up having symbol tables in resulting
// executables or DSOs containing two identical symbols, which is just
// inconvenient.
void Symbol::copyBody(Symbol *Other) {
StringRef S = body()->getName();
memcpy(this->Body.buffer, Other->Body.buffer, sizeof(Symbol::Body));
body()->setName(S);
}
// Print out a log message for --trace-symbol.
void elf::printTraceSymbol(Symbol *Sym) {
SymbolBody *B = Sym->body();

View File

@ -69,9 +69,9 @@ public:
bool isLocal() const { return IsLocal; }
bool isPreemptible() const;
StringRef getName() const { return Name; }
void setName(StringRef S) { Name = S; }
uint8_t getVisibility() const { return StOther & 0x3; }
void parseSymbolVersion();
void copy(SymbolBody *Other);
bool isInGot() const { return GotIndex != -1U; }
bool isInPlt() const { return PltIndex != -1U; }
@ -379,8 +379,6 @@ struct Symbol {
SymbolBody *body() { return reinterpret_cast<SymbolBody *>(Body.buffer); }
const SymbolBody *body() const { return const_cast<Symbol *>(this)->body(); }
void copyBody(Symbol *Other);
};
void printTraceSymbol(Symbol *Sym);