Index: include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h +++ include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h @@ -85,7 +85,8 @@ /// getAbsoluteRanges - Returns absolute address ranges defined by this range /// list. Has to be passed base address of the compile unit referencing this /// range list. - DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const; + DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress, + uint64_t SectionIndex) const; }; } // end namespace llvm Index: include/llvm/DebugInfo/DWARF/DWARFUnit.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -136,6 +136,7 @@ const DWARFAbbreviationDeclarationSet *Abbrevs; uint8_t UnitType; uint64_t BaseAddr; + uint64_t BaseAddrSectionIndex; /// The compile unit debug information entry items. std::vector DieArray; @@ -260,9 +261,11 @@ } uint64_t getBaseAddress() const { return BaseAddr; } + uint64_t getBaseAddressSectionIndex() const { return BaseAddrSectionIndex; } - void setBaseAddress(uint64_t base_addr) { - BaseAddr = base_addr; + void setBaseAddress(uint64_t BaseAddr, uint64_t SectionIndex) { + this->BaseAddr = BaseAddr; + this->BaseAddrSectionIndex = SectionIndex; } DWARFDie getUnitDIE(bool ExtractUnitDIEOnly = true) { Index: lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp +++ lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp @@ -62,14 +62,17 @@ } DWARFAddressRangesVector -DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress) const { +DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress, + uint64_t SectionIndex) const { DWARFAddressRangesVector Res; for (const RangeListEntry &RLE : Entries) { if (RLE.isBaseAddressSelectionEntry(AddressSize)) { BaseAddress = RLE.EndAddress; + SectionIndex = RLE.SectionIndex; } else { Res.push_back({BaseAddress + RLE.StartAddress, - BaseAddress + RLE.EndAddress, RLE.SectionIndex}); + BaseAddress + RLE.EndAddress, + BaseAddress ? SectionIndex : RLE.SectionIndex}); } } return Res; Index: lib/DebugInfo/DWARF/DWARFDie.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFDie.cpp +++ lib/DebugInfo/DWARF/DWARFDie.cpp @@ -243,7 +243,8 @@ if (RangesOffset) { DWARFDebugRangeList RangeList; if (U->extractRangeList(*RangesOffset, RangeList)) - return RangeList.getAbsoluteRanges(U->getBaseAddress()); + return RangeList.getAbsoluteRanges(U->getBaseAddress(), + U->getBaseAddressSectionIndex()); } return DWARFAddressRangesVector(); } Index: lib/DebugInfo/DWARF/DWARFUnit.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFUnit.cpp +++ lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -242,9 +242,9 @@ // If CU DIE was just parsed, copy several attribute values from it. if (!HasCUDie) { DWARFDie UnitDie = getUnitDIE(); - auto BaseAddr = toAddress(UnitDie.find({DW_AT_low_pc, DW_AT_entry_pc})); - if (BaseAddr) - setBaseAddress(*BaseAddr); + const auto &LowPCDie = UnitDie.find({DW_AT_low_pc, DW_AT_entry_pc}); + if (auto BaseAddr = toAddress(LowPCDie)) + setBaseAddress(*BaseAddr, LowPCDie->getSectionIndex()); AddrOffsetSectionBase = toSectionOffset(UnitDie.find(DW_AT_GNU_addr_base), 0); RangeSectionBase = toSectionOffset(UnitDie.find(DW_AT_rnglists_base), 0);