[dsymutil] Avoid invalid keep chains due to pruning
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 4 Jan 2023 23:01:19 +0000 (15:01 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 4 Jan 2023 23:01:58 +0000 (15:01 -0800)
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.

Differential revision: https://reviews.llvm.org/D140930

llvm/lib/DWARFLinker/DWARFLinker.cpp

index 4a8c2c2..d496245 100644 (file)
@@ -788,8 +788,14 @@ void DWARFLinker::lookForDIEsToKeep(AddressesMap &AddressesMap,
     unsigned Idx = Current.CU.getOrigUnit().getDIEIndex(Current.Die);
     CompileUnit::DIEInfo &MyInfo = Current.CU.getInfo(Idx);
 
-    if (MyInfo.Prune)
-      continue;
+    if (MyInfo.Prune) {
+      // We're walking the dependencies of a module forward declaration that was
+      // kept because there is no definition.
+      if (Current.Flags & TF_DependencyWalk)
+        MyInfo.Prune = false;
+      else
+        continue;
+    }
 
     // If the Keep flag is set, we are marking a required DIE's dependencies.
     // If our target is already marked as kept, we're all set.