Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -1704,29 +1704,33 @@ return Ret; } -static InputSectionBase *findSection(ArrayRef Arr, - uint64_t Offset) { - for (InputSectionBase *S : Arr) - if (S && S != &InputSection::Discarded) - if (Offset >= S->getOffsetInFile() && - Offset < S->getOffsetInFile() + S->getSize()) - return S; - return nullptr; -} - static std::vector readAddressArea(DWARFContext &Dwarf, InputSection *Sec, size_t CurrentCU) { std::vector Ret; + std::vector V = Sec->File->getSections(); + V.erase(llvm::remove_if(V, + [](InputSectionBase *IS) { + return !IS || IS == &InputSection::Discarded || + !IS->getSize(); + }), + V.end()); + for (std::unique_ptr &CU : Dwarf.compile_units()) { DWARFAddressRangesVector Ranges; CU->collectAddressRanges(Ranges); - ArrayRef Sections = Sec->File->getSections(); - for (std::pair &R : Ranges) - if (InputSectionBase *S = findSection(Sections, R.first)) - Ret.push_back({S, R.first - S->getOffsetInFile(), - R.second - S->getOffsetInFile(), CurrentCU}); + for (std::pair &R : Ranges) { + auto I = std::lower_bound(V.begin(), V.end(), R.first, + [](InputSectionBase *IS, uint64_t Offset) { + return IS->getOffsetInFile() < Offset; + }); + if (I == V.end()) + continue; + InputSectionBase *IS = *I; + Ret.push_back({IS, R.first - IS->getOffsetInFile(), + R.second - IS->getOffsetInFile(), CurrentCU}); + } ++CurrentCU; } return Ret;