Skip to content

Commit

Permalink
Binary search to find a relocation.
Browse files Browse the repository at this point in the history
This change makes -gdb-index 40% faster. My test case is self-linking lld.

Differential Revision: https://reviews.llvm.org/D36079

llvm-svn: 309652
  • Loading branch information
rui314 committed Aug 1, 2017
1 parent b9417db commit f974994
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lld/ELF/GdbIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ template <class RelTy>
Optional<RelocAddrEntry>
LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,
ArrayRef<RelTy> Rels) const {
auto I = llvm::find_if(Rels,
[=](const RelTy &Rel) { return Rel.r_offset == Pos; });
if (I == Rels.end())
auto It = std::lower_bound(
Rels.begin(), Rels.end(), Pos,
[](const RelTy &A, uint64_t B) { return A.r_offset < B; });
if (It == Rels.end() || It->r_offset != Pos)
return None;
const RelTy &Rel = *I;
const RelTy &Rel = *It;

const ObjFile<ELFT> *File = Sec.getFile<ELFT>();
uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);
const typename ELFT::Sym &Sym = File->getELFSymbols()[SymIndex];
Expand Down

0 comments on commit f974994

Please sign in to comment.