diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -355,6 +355,15 @@ return AddrOffsetSectionBase; } + /// Returns offset to the indexed address value inside .debug_addr section. + std::optional getIndexedAddressOffset(uint64_t Index) { + if (std::optional AddrOffsetSectionBase = + getAddrOffsetSectionBase()) + return *AddrOffsetSectionBase + Index * getAddressByteSize(); + + return std::nullopt; + } + /// Recursively update address to Die map. void updateAddressDieMap(DWARFDie Die); diff --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp --- a/llvm/lib/DWARFLinker/DWARFLinker.cpp +++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp @@ -489,16 +489,14 @@ } break; case dwarf::DW_OP_constx: case dwarf::DW_OP_addrx: { - if (std::optional AddrOffsetSectionBase = - DIE.getDwarfUnit()->getAddrOffsetSectionBase()) { - uint64_t StartOffset = *AddrOffsetSectionBase + Op.getRawOperand(0); - uint64_t EndOffset = - StartOffset + DIE.getDwarfUnit()->getAddressByteSize(); - + if (std::optional AddressOffset = + DIE.getDwarfUnit()->getIndexedAddressOffset( + Op.getRawOperand(0))) { // Check relocation for the address. if (std::optional RelocAdjustment = - RelocMgr.getExprOpAddressRelocAdjustment(*U, Op, StartOffset, - EndOffset)) + RelocMgr.getExprOpAddressRelocAdjustment( + *U, Op, *AddressOffset, + *AddressOffset + DIE.getDwarfUnit()->getAddressByteSize())) return *RelocAdjustment; } } break; diff --git a/llvm/test/tools/dsymutil/Inputs/dwarf5-dw-op-addrx.o b/llvm/test/tools/dsymutil/Inputs/dwarf5-dw-op-addrx.o index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ AddrValue = DIE.find(dwarf::DW_AT_low_pc); - if (std::optional AddrOffsetSectionBase = - DIE.getDwarfUnit()->getAddrOffsetSectionBase()) { - // Addrx is a index into the debug_addr section, not an offset, so we need - // to multiply by byte size. - const uint64_t AddrSize = DIE.getDwarfUnit()->getAddressByteSize(); - const uint64_t StartOffset = - *AddrOffsetSectionBase + (AddrValue->getRawUValue() * AddrSize); - const uint64_t EndOffset = StartOffset + AddrSize; - return hasValidRelocationAt(ValidDebugAddrRelocs, StartOffset, EndOffset); - } + if (std::optional AddressOffset = + DIE.getDwarfUnit()->getIndexedAddressOffset( + AddrValue->getRawUValue())) + return hasValidRelocationAt(ValidDebugAddrRelocs, *AddressOffset, + *AddressOffset + + DIE.getDwarfUnit()->getAddressByteSize()); Linker.reportWarning("no base offset for address table", SrcFileName); return std::nullopt;