This is an archive of the discontinued LLVM Phabricator instance.

[MCDwarf] Generate DWARF v5 .debug_rnglists for assembly files
ClosedPublic

Authored by MaskRay on Feb 28 2020, 11:28 AM.

Details

Summary
// clang -c -gdwarf-5 a.s -o a.o
.section .init; ret
.text; ret

.debug_info contains DW_AT_ranges and llvm-dwarfdump will report
a verification error because .debug_rnglists does not exist.

This patch generates .debug_rnglists for assembly files.
emitListsTableHeaderStart() in DwarfDebug.cpp can be shared with
MCDwarf.cpp. Because CodeGen depends on MC, I move the function to
MCDwarf.cpp

Diff Detail

Event Timeline

MaskRay created this revision.Feb 28 2020, 11:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 28 2020, 11:28 AM

The general direction is fine, but some details need to be tidied up and I'd like to undo a few unnecessary changes.

llvm/include/llvm/MC/MCDwarf.h
48

I think it would be more usual to use a namespace here (which would be lowercase, mcdwarf).

llvm/lib/MC/MCDwarf.cpp
941

This name change seems inappropriate. This symbol is not paired with an End symbol, and for the GenDwarf case there is only one range list.

966

isDWARF5

1166

AFAICT changing these lines has no functional effect, and IMO the result is less readable.

1166

This change also appears to make the code less readable.

1187

This seems like a gratuitous name change. There is only one range list, and it has its own section, so the old name seems fine.

1190

Why remove the asserts?

1220–1223

Lost another assertion here. You could move it inside emitGenDwarfRanges() if you wish, but I would rather not remove assertions.

llvm/test/MC/ARM/dwarf-asm-multiple-sections.s
2

I'd prefer to have this check both DWARF and DWARF5 prefixes. The generic checks provide context.

4

Keep this using both RELOC and RELOC5 here.

73–78

The above checks (for .debug_ranges) should all become DWARF4 checks.

110

The .debug_ranges checks should all be using RELOC4.

MaskRay updated this revision to Diff 247389.Feb 28 2020, 4:13 PM
MaskRay marked 13 inline comments as done.

Address comments

MaskRay added inline comments.Feb 28 2020, 4:15 PM
llvm/lib/MC/MCDwarf.cpp
941

Rename to RangesSymbol?

1187

For .debug_rnglists, It is no longer at the start of the section, so the old name is not appropriate.

1190

MCSymbolRefExpr::create asserts the non-nullness.

MaskRay updated this revision to Diff 247398.Feb 28 2020, 5:53 PM

Revert one unneeded test line change.

Post-weekend ping :) (Sorry if that was too frequent..)

probinson accepted this revision.Mar 3 2020, 8:46 AM

LGTM, thanks!

llvm/lib/MC/MCDwarf.cpp
1187

Ah, right, I'd forgotten it points to the table not the header, in v5.

This revision is now accepted and ready to land.Mar 3 2020, 8:46 AM

Post-weekend ping :) (Sorry if that was too frequent..)

Our usual guidance is a week between pings.

This revision was automatically updated to reflect the committed changes.
dblaikie added inline comments.Mar 3 2020, 1:35 PM
llvm/lib/MC/MCDwarf.cpp
48–59

Please pass "S" by reference here, since it's unconditionally dereferenced (so the null state isn't needed) - this will simplify some of the callers too (x.get() -> *x)

TableStart and TableEnd can remain pointers since their underlying APIs use them/they're more "tokens" to pass around.

1120–1124

Might be worth considering rolling the start/end label creation into this utility function & having this function return the EndSymbol for later use?

(some of the other "emit a header with the usual length field" implementations in AsmPrinter use this idiom - the function creates both labels, returns the end label for the outer code to emit at the end of the contents)

MaskRay marked 2 inline comments as done.Mar 3 2020, 2:05 PM
MaskRay added inline comments.
llvm/lib/MC/MCDwarf.cpp
48–59

Agreed with the analysis.

It also makes sense for MCStreamer::emitAbsoluteSymbolDiff to take references as parameters. However, MCSymbol * typed parameters are much more common than MCSymbol &.

1120–1124
// https://github.com/llvm/llvm-project/blob/master/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp#L2425
static MCSymbol *emitLoclistsTableHeader(AsmPrinter *Asm,
                                         const DwarfDebug &DD) {
  MCSymbol *TableStart = Asm->createTempSymbol("debug_loclist_table_start");
  MCSymbol *TableEnd = Asm->createTempSymbol("debug_loclist_table_end");
  mcdwarf::emitListsTableHeaderStart(*Asm->OutStreamer, TableStart, TableEnd);

The temporary labels may have a different name (loclist). Shall I add another parameter SymbolName accepting either debug_loclists_header or debug_rnglists_header?

MaskRay marked an inline comment as done.Mar 3 2020, 2:06 PM
MaskRay added inline comments.
dblaikie added inline comments.Mar 3 2020, 2:30 PM
llvm/lib/MC/MCDwarf.cpp
1120–1124

I'm undecided/your choice - I wonder if it might be reasonable to not worry about giving them such distinct names? let them be debug_list_header0, debug_list_header1, etc? I don't mind too much either way. Adding the list type string, or not. I guess it's probably nice to add it.

MaskRay marked 2 inline comments as done.Mar 3 2020, 3:21 PM
MaskRay added inline comments.
llvm/lib/MC/MCDwarf.cpp
1120–1124

In D75568, I moved TableStart/TableEnd generation into emitListsTableHeaderStart(). PTAL~

It seems we don't have a test checking -filetype=asm output, so the name is not significant.

dblaikie added inline comments.Mar 3 2020, 4:06 PM
llvm/lib/MC/MCDwarf.cpp
1120–1124

Yeah, I wouldn't expect we'd test the asm output - but we still like to keep it readable and editable (eg: the names of labels, the text of comments, the use of labels rather than precalculating offsets (sometimes - we haven't done that completely, but it might be worthwhile to make for highly editable DWARF)). Having the more specific names /could/ be nice - but like I said above, I don't think it's super important & should still be quite legible/editable as-is. Thanks!