[llvm] f6c1796 - [DWARFLinker] add DWARFUnit::getIndexedAddressOffset().
Alexey Lapshin via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 20 04:06:49 PDT 2023
Author: Alexey Lapshin
Date: 2023-06-20T13:03:12+02:00
New Revision: f6c1796b446f4c6cbff082fe3dd3f982171a8597
URL: https://github.com/llvm/llvm-project/commit/f6c1796b446f4c6cbff082fe3dd3f982171a8597
DIFF: https://github.com/llvm/llvm-project/commit/f6c1796b446f4c6cbff082fe3dd3f982171a8597.diff
LOG: [DWARFLinker] add DWARFUnit::getIndexedAddressOffset().
This patch is a followup for D153162. It cures one more place
where indexed address was incorrectly read. It also moves handling
of indexed address into DWARFUnit.
Differential Revision: https://reviews.llvm.org/D153297
Added:
Modified:
llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
llvm/lib/DWARFLinker/DWARFLinker.cpp
llvm/test/tools/dsymutil/Inputs/dwarf5-dw-op-addrx.o
llvm/test/tools/dsymutil/X86/dwarf5-dw-op-addrx.test
llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
index 8d6310a7f2745..b42c951598d6f 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
@@ -355,6 +355,15 @@ class DWARFUnit {
return AddrOffsetSectionBase;
}
+ /// Returns offset to the indexed address value inside .debug_addr section.
+ std::optional<uint64_t> getIndexedAddressOffset(uint64_t Index) {
+ if (std::optional<uint64_t> 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
index 18b81468fc906..0c84bf161aa15 100644
--- a/llvm/lib/DWARFLinker/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp
@@ -489,16 +489,14 @@ DWARFLinker::getVariableRelocAdjustment(AddressesMap &RelocMgr,
} break;
case dwarf::DW_OP_constx:
case dwarf::DW_OP_addrx: {
- if (std::optional<uint64_t> AddrOffsetSectionBase =
- DIE.getDwarfUnit()->getAddrOffsetSectionBase()) {
- uint64_t StartOffset = *AddrOffsetSectionBase + Op.getRawOperand(0);
- uint64_t EndOffset =
- StartOffset + DIE.getDwarfUnit()->getAddressByteSize();
-
+ if (std::optional<uint64_t> AddressOffset =
+ DIE.getDwarfUnit()->getIndexedAddressOffset(
+ Op.getRawOperand(0))) {
// Check relocation for the address.
if (std::optional<int64_t> 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 fb2a6d3242ec5..62d1b03eb20e5 100644
Binary files a/llvm/test/tools/dsymutil/Inputs/dwarf5-dw-op-addrx.o and b/llvm/test/tools/dsymutil/Inputs/dwarf5-dw-op-addrx.o
diff er
diff --git a/llvm/test/tools/dsymutil/X86/dwarf5-dw-op-addrx.test b/llvm/test/tools/dsymutil/X86/dwarf5-dw-op-addrx.test
index 8951470f4c5b6..08a12022bfe53 100644
--- a/llvm/test/tools/dsymutil/X86/dwarf5-dw-op-addrx.test
+++ b/llvm/test/tools/dsymutil/X86/dwarf5-dw-op-addrx.test
@@ -4,6 +4,17 @@
## cat dwarf5-dw-op-addrx.c
+## char arr[40];
+## char arr2[40];
+## char arr3[40];
+## char arr4[40];
+## char arr5[40];
+## char arr6[40];
+## char arr7[40];
+## char arr8[40];
+## char arr9[40];
+## int main() { return 0;}
+
## $ clang -gdwarf-5 dwarf5-dw-op-addrx.c -c -O2 -o dwarf5-dw-op-addrx.o
#RUN: dsymutil -oso-prepend-path %p/../Inputs -y %s -o %t.dSYM
@@ -21,19 +32,75 @@
#DWARF-CHECK: DW_AT_low_pc {{.*}}0x0000000100000fb0
#DWARF-CHECK: DW_TAG_variable
#DWARF-CHECK: DW_AT_name {{.*}}"arr"
+#DWARF-CHECK: DW_AT_location {{.*}}(DW_OP_addr 0x100001000)
+#DWARF-CHECK: DW_TAG_variable
+#DWARF-CHECK: DW_AT_name {{.*}}"arr2"
#DWARF-CHECK: DW_AT_location {{.*}}(DW_OP_addr 0x100002000)
+#DWARF-CHECK: DW_TAG_variable
+#DWARF-CHECK: DW_AT_name {{.*}}"arr3"
+#DWARF-CHECK: DW_AT_location {{.*}}(DW_OP_addr 0x100003000)
+#DWARF-CHECK: DW_TAG_variable
+#DWARF-CHECK: DW_AT_name {{.*}}"arr4"
+#DWARF-CHECK: DW_AT_location {{.*}}(DW_OP_addr 0x100004000)
+#DWARF-CHECK: DW_TAG_variable
+#DWARF-CHECK: DW_AT_name {{.*}}"arr5"
+#DWARF-CHECK: DW_AT_location {{.*}}(DW_OP_addr 0x100005000)
+#DWARF-CHECK: DW_TAG_variable
+#DWARF-CHECK: DW_AT_name {{.*}}"arr6"
+#DWARF-CHECK: DW_AT_location {{.*}}(DW_OP_addr 0x100006000)
+#DWARF-CHECK: DW_TAG_variable
+#DWARF-CHECK: DW_AT_name {{.*}}"arr7"
+#DWARF-CHECK: DW_AT_location {{.*}}(DW_OP_addr 0x100007000)
+#DWARF-CHECK: DW_TAG_variable
+#DWARF-CHECK: DW_AT_name {{.*}}"arr8"
+#DWARF-CHECK: DW_AT_location {{.*}}(DW_OP_addr 0x100008000)
+#DWARF-CHECK: DW_TAG_variable
+#DWARF-CHECK: DW_AT_name {{.*}}"arr9"
+#DWARF-CHECK: DW_AT_location {{.*}}(DW_OP_addr 0x100009000)
#DWARF-CHECK-NOT: .debug_addr
#UPD-DWARF-CHECK: DW_TAG_compile_unit
#UPD-DWARF-CHECK: DW_AT_name {{.*}}"dwarf5-dw-op-addrx.c"
-#UPD-DWARF-CHECK: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000001) address = 0x0000000000000000)
+#UPD-DWARF-CHECK: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000009) address = 0x0000000000000000)
#UPD-DWARF-CHECK: DW_AT_high_pc [DW_FORM_data4] (0x00000008)
#UPD-DWARF-CHECK: DW_AT_addr_base [DW_FORM_sec_offset] (0x00000008)
#UPD-DWARF-CHECK: DW_TAG_variable
#UPD-DWARF-CHECK: DW_AT_name {{.*}}"arr"
#UPD-DWARF-CHECK: DW_AT_location [DW_FORM_exprloc] (DW_OP_addrx 0x0)
+#UPD-DWARF-CHECK: DW_TAG_variable
+#UPD-DWARF-CHECK: DW_AT_name {{.*}}"arr2"
+#UPD-DWARF-CHECK: DW_AT_location [DW_FORM_exprloc] (DW_OP_addrx 0x1)
+#UPD-DWARF-CHECK: DW_TAG_variable
+#UPD-DWARF-CHECK: DW_AT_name {{.*}}"arr3"
+#UPD-DWARF-CHECK: DW_AT_location [DW_FORM_exprloc] (DW_OP_addrx 0x2)
+#UPD-DWARF-CHECK: DW_TAG_variable
+#UPD-DWARF-CHECK: DW_AT_name {{.*}}"arr4"
+#UPD-DWARF-CHECK: DW_AT_location [DW_FORM_exprloc] (DW_OP_addrx 0x3)
+#UPD-DWARF-CHECK: DW_TAG_variable
+#UPD-DWARF-CHECK: DW_AT_name {{.*}}"arr5"
+#UPD-DWARF-CHECK: DW_AT_location [DW_FORM_exprloc] (DW_OP_addrx 0x4)
+#UPD-DWARF-CHECK: DW_TAG_variable
+#UPD-DWARF-CHECK: DW_AT_name {{.*}}"arr6"
+#UPD-DWARF-CHECK: DW_AT_location [DW_FORM_exprloc] (DW_OP_addrx 0x5)
+#UPD-DWARF-CHECK: DW_TAG_variable
+#UPD-DWARF-CHECK: DW_AT_name {{.*}}"arr7"
+#UPD-DWARF-CHECK: DW_AT_location [DW_FORM_exprloc] (DW_OP_addrx 0x6)
+#UPD-DWARF-CHECK: DW_TAG_variable
+#UPD-DWARF-CHECK: DW_AT_name {{.*}}"arr8"
+#UPD-DWARF-CHECK: DW_AT_location [DW_FORM_exprloc] (DW_OP_addrx 0x7)
+#UPD-DWARF-CHECK: DW_TAG_variable
+#UPD-DWARF-CHECK: DW_AT_name {{.*}}"arr9"
+#UPD-DWARF-CHECK: DW_AT_location [DW_FORM_exprloc] (DW_OP_addrx 0x8)
#UPD-DWARF-CHECK: .debug_addr contents:
-#UPD-DWARF-CHECK: 0x00000000: Address table header: length = 0x00000014, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00
+#UPD-DWARF-CHECK: 0x00000000: Address table header: length = 0x00000054, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00
+#UPD-DWARF-CHECK: 0x0000000000000000
+#UPD-DWARF-CHECK: 0x0000000000000000
+#UPD-DWARF-CHECK: 0x0000000000000000
+#UPD-DWARF-CHECK: 0x0000000000000000
+#UPD-DWARF-CHECK: 0x0000000000000000
+#UPD-DWARF-CHECK: 0x0000000000000000
+#UPD-DWARF-CHECK: 0x0000000000000000
+#UPD-DWARF-CHECK: 0x0000000000000000
#UPD-DWARF-CHECK: 0x0000000000000000
#UPD-DWARF-CHECK: 0x0000000000000000
@@ -44,4 +111,12 @@ objects:
timestamp: 1676048242
symbols:
- { sym: _main, objAddr: 0x0000000000000000, binAddr: 0x0000000100000FB0, size: 0x00000008 }
- - { sym: _arr, binAddr: 0x0000000100002000, size: 0x00000000 }
+ - { sym: _arr, binAddr: 0x0000000100001000, size: 0x00000008 }
+ - { sym: _arr2, binAddr: 0x0000000100002000, size: 0x00000008 }
+ - { sym: _arr3, binAddr: 0x0000000100003000, size: 0x00000008 }
+ - { sym: _arr4, binAddr: 0x0000000100004000, size: 0x00000008 }
+ - { sym: _arr5, binAddr: 0x0000000100005000, size: 0x00000008 }
+ - { sym: _arr6, binAddr: 0x0000000100006000, size: 0x00000008 }
+ - { sym: _arr7, binAddr: 0x0000000100007000, size: 0x00000008 }
+ - { sym: _arr8, binAddr: 0x0000000100008000, size: 0x00000008 }
+ - { sym: _arr9, binAddr: 0x0000000100009000, size: 0x00000008 }
diff --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
index 09a69a35a23ca..4b281d5f19801 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
@@ -1079,16 +1079,12 @@ std::optional<int64_t> DwarfLinkerForBinary::AddressManager<
case dwarf::DW_FORM_addrx3:
case dwarf::DW_FORM_addrx4: {
std::optional<DWARFFormValue> AddrValue = DIE.find(dwarf::DW_AT_low_pc);
- if (std::optional<uint64_t> 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<uint64_t> 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;
More information about the llvm-commits
mailing list