From dd7297e1bffeaea533a2353489ead3b388ceed14 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 27 Jan 2021 18:39:07 -0800 Subject: [PATCH] DebugInfo: Fix bug in addr+offset exprloc to use DWARFv5 addrx op instead of DWARFv4 GNU extension --- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 24 ++++++++++-------------- llvm/test/DebugInfo/X86/ranges_always.ll | 8 ++++---- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 6267c3e..bc45a78 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -319,22 +319,18 @@ void DwarfUnit::addPoolOpAddress(DIEValueList &Die, const MCSymbol *Label) { const MCSymbol *Base = nullptr; if (Label->isInSection() && DD->useAddrOffsetExpressions()) Base = DD->getSectionLabel(&Label->getSection()); - if (!Base) { - uint32_t Index = DD->getAddressPool().getIndex(Label); - if (DD->getDwarfVersion() >= 5) { - addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addrx); - addUInt(Die, dwarf::DW_FORM_addrx, Index); - } else { - addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index); - addUInt(Die, dwarf::DW_FORM_GNU_addr_index, Index); - } - return; + + uint32_t Index = DD->getAddressPool().getIndex(Base ? Base : Label); + + if (DD->getDwarfVersion() >= 5) { + addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addrx); + addUInt(Die, dwarf::DW_FORM_addrx, Index); + } else { + addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index); + addUInt(Die, dwarf::DW_FORM_GNU_addr_index, Index); } - addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index); - addUInt(Die, dwarf::DW_FORM_GNU_addr_index, - DD->getAddressPool().getIndex(Base)); - if (Base != Label) { + if (Base && Base != Label) { addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_const4u); addLabelDelta(Die, (dwarf::Attribute)0, Label, Base); addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_plus); diff --git a/llvm/test/DebugInfo/X86/ranges_always.ll b/llvm/test/DebugInfo/X86/ranges_always.ll index 9d1498c..4a60e9d 100644 --- a/llvm/test/DebugInfo/X86/ranges_always.ll +++ b/llvm/test/DebugInfo/X86/ranges_always.ll @@ -51,20 +51,20 @@ ; CHECK: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x0000000000000000 ".text") ; CHECK: DW_AT_high_pc [DW_FORM_data4] (0x00000010) ; CHECK: DW_TAG_inlined_subroutine -; EXPR: DW_AT_low_pc [DW_FORM_exprloc] (DW_OP_GNU_addr_index 0x0, DW_OP_const4u 0x9, DW_OP_plus) +; EXPR: DW_AT_low_pc [DW_FORM_exprloc] (DW_OP_addrx 0x0, DW_OP_const4u 0x9, DW_OP_plus) ; EXPR: DW_AT_high_pc [DW_FORM_data4] (0x00000005) ; RNG: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = [[INL_RANGE:.*]] ; CHECK: DW_TAG_call_site ; RNG: DW_AT_call_return_pc [DW_FORM_addrx] (indexed (00000001) address = 0x0000000000000009 ".text") -; EXPR: DW_AT_call_return_pc [DW_FORM_exprloc] (DW_OP_GNU_addr_index 0x0, DW_OP_const4u 0x9, DW_OP_plus) +; EXPR: DW_AT_call_return_pc [DW_FORM_exprloc] (DW_OP_addrx 0x0, DW_OP_const4u 0x9, DW_OP_plus) ; CHECK: DW_TAG_call_site ; RNG: DW_AT_call_return_pc [DW_FORM_addrx] (indexed (00000002) address = 0x000000000000000e ".text") -; EXPR: DW_AT_call_return_pc [DW_FORM_exprloc] (DW_OP_GNU_addr_index 0x0, DW_OP_const4u 0xe, DW_OP_plus) +; EXPR: DW_AT_call_return_pc [DW_FORM_exprloc] (DW_OP_addrx 0x0, DW_OP_const4u 0xe, DW_OP_plus) ; CHECK: NULL ; CHECK: DW_TAG_subprogram ; CHECK: DW_AT_name {{.*}} "f1" ; CHECK: DW_TAG_subprogram -; EXPR: DW_AT_low_pc [DW_FORM_exprloc] (DW_OP_GNU_addr_index 0x0, DW_OP_const4u 0x20, DW_OP_plus) +; EXPR: DW_AT_low_pc [DW_FORM_exprloc] (DW_OP_addrx 0x0, DW_OP_const4u 0x20, DW_OP_plus) ; EXPR: DW_AT_high_pc [DW_FORM_data4] (0x00000006) ; RNG: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x1) rangelist = [[F5_RANGE:.*]] ; CHECK: DW_TAG_subprogram -- 2.7.4