This is an archive of the discontinued LLVM Phabricator instance.

[MC] Implement generating 64-bit debug info.
AbandonedPublic

Authored by ikudrin on May 21 2020, 9:08 AM.

Details

Summary

The patch adds a new command-line switch --dwarf64 to llvm-mc, which selects the format of debug info generated by the tool. The support is limited to 64-bit targets because the format requires using 64-bit relocations. COFF targets are not supported for the same reason.

Diff Detail

Event Timeline

ikudrin created this revision.May 21 2020, 9:08 AM

Nice! This looks reasonable to me.

So this is DWARF64 support for debug_line in LLVM? And the first support for DWARF64 emission in LLVM in general?

Probably good to include that in the title - something like "Add initial (debug_line only) support for DWARF64" perhaps.

dblaikie added inline comments.May 21 2020, 4:03 PM
llvm/test/MC/ELF/gen-dwarf64.s
81–83

This concerns me slightly - looks like there was some latent/hidden/untested DWARF64 support in the rnglists that's just now become testable? So it might need some more testing if it's been so far untested? (similarly with any other sections with latent support - debug_info, debug_aranges, abbrev(? not sure if abbrev is different in 32/64))

llvm/tools/llvm-mc/llvm-mc.cpp
405–414

Perhaps this should have a FIXME? and/or the code where the 4-byte only support is should have a FIXME? Are you planning to do that in a follow-up patch?

And is this error-path tested?

MaskRay added inline comments.May 21 2020, 11:26 PM
llvm/test/MC/ELF/gen-dwarf64.s
1

ELF can use # as well. If you want to add comments, you may use ##

llvm/tools/llvm-mc/llvm-mc.cpp
400

cc/ld/binutils usually don't append a dot in a diagnostic.

They do not exist -> 32-bit targets don't support DWARF64, which requires 64-bit relocations.

405

Does it make sense to explicitly check for COFF?

echristo added inline comments.May 22 2020, 12:11 AM
llvm/test/MC/ELF/gen-dwarf64.s
2

I'd probably prefer the error cases to be in a separate test.

ikudrin marked 6 inline comments as done.May 22 2020, 4:40 AM

So this is DWARF64 support for debug_line in LLVM?

Not exactly. The patch supports all tables that llvm-mc can generate if I have not missed anything. And the support, for now, is enabled only in the tool itself.

And the first support for DWARF64 emission in LLVM in general?

That is probably true, though I do not have deep knowledge of all LLVM tree to say for sure.

Probably good to include that in the title - something like "Add initial (debug_line only) support for DWARF64" perhaps.

The patch aims to support all tables llvm-mc can generate in one shot, so that comment would not be exactly correct. Or maybe I am not following you.

llvm/test/MC/ELF/gen-dwarf64.s
81–83

There was no support for DWARF64 before this patch. As for .debug_rnglists, there are not many changes concerning this format, because we do not emit offsets for range lists, see emitGenDwarfRanges().

I've extended the test adding some additional fields, but in general, I suppose that the produced tables are correct as long as llvm-dwarfdump can successfully parse them and report the format.

llvm/tools/llvm-mc/llvm-mc.cpp
405

This setting affects the emitting of 64-bit info directly, as it is directly passed to MCStreamer::emitSymbolValue(). Checking for targeting COFF would be an indirect condition, which potentially might become incorrect without noticing. I prefer a more robust condition.

405–414

Not sure if anyone would struggle to support DWARF64 on 32-bit targets. That would be tricky without 64-bit relocations. Personally, I do not have such plans.

All three cases have tests, see COFF/dwarf64-err.s and ELF/dwarf64-err.s.

ikudrin updated this revision to Diff 265705.May 22 2020, 4:41 AM
  • Extended checks in the main test.
  • Moved checks for error cases into a separate test.
  • Addressed other comments.

I know this wouldn't be DWARF compliant - but could you separate this into one patch per section. (the first patch could add a test case & just check the debug_abbrev section has correct DWARF64, the next one testing the debug_info, etc. (that is assuming llvm-dwarfdump can handle mixid DWARF32/DWARF64 sections) - it'd be easier to validate all the changes to each sections emission are being tested appropriately that way

Thanks for this. Looks pretty good, but I haven't given it enough of an in-depth read, nor is my MC knowledge in this area up-to-date enough to be confident enough to approve.

llvm/tools/llvm-mc/llvm-mc.cpp
391

Nit: either "the 64-bit DWARF format" or simply "64-bit DWARF".

400

cc/ld/binutils usually don't append a dot in a diagnostic.

For reference, this is now in the LLVM style guide too (along with no upper-case letter for the start of diagnostics).

ikudrin abandoned this revision.Jun 4 2020, 5:27 AM
ikudrin marked 2 inline comments as done.

I know this wouldn't be DWARF compliant - but could you separate this into one patch per section. (the first patch could add a test case & just check the debug_abbrev section has correct DWARF64, the next one testing the debug_info, etc. (that is assuming llvm-dwarfdump can handle mixid DWARF32/DWARF64 sections) - it'd be easier to validate all the changes to each sections emission are being tested appropriately that way

I've prepared a series of patches starting with D81143. Please, take a look. So, I am abandoning this revision in favor of the new set.

llvm/tools/llvm-mc/llvm-mc.cpp
391

Thanks! Fixed in D81143.

Some of these changes are specific to cases where we are emitting DWARF describing assembler source; I don't see any reason to support DWARF-64 for those cases. (In general, any functions with GenDwarf in the name are for this case.) Also in most cases the DWARF version for sections describing assembler source are hard-coded to DWARF version 2, which did not define the DWARF-64 format.

Ah sorry hadn't noticed this one was abandoned. Never mind.