[DebugInfo] Fix misleading using of DWARF forms with DIELabel. NFCI.

DIELabel can emit only 32- or 64-bit values, while it was created in
some places with DW_FORM_udata, which implies emitting uleb128.
Nevertheless, these places also expected to emit U32 or U64, but just
used a misleading DWARF form. The patch updates those places to use more
appropriate DWARF forms and restricts DIELabel::SizeOf() to accept only
forms that are actually used in the LLVM codebase.

Differential Revision: https://reviews.llvm.org/D84094
This commit is contained in:
Igor Kudrin 2020-08-03 15:04:08 +07:00
parent 8feff8d14f
commit f98e03a35d
3 changed files with 17 additions and 11 deletions

View File

@ -495,19 +495,25 @@ void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
/// EmitValue - Emit label value.
///
void DIELabel::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
AP->emitLabelReference(
Label, SizeOf(AP, Form),
Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_sec_offset ||
Form == dwarf::DW_FORM_ref_addr || Form == dwarf::DW_FORM_data4);
bool IsSectionRelative = Form != dwarf::DW_FORM_addr;
AP->emitLabelReference(Label, SizeOf(AP, Form), IsSectionRelative);
}
/// SizeOf - Determine size of label value in bytes.
///
unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
if (Form == dwarf::DW_FORM_data4) return 4;
if (Form == dwarf::DW_FORM_sec_offset) return 4;
if (Form == dwarf::DW_FORM_strp) return 4;
return AP->MAI->getCodePointerSize();
switch (Form) {
case dwarf::DW_FORM_data4:
return 4;
case dwarf::DW_FORM_sec_offset:
case dwarf::DW_FORM_strp:
// FIXME: add support for DWARF64
return 4;
case dwarf::DW_FORM_addr:
return AP->MAI->getCodePointerSize();
default:
llvm_unreachable("DIE Value form not supported yet");
}
}
LLVM_DUMP_METHOD

View File

@ -439,8 +439,8 @@ DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP) {
true});
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_WASM_location);
addSInt(*Loc, dwarf::DW_FORM_sdata, FrameBase.Location.WasmLoc.Kind);
addLabel(*Loc, dwarf::DW_FORM_udata, SPSym);
addSInt(*Loc, dwarf::DW_FORM_sdata, TI_GLOBAL_RELOC);
addLabel(*Loc, dwarf::DW_FORM_data4, SPSym);
DD->addArangeLabel(SymbolCU(this, SPSym));
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
addBlock(*SPDie, dwarf::DW_AT_frame_base, Loc);

View File

@ -335,7 +335,7 @@ void DwarfUnit::addOpAddress(DIELoc &Die, const MCSymbol *Sym) {
}
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
addLabel(Die, dwarf::DW_FORM_udata, Sym);
addLabel(Die, dwarf::DW_FORM_addr, Sym);
}
void DwarfUnit::addLabelDelta(DIE &Die, dwarf::Attribute Attribute,