[llvm] [BOLT] Fix updating DW_AT_stmt_list for DWARF5 TUs. (PR #79374)
Maksim Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 24 15:16:09 PST 2024
================
@@ -1393,41 +1393,60 @@ void DWARFRewriter::updateLineTableOffsets(const MCAsmLayout &Layout) {
// ones.
std::unordered_map<uint64_t, uint64_t> DebugLineOffsetMap;
- auto GetStatementListValue = [](DWARFUnit *Unit) {
- std::optional<DWARFFormValue> StmtList =
- Unit->getUnitDIE().find(dwarf::DW_AT_stmt_list);
+ auto GetStatementListValue =
+ [](const DWARFDie &DIE) -> std::optional<uint64_t> {
+ std::optional<DWARFFormValue> StmtList = DIE.find(dwarf::DW_AT_stmt_list);
+ if (!StmtList)
+ return std::nullopt;
std::optional<uint64_t> Offset = dwarf::toSectionOffset(StmtList);
assert(Offset && "Was not able to retrieve value of DW_AT_stmt_list.");
return *Offset;
};
- for (const std::unique_ptr<DWARFUnit> &CU : BC.DwCtx->compile_units()) {
+ SmallVector<DWARFUnit *, 1> TUs;
+ for (const std::unique_ptr<DWARFUnit> &CU : BC.DwCtx->info_section_units()) {
+ if (CU->isTypeUnit()) {
+ TUs.push_back(CU.get());
+ continue;
+ }
const unsigned CUID = CU->getOffset();
MCSymbol *Label = BC.getDwarfLineTable(CUID).getLabel();
if (!Label)
continue;
- std::optional<AttrInfo> AttrVal =
- findAttributeInfo(CU.get()->getUnitDIE(), dwarf::DW_AT_stmt_list);
- if (!AttrVal)
+ std::optional<uint64_t> StmtOffset =
+ GetStatementListValue(CU.get()->getUnitDIE());
+ if (!StmtOffset)
continue;
const uint64_t LineTableOffset = Layout.getSymbolOffset(*Label);
- DebugLineOffsetMap[GetStatementListValue(CU.get())] = LineTableOffset;
+ DebugLineOffsetMap[*StmtOffset] = LineTableOffset;
assert(DbgInfoSection && ".debug_info section must exist");
LineTablePatchMap[CU.get()] = LineTableOffset;
}
- for (const std::unique_ptr<DWARFUnit> &TU : BC.DwCtx->types_section_units()) {
- DWARFUnit *Unit = TU.get();
- std::optional<AttrInfo> AttrVal =
- findAttributeInfo(TU.get()->getUnitDIE(), dwarf::DW_AT_stmt_list);
- if (!AttrVal)
+ for (const std::unique_ptr<DWARFUnit> &TU : BC.DwCtx->types_section_units())
+ TUs.push_back(TU.get());
+
+ for (DWARFUnit *TU : TUs) {
+ std::optional<uint64_t> StmtOffset =
+ GetStatementListValue(TU->getUnitDIE());
+ if (!StmtOffset)
+ continue;
+ auto Iter = DebugLineOffsetMap.find(*StmtOffset);
+ if (Iter == DebugLineOffsetMap.end()) {
+ // Implementation depends on TU sharing DW_AT_stmt_list with a CU.
+ // Only case that it hasn't been true was for manually modified assembly
+ // file. Adding this warning in case assumption is false.
+ errs()
+ << "BOLT-WARNING: [internal-dwarf-error]: A TU at offset: "
----------------
maksfb wrote:
"... at offset: 0x"
https://github.com/llvm/llvm-project/pull/79374
More information about the llvm-commits
mailing list