diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp --- a/bolt/lib/Rewrite/DWARFRewriter.cpp +++ b/bolt/lib/Rewrite/DWARFRewriter.cpp @@ -839,18 +839,20 @@ return; } - // Convert DW_AT_low_pc into DW_AT_GNU_ranges_base. - if (!LowPCAttrInfo) { - errs() << "BOLT-ERROR: skeleton CU at 0x" - << Twine::utohexstr(DIE.getOffset()) - << " does not have DW_AT_GNU_ranges_base or DW_AT_low_pc to" - " convert to update ranges base\n"; + if (DIE.getOffset() != DIE.getDwarfUnit()->getUnitDIE().getOffset()) return; - } - AbbrevWriter.addAttribute(*DIE.getDwarfUnit(), AbbreviationDecl, - dwarf::DW_AT_GNU_ranges_base, - dwarf::DW_FORM_sec_offset); + // If we are at this point we are in the CU/Skeleton CU, and + // DW_AT_GNU_ranges_base or DW_AT_rnglists_base doesn't exist. + if (DIE.getDwarfUnit()->getVersion() >= 5) { + AbbrevWriter.addAttribute(*DIE.getDwarfUnit(), AbbreviationDecl, + dwarf::DW_AT_rnglists_base, + dwarf::DW_FORM_sec_offset); + } else { + AbbrevWriter.addAttribute(*DIE.getDwarfUnit(), AbbreviationDecl, + dwarf::DW_AT_GNU_ranges_base, + dwarf::DW_FORM_sec_offset); + } reinterpret_cast(DebugInfoPatcher) .insertNewEntry(DIE, *RangesBase); diff --git a/bolt/test/X86/dwarf5-rangeoffset-to-rangeindex.s b/bolt/test/X86/dwarf5-rangeoffset-to-rangeindex.s --- a/bolt/test/X86/dwarf5-rangeoffset-to-rangeindex.s +++ b/bolt/test/X86/dwarf5-rangeoffset-to-rangeindex.s @@ -21,6 +21,11 @@ # POSTCHECK-SAME: (indexed (0x0) rangelist = 0x00000018 # POSTCHECK-NEXT: [0x[[#ADDR]], 0x[[#ADDR + 11]] # POSTCHECK-NEXT: [0x[[#ADDR1]], 0x[[#ADDR1 + 11]] +# POSTCHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] +# POSTCHECK-NEXT: DW_AT_stmt_list [DW_FORM_sec_offset] +# POSTCHECK-NEXT: DW_AT_rnglists_base [DW_FORM_sec_offset] (0x0000000c) +# POSTCHECK-NEXT: DW_AT_addr_base [DW_FORM_sec_offset] (0x00000008) + # int foo() { # return 3;