Skip to content

Commit

Permalink
[ELF] Optimize -Map. NFC
Browse files Browse the repository at this point in the history
getVA is slow. Avoid calling it in the llvm::sort comparator.
  • Loading branch information
MaskRay committed Jan 27, 2022
1 parent 14b7785 commit afeb4a6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lld/ELF/MapFile.cpp
Expand Up @@ -37,7 +37,8 @@ using namespace llvm::object;
using namespace lld;
using namespace lld::elf;

using SymbolMapTy = DenseMap<const SectionBase *, SmallVector<Defined *, 4>>;
using SymbolMapTy = DenseMap<const SectionBase *,
SmallVector<std::pair<Defined *, uint64_t>, 0>>;

static constexpr char indent8[] = " "; // 8 spaces
static constexpr char indent16[] = " "; // 16 spaces
Expand Down Expand Up @@ -67,7 +68,7 @@ static std::vector<Defined *> getSymbols() {
static SymbolMapTy getSectionSyms(ArrayRef<Defined *> syms) {
SymbolMapTy ret;
for (Defined *dr : syms)
ret[dr->section].push_back(dr);
ret[dr->section].emplace_back(dr, dr->getVA());

// Sort symbols by address. We want to print out symbols in the
// order in the output file rather than the order they appeared
Expand All @@ -76,12 +77,11 @@ static SymbolMapTy getSectionSyms(ArrayRef<Defined *> syms) {
for (auto &it : ret) {
// Deduplicate symbols which need a canonical PLT entry/copy relocation.
set.clear();
llvm::erase_if(it.second,
[&](Defined *sym) { return !set.insert(sym).second; });

llvm::stable_sort(it.second, [](Defined *a, Defined *b) {
return a->getVA() < b->getVA();
llvm::erase_if(it.second, [&](std::pair<Defined *, uint64_t> a) {
return !set.insert(a.first).second;
});

llvm::stable_sort(it.second, llvm::less_second());
}
return ret;
}
Expand Down Expand Up @@ -184,7 +184,7 @@ static void writeMapFile(raw_fd_ostream &os) {
writeHeader(os, isec->getVA(), osec->getLMA() + isec->outSecOff,
isec->getSize(), isec->alignment);
os << indent8 << toString(isec) << '\n';
for (Symbol *sym : sectionSyms[isec])
for (Symbol *sym : llvm::make_first_range(sectionSyms[isec]))
os << symStr[sym] << '\n';
}
continue;
Expand Down

0 comments on commit afeb4a6

Please sign in to comment.