[llvm] [dsymutil] Fix parallel linker's self-recursive typedef DIE (PR #166675)

Roy Shi via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 5 16:47:10 PST 2025


https://github.com/royitaqi created https://github.com/llvm/llvm-project/pull/166675

The **root cause** of https://github.com/llvm/llvm-project/issues/162954 is that the two typedef DIEs are merged into one. This is because their synthetic names are the same (see below). The (same) synthetic names are then used as the hash key of the type pool in the (output) artificial type unit (code), making the two input DIEs to both be paired with the same output DIE.
```
CompileUnit::assignTypeNamesRec(): current child = 0x00000044
SyntheticTypeNameBuilder::addDIETypeName():
    added parent name. SyntheticName =
    added type prefix. SyntheticName ={H}
    added type name. SyntheticName ={H}BarInt   <-- Same synthetic name
    assigned to type descriptor. TypeEntryPtr = 0x0x13300a018   <-- It's the same type entry object

CompileUnit::assignTypeNamesRec(): current child = 0x0000004c
SyntheticTypeNameBuilder::addDIETypeName():
    added parent name. SyntheticName =
    added type prefix. SyntheticName ={H}
    added type name. SyntheticName ={H}BarInt   <-- Same synthetic name
    assigned to type descriptor. TypeEntryPtr = 0x0x13300a018   <-- It's the same type entry object
```

One **solution** to fix this is to differentiate the two input DIEs' synthetic names, so that they generate different output DIEs, so that they end up being two DIEs the linked DWARF.

This patch implements this solution and differentiate their synthetic names by adding decl file and line. This is done only for typedef DIEs to minimize the change.

A different implementation can be to call `addReferencedODRDies()` (just 10 lines below my change) so that the synthetic name will contain the referenced types recursively. I'm open to switch to this implementation if it's better.

>From fec4700b3d468dfbd6b68ff34afd4bc3f8ef87be Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Wed, 5 Nov 2025 16:18:40 -0800
Subject: [PATCH] [dsymutil] Fix parallel linker so it won't generate
 self-recurrisve typedef DIE

---
 llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp b/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp
index 34174f98b7e37..144cdb18f76d6 100644
--- a/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp
@@ -372,6 +372,11 @@ Error SyntheticTypeNameBuilder::addTypeName(UnitEntryPairTy InputUnitEntryPair,
       addValueName(InputUnitEntryPair, dwarf::DW_AT_const_value);
     }
   } break;
+  case dwarf::DW_TAG_typedef: {
+    // Add decl file and line if haven't already.
+    if (!HasDeclFileName)
+      addDieNameFromDeclFileAndDeclLine(InputUnitEntryPair, HasDeclFileName);
+  } break;
   default: {
     // Nothing to do.
   } break;



More information about the llvm-commits mailing list