This is an archive of the discontinued LLVM Phabricator instance.

[dsymutil] Verify the keep chain when asserts are enabled
ClosedPublic

Authored by JDevlieghere on Dec 16 2022, 10:10 AM.

Details

Summary

Yesterday I was debugging another instance of the Ref > InputDIE.getOffset() assertion failing in dsymutil. Interestingly, the issue was totally unrelated to D138176. I narrowed down the issue to a DIE being marked as kept while its parent wasn't. That should never happen and is easy to diagnose. To verify my hypothesis, I wrote a little verifier function. Given the complexity of the algorithm that looks for DIEs to keep, I think it's useful to keep it around and do the verification when asserts are enabled.

Diff Detail

Event Timeline

JDevlieghere created this revision.Dec 16 2022, 10:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 16 2022, 10:10 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
JDevlieghere requested review of this revision.Dec 16 2022, 10:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 16 2022, 10:10 AM

Here's what the output looks like for the bug I'm currently working on:

error: Found invalid link in keep chain between 0x6ac5 and 0x6aec
Parent:
0x00006ac5: DW_TAG_module
              DW_AT_name        ("C")
              DW_AT_LLVM_config_macros  ("...")
              DW_AT_LLVM_include_path   ("...")
{
  AddrAdjust: 0
  Ctxt: 0x0000000000000000
  Clone: 0x0000000000000000
  ParentIdx: 558
  Keep: 0
  InDebugMap: 0
  Prune: 1
  Incomplete: 0
  InModuleScope: 1
  ODRMarkingDone: 0
}
Child:
0x00006aec:   DW_TAG_module
                DW_AT_name      ("stddef")
                DW_AT_LLVM_config_macros        ("...")
                DW_AT_LLVM_include_path ("...")
{
  AddrAdjust: 0
  Ctxt: 0x0000000000000000
  Clone: 0x0000000000000000
  ParentIdx: 581
  Keep: 1
  InDebugMap: 0
  Prune: 0
  Incomplete: 0
  InModuleScope: 1
  ODRMarkingDone: 0
}
LLVM ERROR: invalid keep chain
JDevlieghere edited the summary of this revision. (Show Details)Dec 16 2022, 10:13 AM
JDevlieghere edited the summary of this revision. (Show Details)
friss accepted this revision.Dec 16 2022, 10:42 AM

LGTM with minor nit

llvm/lib/DWARFLinker/DWARFLinker.cpp
889

Should this be errs()? Same thing right below.

This revision is now accepted and ready to land.Dec 16 2022, 10:42 AM

Address Fred's comment

aprantl added inline comments.Dec 16 2022, 12:26 PM
llvm/lib/DWARFLinker/DWARFLinker.cpp
2597

Since dsymutil accepts --verify should this maybe be in all builds and enable by that flag?

JDevlieghere marked an inline comment as done.Dec 16 2022, 12:57 PM
JDevlieghere added inline comments.
llvm/lib/DWARFLinker/DWARFLinker.cpp
2597

The verify option checks the validity of the input and/or output dwarf. The verification done here is strictly enforcing an implementation variant, like an assert. I think that besides the name there's not enough overlap to make it part of that.

avl added inline comments.Dec 17 2022, 3:06 AM
llvm/lib/DWARFLinker/DWARFLinker.cpp
877

it looks not neccessary to reverse here.

886

this check looks redundant.

JDevlieghere marked 3 inline comments as done.Dec 19 2022, 8:13 AM
JDevlieghere added inline comments.
llvm/lib/DWARFLinker/DWARFLinker.cpp
877

You're right, but it also doesn't hurt and makes sure we visit children in order (and report them that way) which I think makes the output more like the input if there are multiple broken links for one parent.

886

It guards the report_fatal_error below.

avl added inline comments.Dec 19 2022, 10:36 AM
llvm/lib/DWARFLinker/DWARFLinker.cpp
877

Ok then.

886

Oh, right.

This revision was automatically updated to reflect the committed changes.
JDevlieghere marked 2 inline comments as done.