Skip to content

Commit dd7297e

Browse files
committed
DebugInfo: Fix bug in addr+offset exprloc to use DWARFv5 addrx op instead of DWARFv4 GNU extension
1 parent 8a77056 commit dd7297e

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,22 +319,18 @@ void DwarfUnit::addPoolOpAddress(DIEValueList &Die, const MCSymbol *Label) {
319319
const MCSymbol *Base = nullptr;
320320
if (Label->isInSection() && DD->useAddrOffsetExpressions())
321321
Base = DD->getSectionLabel(&Label->getSection());
322-
if (!Base) {
323-
uint32_t Index = DD->getAddressPool().getIndex(Label);
324-
if (DD->getDwarfVersion() >= 5) {
325-
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addrx);
326-
addUInt(Die, dwarf::DW_FORM_addrx, Index);
327-
} else {
328-
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
329-
addUInt(Die, dwarf::DW_FORM_GNU_addr_index, Index);
330-
}
331-
return;
322+
323+
uint32_t Index = DD->getAddressPool().getIndex(Base ? Base : Label);
324+
325+
if (DD->getDwarfVersion() >= 5) {
326+
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addrx);
327+
addUInt(Die, dwarf::DW_FORM_addrx, Index);
328+
} else {
329+
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
330+
addUInt(Die, dwarf::DW_FORM_GNU_addr_index, Index);
332331
}
333332

334-
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
335-
addUInt(Die, dwarf::DW_FORM_GNU_addr_index,
336-
DD->getAddressPool().getIndex(Base));
337-
if (Base != Label) {
333+
if (Base && Base != Label) {
338334
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_const4u);
339335
addLabelDelta(Die, (dwarf::Attribute)0, Label, Base);
340336
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);

llvm/test/DebugInfo/X86/ranges_always.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@
5151
; CHECK: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x0000000000000000 ".text")
5252
; CHECK: DW_AT_high_pc [DW_FORM_data4] (0x00000010)
5353
; CHECK: DW_TAG_inlined_subroutine
54-
; EXPR: DW_AT_low_pc [DW_FORM_exprloc] (DW_OP_GNU_addr_index 0x0, DW_OP_const4u 0x9, DW_OP_plus)
54+
; EXPR: DW_AT_low_pc [DW_FORM_exprloc] (DW_OP_addrx 0x0, DW_OP_const4u 0x9, DW_OP_plus)
5555
; EXPR: DW_AT_high_pc [DW_FORM_data4] (0x00000005)
5656
; RNG: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = [[INL_RANGE:.*]]
5757
; CHECK: DW_TAG_call_site
5858
; RNG: DW_AT_call_return_pc [DW_FORM_addrx] (indexed (00000001) address = 0x0000000000000009 ".text")
59-
; EXPR: DW_AT_call_return_pc [DW_FORM_exprloc] (DW_OP_GNU_addr_index 0x0, DW_OP_const4u 0x9, DW_OP_plus)
59+
; EXPR: DW_AT_call_return_pc [DW_FORM_exprloc] (DW_OP_addrx 0x0, DW_OP_const4u 0x9, DW_OP_plus)
6060
; CHECK: DW_TAG_call_site
6161
; RNG: DW_AT_call_return_pc [DW_FORM_addrx] (indexed (00000002) address = 0x000000000000000e ".text")
62-
; EXPR: DW_AT_call_return_pc [DW_FORM_exprloc] (DW_OP_GNU_addr_index 0x0, DW_OP_const4u 0xe, DW_OP_plus)
62+
; EXPR: DW_AT_call_return_pc [DW_FORM_exprloc] (DW_OP_addrx 0x0, DW_OP_const4u 0xe, DW_OP_plus)
6363
; CHECK: NULL
6464
; CHECK: DW_TAG_subprogram
6565
; CHECK: DW_AT_name {{.*}} "f1"
6666
; CHECK: DW_TAG_subprogram
67-
; EXPR: DW_AT_low_pc [DW_FORM_exprloc] (DW_OP_GNU_addr_index 0x0, DW_OP_const4u 0x20, DW_OP_plus)
67+
; EXPR: DW_AT_low_pc [DW_FORM_exprloc] (DW_OP_addrx 0x0, DW_OP_const4u 0x20, DW_OP_plus)
6868
; EXPR: DW_AT_high_pc [DW_FORM_data4] (0x00000006)
6969
; RNG: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x1) rangelist = [[F5_RANGE:.*]]
7070
; CHECK: DW_TAG_subprogram

0 commit comments

Comments
 (0)