Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -1704,13 +1704,34 @@ return Ret; } -static InputSectionBase *findSection(ArrayRef Arr, +// Finds input section Offset belongs to in [Begin, End] interval which must be +// sorted by offset in file. Algorithm used is binary search. We can not simply use +// std::lower_bound instead because have input sections that are discarded +// or even just null. +static InputSectionBase *findSection(InputSectionBase *const *Begin, + InputSectionBase *const *End, uint64_t Offset) { - for (InputSectionBase *S : Arr) - if (S && S != &InputSection::Discarded) - if (Offset >= S->getOffsetInFile() && - Offset < S->getOffsetInFile() + S->getSize()) - return S; + while (!*Begin || *Begin == &InputSection::Discarded) + if (++Begin > End) + return nullptr; + + while (!*End || *End == &InputSection::Discarded) + if (--End < Begin) + return nullptr; + + if ((*Begin)->getOffsetInFile() > Offset || + Offset > (*End)->getOffsetInFile() + (*End)->getSize()) + return nullptr; + + if (Begin == End) + return *Begin; + + size_t N = (End - Begin) / 2; + InputSectionBase *const *Mid = Begin + N; + if (InputSectionBase *Ret = findSection(Mid + 1, End, Offset)) + return Ret; + if (InputSectionBase *Ret = findSection(Begin, Mid, Offset)) + return Ret; return nullptr; } @@ -1718,15 +1739,18 @@ readAddressArea(DWARFContext &Dwarf, InputSection *Sec, size_t CurrentCU) { std::vector Ret; + ArrayRef Arr = Sec->File->getSections(); 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) { + InputSectionBase *IS = + findSection(Arr.begin(), Arr.begin() + Arr.size() - 1, R.first); + if (IS) + Ret.push_back({IS, R.first - IS->getOffsetInFile(), + R.second - IS->getOffsetInFile(), CurrentCU}); + } ++CurrentCU; } return Ret; @@ -1750,8 +1774,12 @@ class ObjInfoTy : public llvm::LoadedObjectInfo { uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const override { auto &S = static_cast(Sec); + + //ELFObjectFile< S.getObject() + if (S.getFlags() & ELF::SHF_ALLOC) return S.getOffset(); + //assert(false); return 0; }