[PATCH] D26879: Make a DwarfGen class that can generate DWARF for unittests and add units tests to test DWARF API.

Greg Clayton via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 22 09:44:03 PST 2016


clayborg added a comment.

In https://reviews.llvm.org/D26879#602736, @dblaikie wrote:

> I'm curious/would like to better understand what motivated the changes to to existing code (in lib/CodeGen/AsmPrinter, DwarfLinker, etc) - given that llvm-dsymutil was already using these APIs to generate DWARF without needing these changes? (what's different about the unit test scenario compared to the llvm-dsymutil scenario)


llvm-dsymutil just avoids using the AsmPrinter for anything that would cause it to assert and die due to lack of having DwarfDebug. In the function DwarfLinker::DIECloner::cloneDieReferenceAttribute() we see:

  if (AttrSpec.Form == dwarf::DW_FORM_ref_addr ||
      (Unit.hasODR() && isODRAttribute(AttrSpec.Attr))) {
    // We cannot currently rely on a DIEEntry to emit ref_addr
    // references, because the implementation calls back to DwarfDebug
    // to find the unit offset. (We don't have a DwarfDebug)
    // FIXME: we should be able to design DIEEntry reliance on
    // DwarfDebug away.
    uint64_t Attr;
    if (Ref < InputDIE.getOffset()) {
      // We must have already cloned that DIE.
      uint32_t NewRefOffset =
          RefUnit->getStartOffset() + NewRefDie->getOffset();
      Attr = NewRefOffset;
      Die.addValue(DIEAlloc, dwarf::Attribute(AttrSpec.Attr),
                   dwarf::DW_FORM_ref_addr, DIEInteger(Attr));
    } else {
      // A forward reference. Note and fixup later.
      Attr = 0xBADDEF;
      Unit.noteForwardReference(
          NewRefDie, RefUnit, Ctxt,
          Die.addValue(DIEAlloc, dwarf::Attribute(AttrSpec.Attr),
                       dwarf::DW_FORM_ref_addr, DIEInteger(Attr)));
    }
    return U.getRefAddrByteSize();
  }

They basically manually iterate through all DIEs before they attempt to let the AsmPrinter emit then and change any DIEValue objects that refer to a DIEEntry into a DIEInteger. Not sure how they size the DIEInteger correctly when emitting it though. I don't think they need to take into account DWARF version 2 since they don't deal with that. but I haven't looked too closely at the DwarfLinker to know for sure.

By adding the DWARF version we can just use all of the code in DIE.h/.cpp as is without any changes.


https://reviews.llvm.org/D26879





More information about the llvm-commits mailing list