Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -1697,29 +1697,39 @@ 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) { + typedef std::pair Range; + std::vector Ret; for (std::unique_ptr &CU : Dwarf.compile_units()) { DWARFAddressRangesVector Ranges; CU->collectAddressRanges(Ranges); + std::sort(Ranges.begin(), Ranges.end(), + [](Range &A, Range &B) { return A.first < B.first; }); + ArrayRef Sections = Sec->File->getSections(); - for (std::pair &R : Ranges) - if (InputSectionBase *S = findSection(Sections, R.first)) + auto It = Ranges.begin(); + for (InputSectionBase *S : Sections) { + if (!S || S == &InputSection::Discarded) + continue; + + while (It != Ranges.end()) { + const Range &R = *It; + bool Inside = R.first >= S->getOffsetInFile() && + R.first < S->getOffsetInFile() + S->getSize(); + if (!Inside) + break; + Ret.push_back({S, R.first - S->getOffsetInFile(), R.second - S->getOffsetInFile(), CurrentCU}); + ++It; + } + if (It == Ranges.end()) + break; + } ++CurrentCU; } return Ret;