mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-03 17:32:59 +00:00
[DWARF] - Speedup handling of relocations in DWARFContextInMemory.
I am working on a speedup of building .gdb_index in LLD and noticed that relocations that are proccessed in DWARFContextInMemory often uses the same symbol in a row. This patch introduces caching to reduce the relocations proccessing time. For benchmark, I took debug LLC binary objects configured with -ggnu-pubnames and linked it using LLD. Link time without --gdb-index is about 4,45s. Link time with --gdb-index: a) Without patch: 19,16s b) With patch: 15,52s That means time spent on --gdb-index in this configuration is 19,16s - 4,45s = 14,71s (without patch) vs 15,52s - 4,45s = 11,07s (with patch). Differential revision: https://reviews.llvm.org/D31136 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303051 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
eadb58fda7
commit
fbe48085e6
@ -905,16 +905,23 @@ static Error createError(const Twine &Reason, llvm::Error E) {
|
|||||||
/// Returns the address of symbol relocation used against. Used for futher
|
/// Returns the address of symbol relocation used against. Used for futher
|
||||||
/// relocations computation. Symbol's section load address is taken in account if
|
/// relocations computation. Symbol's section load address is taken in account if
|
||||||
/// LoadedObjectInfo interface is provided.
|
/// LoadedObjectInfo interface is provided.
|
||||||
static Expected<uint64_t> getSymbolAddress(const object::ObjectFile &Obj,
|
static Expected<uint64_t>
|
||||||
const RelocationRef &Reloc,
|
getSymbolAddress(const object::ObjectFile &Obj, const RelocationRef &Reloc,
|
||||||
const LoadedObjectInfo *L) {
|
const LoadedObjectInfo *L,
|
||||||
|
std::map<SymbolRef, uint64_t> &Cache) {
|
||||||
uint64_t Ret = 0;
|
uint64_t Ret = 0;
|
||||||
object::section_iterator RSec = Obj.section_end();
|
object::section_iterator RSec = Obj.section_end();
|
||||||
object::symbol_iterator Sym = Reloc.getSymbol();
|
object::symbol_iterator Sym = Reloc.getSymbol();
|
||||||
|
|
||||||
|
std::map<SymbolRef, uint64_t>::iterator CacheIt = Cache.end();
|
||||||
// First calculate the address of the symbol or section as it appears
|
// First calculate the address of the symbol or section as it appears
|
||||||
// in the object file
|
// in the object file
|
||||||
if (Sym != Obj.symbol_end()) {
|
if (Sym != Obj.symbol_end()) {
|
||||||
|
bool New;
|
||||||
|
std::tie(CacheIt, New) = Cache.insert({*Sym, 0});
|
||||||
|
if (!New)
|
||||||
|
return CacheIt->second;
|
||||||
|
|
||||||
Expected<uint64_t> SymAddrOrErr = Sym->getAddress();
|
Expected<uint64_t> SymAddrOrErr = Sym->getAddress();
|
||||||
if (!SymAddrOrErr)
|
if (!SymAddrOrErr)
|
||||||
return createError("error: failed to compute symbol address: ",
|
return createError("error: failed to compute symbol address: ",
|
||||||
@ -943,6 +950,10 @@ static Expected<uint64_t> getSymbolAddress(const object::ObjectFile &Obj,
|
|||||||
if (L && RSec != Obj.section_end())
|
if (L && RSec != Obj.section_end())
|
||||||
if (uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec))
|
if (uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec))
|
||||||
Ret += SectionLoadAddress - RSec->getAddress();
|
Ret += SectionLoadAddress - RSec->getAddress();
|
||||||
|
|
||||||
|
if (CacheIt != Cache.end())
|
||||||
|
CacheIt->second = Ret;
|
||||||
|
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1075,6 +1086,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<SymbolRef, uint64_t> AddrCache;
|
||||||
if (Section.relocation_begin() != Section.relocation_end()) {
|
if (Section.relocation_begin() != Section.relocation_end()) {
|
||||||
uint64_t SectionSize = RelocatedSection->getSize();
|
uint64_t SectionSize = RelocatedSection->getSize();
|
||||||
for (const RelocationRef &Reloc : Section.relocations()) {
|
for (const RelocationRef &Reloc : Section.relocations()) {
|
||||||
@ -1083,7 +1095,8 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
|
|||||||
if (isRelocScattered(Obj, Reloc))
|
if (isRelocScattered(Obj, Reloc))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Expected<uint64_t> SymAddrOrErr = getSymbolAddress(Obj, Reloc, L);
|
Expected<uint64_t> SymAddrOrErr =
|
||||||
|
getSymbolAddress(Obj, Reloc, L, AddrCache);
|
||||||
if (!SymAddrOrErr) {
|
if (!SymAddrOrErr) {
|
||||||
errs() << toString(SymAddrOrErr.takeError()) << '\n';
|
errs() << toString(SymAddrOrErr.takeError()) << '\n';
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user