This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Prevent duplicate files in debug line header in dwarf 5: another attempt
AcceptedPublic

Authored by tamur on Apr 9 2019, 2:36 PM.

Details

Summary

Another attempt to land the changes in debug line header to prevent duplicate files in Dwarf 5. I rolled back my previous commit because of a mistake in generating the object file in a test. Meanwhile, I addressed some offline comments and changed the implementation; the largest difference is that MCDwarfLineTableHeader does not keep DwarfVersion but gets it as a parameter. I also merged the patch to fix two lld tests that will strt to fail into this patch.

Original Commit: https://reviews.llvm.org/D59515

Original Message:
Motivation: In previous dwarf versions, file name indexes started from 1, and the primary source file was not explicit. Dwarf 5 standard (6.2.4) prescribes the primary source file to be explicitly given an entry with an index number 0.

The current implementation honors the specification by just duplicating the main source file, once with index number 0, and later maybe with another index number. While this is compliant with the letter of the standard, the duplication causes problems for consumers of this information such as lldb. (Some files are duplicated, where only some of them have a line table although all refer to the same file)

With this change, dwarf 5 debug line section files always start from 0, and the zeroth entry is not duplicated whenever possible. This requires different handling of dwarf 4 and dwarf 5 during generation (e.g. when a function returns an index zero for a file name, it signals an error in dwarf 4, but not in dwarf 5) However, I think the minor complication is worth it, because it enables all consumers (lldb, gdb, dwarfdump, objdump, and so on) to treat all files in the file name list homogenously.

Event Timeline

tamur created this revision.Apr 9 2019, 2:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 9 2019, 2:36 PM
MaskRay added inline comments.Apr 10 2019, 1:26 AM
llvm/include/llvm/MC/MCDwarf.h
44–51

Should the comment be updated as well?

tamur updated this revision to Diff 194543.Apr 10 2019, 10:19 AM
tamur marked an inline comment as done.Apr 10 2019, 10:20 AM
MaskRay added inline comments.Apr 11 2019, 4:39 AM
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
1013

For DWARF<5, if we make FileNames[0] a placeholder (i.e. waste the first entry), would that make the logic simpler? e.g. we may not need the two functions.

tamur marked an inline comment as done.Apr 11 2019, 1:15 PM
tamur added inline comments.
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
1013

Prologue.FileNames is public and is referred from outside. I don't want to change Prologue.FileNames implementation for Dwarf 4; that entails changing those clients and results in a larger patch. Alternatively, this patch is minimal and deals with 'dirty' stuff in a small, private method.

MaskRay added inline comments.Apr 15 2019, 6:10 AM
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
1013

Thinking it more. Dispatching on DwarfVersion >= 5 looks better to me.

echristo accepted this revision.Apr 17 2019, 11:41 PM

OK, this code could use some work, but not for you to refactor it more than you already have.

One change: Please change your use of MCContext in the patch with an unsigned DwarfVersion and pass that down instead. There is, sadly, nothing else that can be minimized by passing the context and it's just a little more confusing. Conveniently you can get the version anywhere you were getting the context so it should be a mechanical change.

LGTM with that change. Feel free to commit without uploading another version at that point.

Thanks!

-eric

This revision is now accepted and ready to land.Apr 17 2019, 11:41 PM