This is an archive of the discontinued LLVM Phabricator instance.

[dsymutil] Avoid invalid keep chains due to pruning
ClosedPublic

Authored by JDevlieghere on Jan 3 2023, 4:50 PM.

Details

Summary

The pruning property that's part of the DIE info is fully computing during the analyzeContextInfo phase, but can be updated during the lookForDIEsToKeep phase.

// Keep a module forward declaration if there is no definition.
if (!(isODRAttribute(AttrSpec.Attr) && Info.Ctxt &&
      Info.Ctxt->hasCanonicalDIE()))
  Info.Prune = false;

When the pruning property is updated during the lookForDIEsToKeep phase, it's not propagated to the parent, unlike during the analyzeContextInfo phase. This can result in an invalid keep chain with the child DIE being marked as kept while its parent is still marked as pruned and therefore never kept, a situation that's now caught by 1b79bed8f532.

This patch fixes this issue by updating the pruning properties of the parent DIE during the parent walk.

Similar to c9cbe6937b1f, this issue was caught in a big internal project that doesn't lend itself to reduction and so far I haven't been able to create an artificial test case where (1) a pruned DIE doesn't have a decl context and (2) is marked as kept.

Diff Detail

Event Timeline

JDevlieghere created this revision.Jan 3 2023, 4:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2023, 4:50 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
JDevlieghere requested review of this revision.Jan 3 2023, 4:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2023, 4:50 PM
avl accepted this revision.Jan 4 2023, 1:52 PM
avl added inline comments.
llvm/lib/DWARFLinker/DWARFLinker.cpp
793

It looks OK. Though add the comment explaining what is going on, please?
That Prune is erased because we decided to keep module forward declaration(and its dependencies) inside lookForRefDIEsToKeep.

This revision is now accepted and ready to land.Jan 4 2023, 1:52 PM
This revision was automatically updated to reflect the committed changes.