[Symbolize] Uniquify sorted vector<pair<SymbolDesc, StringRef>>

llvm-svn: 357833
This commit is contained in:
Fangrui Song 2019-04-06 02:18:56 +00:00
parent 9f4707c6ca
commit 78d0d7ff6b
2 changed files with 16 additions and 10 deletions

View File

@ -81,10 +81,22 @@ SymbolizableObjectFile::create(object::ObjectFile *Obj,
std::vector<std::pair<SymbolDesc, StringRef>> &Fs = res->Functions,
&Os = res->Objects;
llvm::sort(Fs);
Fs.erase(std::unique(Fs.begin(), Fs.end()), Fs.end());
llvm::sort(Os);
Os.erase(std::unique(Os.begin(), Os.end()), Os.end());
auto Uniquify = [](std::vector<std::pair<SymbolDesc, StringRef>> &S) {
// Sort by (Addr,Size,Name). If several SymbolDescs share the same Addr,
// pick the one with the largest Size. This helps us avoid symbols with no
// size information (Size=0).
llvm::sort(S);
auto I = S.begin(), E = S.end(), J = S.begin();
while (I != E) {
auto OI = I;
while (++I != E && OI->first.Addr == I->first.Addr) {
}
*J++ = I[-1];
}
S.erase(J, S.end());
};
Uniquify(Fs);
Uniquify(Os);
return std::move(res);
}
@ -205,9 +217,6 @@ bool SymbolizableObjectFile::getNameFromSymbolTable(SymbolRef::Type Type,
uint64_t &Size) const {
const auto &Symbols = Type == SymbolRef::ST_Function ? Functions : Objects;
std::pair<SymbolDesc, StringRef> SD{{Address, UINT64_C(-1)}, StringRef()};
// SymbolDescs are sorted by (Addr,Size), if several SymbolDescs share the
// same Addr, pick the one with the largest Size. This helps us avoid symbols
// with no size information (Size=0).
auto SymbolIterator = llvm::upper_bound(Symbols, SD);
if (SymbolIterator == Symbols.begin())
return false;

View File

@ -75,9 +75,6 @@ private:
// the following symbol.
uint64_t Size;
bool operator==(const SymbolDesc &RHS) const {
return Addr == RHS.Addr && Size == RHS.Size;
}
bool operator<(const SymbolDesc &RHS) const {
return Addr != RHS.Addr ? Addr < RHS.Addr : Size < RHS.Size;
}