[llvm-dev] Query regarding relocatable stuff in DWO.

David Blaikie via llvm-dev llvm-dev at lists.llvm.org
Mon Dec 23 14:37:43 PST 2019

On Sun, Dec 22, 2019 at 5:40 AM Sourabh Singh Tomar <sourav0311 at gmail.com>

> Hello Everyone,
> Consider this asm snippet for a moment --
> section .debug_info.dwo
> ...
> .long   .Ldebug_macinfo0        # DW_AT_macros
> ...
> .section        .debug_macinfo.dwo,"e", at progbits
>  .Ldebug_macinfo0:
>      .byte   0x1     # Define macro
> ....
> When compiling this with clang, produces
> fatal error: error in backend: A dwo section may not contain relocations
> -- seems fair,
> Since we don't want relocations in DWO file. Please note here GCC{trunk}
> has no problem with this /Okay with relocations in DWO/ Why??
> Now the real problem -- Since DW_AT_macros/macinfo can appear in both
> split/non-split case.{Only in one or another}. Pointing to macro/macro.dwo
> section.
> Now clang won't allow me to use above approach. So only option left to
> avoid relocations, emitting DW_AT_macros attribute as a difference of
> labels.
> i.e
> .long   .Lcu_macro_begin1-.debug_macro.dwo       # DW_AT_macro_info

Judging by GCC's behavior, and other cases of similar features (consider
the abbrev table offset in the CU header in Split DWARF - similarly, it
isn't relocated, but is a constant value (computed, potentially by a
difference of two labels - but in LLVM's case it's probably just to always
emit it as zero, not sure how we actually implement it though))

> This worked great, clang is fine, GDB also happy. But that was manual
> assembly hack I opted. I didn't find any API in /MCStreamer/ that can
> provide me a difference of 2 labels as label.
> This is needed here --
> TheCU.addSectionLabel(TheCU.getUnitDie(),dwarf::DW_AT_macros,
>               /*Label here?*/,
> TLOF.getDwarfMacroDWOSection()->getBeginSymbol()); -- requires a label to
> add in.

Yeah, there's lots of other cases in the DWARF where a difference of two
labels is needed as an attribute value - consider DW_AT_high_pc for
instance (in DWARFv4 and above), it's emitted as a difference of two
labels, like this:

    if (DD->getDwarfVersion() < 4)
      addLabelAddress(D, dwarf::DW_AT_high_pc, End);
      addLabelDelta(D, dwarf::DW_AT_high_pc, End, Begin);

Oh, an even more analogous example, it seems, is DWARFv4 extension split
DWARF support for ranges:

      if (isDwoUnit())
        addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, List.Label,
        addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges, List.Label,

So it looks like you might be able to use the same logic for the
DW_AT_macros attribute. (looks like the only difference between the two
options (addLabelDelta and addSectionLabel) is the DW_FORM chosen, and the
"addSectionLabel" one uses sec_offset where available, which is what GCC
uses for its DW_AT_macro, etc))

> Theirs analogous EmitLabelDifference(Sym, Sym, Size) API -- but that's for
> emitting + return type is void, So can't plug it in in here.
> Any hints, how to overcome this ?
> Thanks in anticipation!
> Sourabh.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191223/217ee184/attachment.html>

More information about the llvm-dev mailing list