This is an archive of the discontinued LLVM Phabricator instance.

Improved Macro emission in dwarf
ClosedPublic

Authored by aaboud on Jan 18 2016, 5:17 AM.

Details

Summary

Followed David feedback on emitting offset of macinfo entry into compiler unit DIE.
New code is using delta between labels rather than explicitly calculating size/offset of macro entry.

Diff Detail

Repository
rL LLVM

Event Timeline

aaboud updated this revision to Diff 45172.Jan 18 2016, 5:17 AM
aaboud updated this revision to Diff 45173.
aaboud retitled this revision from to Improved Macro emission in dwarf.
aaboud updated this object.
aaboud added reviewers: dblaikie, aprantl.
aaboud added a subscriber: llvm-commits.

Reverted the new structures AsmStreamerBase, ...
As they are not needed anymore.

aprantl edited edge metadata.Jan 19 2016, 10:17 AM

Thanks for going through this again! I'll defer to dblaikie who is more familiar with this code than I am.

dblaikie added inline comments.Jan 19 2016, 3:16 PM
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
627 ↗(On Diff #45173)

This seems wrong - a delta isn't a section offset. Once this DWARF is relocated (eg: linked with another object file containing DWARF) these deltas would become incorrect.

A label delta is constant, not a dynamic/link time relocation - representing the distance between two labels. That doesn't change when the debug info is linked and multiple macinfo sections are concatenated together.

But DWARF requires the sec_offset to represent the final offset within the section of the linked debug info. So I assume, much like DW_AT_stmt_list and DW_AT_ranges. Like those two attributes, I assume this one should be emitted using "addSectionOffset" to ensure it has the right kind of relocation, etc. (& on MachO it doesn't use a reloc - addSectionOffset handles that case too)

lib/CodeGen/AsmPrinter/DwarfDebug.h
211 ↗(On Diff #45173)

Rather than adding a map, the MCSymbol should probably just be part of the DwarfCompileUnit itself?

(you can check DwarfCompileUnit::attachRangesOrLowHighPC, used to add DW_AT_ranges to the DW_TAG_compile_unit (& elsewhere) for some inspiration - though it won't match that exactly (that one builds a range list, keeps a label for it, attaches a reloc to that label, later on emits the range list with the label - some of that should be similar to what you need/want, without the need to build an intermediate data structure like the range list))

aaboud updated this revision to Diff 45394.Jan 20 2016, 8:35 AM
aaboud edited edge metadata.
aaboud marked 2 inline comments as done.

Applied changes according to David comments.

Thanks David for the comments.
I uploaded a new patch.

Please, let me know if this looks right now.

lib/CodeGen/AsmPrinter/DwarfDebug.cpp
627 ↗(On Diff #45173)

I should check more for similar cases before highjack the addLabelDelta. Thanks for pointing that out.

Also, I had a bug there, because I wanted to calculate the offset from the beginning of the section and not from the previous section!

I reverted the change in addLabelDelta function and now is using addSectionDelta function, hope that it is the right one.

do you agree?

dblaikie added inline comments.Jan 20 2016, 9:51 AM
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
565 ↗(On Diff #45394)

We don't support non-existence of other DWARF sections (we don't generally check for null return from TLOF.getDwarf* functions elsewhere, so far as I can see/recall) - is there any reason we need to do it in this particular case?

566 ↗(On Diff #45394)

I think this is the wrong API (looking at how setBeginSymbol is called elsewhere) to create the section start symbol - but in any case, again, we don't create section start symbols anywhere in the DWARF codegen, so I don't think we need to do it for Macro info either. We just rely on their existence in all other cases, it seems?

It's probably worth doing a little test of your own to build two separate objects with macro info, link them together & check that dumping/values all make sense - that the two CU's references to their macinfo actually get relocated during linking, etc. (no need to commit a test like this - we could have a test that checks that there is a relocation for the macinfo attribute, but I'm not /too/ fussed about that, it's awkward and probably annoyingly platform specific, etc)

629 ↗(On Diff #45394)

addSectionDelta isn't quite right - because it doesn't account for the MachO case where relocations are not used.

DwarfCompileUnit::addSectionLabel handles this case and wraps addSectionDelta.

1511 ↗(On Diff #45394)

Please commit these unrelated comment fixes separately. No need for further review on that, you can just commit them directly yourself.

aaboud marked 4 inline comments as done.Jan 24 2016, 1:26 AM

Thanks David for the comments.
I will upload a new patch soon.

lib/CodeGen/AsmPrinter/DwarfDebug.cpp
565 ↗(On Diff #45394)

No specific reason.
It is just that I used an old implementation used to be in LLVM in the past that tries to emit macros.
That implementation used to check the existence of DWARF sections.
I was not sure if I should keep it or not.

Anyway, I removed the checks.

566 ↗(On Diff #45394)

Sorry for my lack of understanding how the section handling works.
I debugged it a little and understand what was missing, I should have initialized the macinfo section with a name for the begin label.

I will do the manual test to verify that the generated object file is accepted by the linker.

629 ↗(On Diff #45394)

Now, I understand what you mean. I modified the code to use "addSectionLabel".
In your first comment you mentioned "addSectionOffset" and I could not figure out how I can use it with labels.

aaboud updated this revision to Diff 45819.Jan 24 2016, 1:28 AM
aaboud marked 3 inline comments as done.

Modified patch according to David comments.

dblaikie accepted this revision.Jan 28 2016, 5:30 PM
dblaikie edited edge metadata.

Looks good - thanks!

This revision is now accepted and ready to land.Jan 28 2016, 5:30 PM
This revision was automatically updated to reflect the committed changes.