[llvm] [DWARFLinker] Unset TF_SkipPC for children in debug map (PR #228612)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 16:46:37 PDT 2026


https://github.com/ellishg updated https://github.com/llvm/llvm-project/pull/228612

>From 9fb7240de97df276c195907a40d85d4eea7feac9 Mon Sep 17 00:00:00 2001
From: Ellis Hoag <ellishoag at meta.com>
Date: Fri, 2 Oct 2026 15:24:30 -0700
Subject: [PATCH 1/2] [DWARFLinker] Unset TF_SkipPC for children in debug map

If a subprogram is not in the debug map, then we add the `TF_SkipPC` flag as before to omit `DW_AT_low_pc` from the dwarf. But if it is in the input map, then we want to retain `DW_AT_low_pc` by removing the `TF_SkipPC` flag. This makes a difference when the parent already has `TF_SkipPC`, which is propagated to its children.

Interestingly, this does not seem to be an issue for the parallel linker.
---
 llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp  |  8 ++-
 .../tools/dsymutil/AArch64/skip-pc-nested.ll  | 56 +++++++++++++++++++
 2 files changed, 62 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/tools/dsymutil/AArch64/skip-pc-nested.ll

diff --git a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
index 454143ec00120..b8ae70477d7c6 100644
--- a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
@@ -1890,8 +1890,12 @@ DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE,
 
   if (Abbrev->getTag() == dwarf::DW_TAG_subprogram) {
     Flags |= TF_InFunctionScope;
-    if (!Info.InDebugMap && LLVM_LIKELY(!Update))
-      Flags |= TF_SkipPC;
+    if (LLVM_LIKELY(!Update)) {
+      if (Info.InDebugMap)
+        Flags &= ~TF_SkipPC;
+      else
+        Flags |= TF_SkipPC;
+    }
   } else if (Abbrev->getTag() == dwarf::DW_TAG_variable) {
     // Function-local globals could be in the debug map even when the function
     // is not, e.g., inlined functions.
diff --git a/llvm/test/tools/dsymutil/AArch64/skip-pc-nested.ll b/llvm/test/tools/dsymutil/AArch64/skip-pc-nested.ll
new file mode 100644
index 0000000000000..efd2d69d3d186
--- /dev/null
+++ b/llvm/test/tools/dsymutil/AArch64/skip-pc-nested.ll
@@ -0,0 +1,56 @@
+; RUN: rm -rf %t && split-file %s %t
+
+; RUN: %llc_dwarf -filetype=obj %t/input.ll -o %t/input.o
+
+; RUN: dsymutil -f --linker=classic -oso-prepend-path=%t -y %t/input.map -o %t/classic.dwarf
+; RUN: llvm-dwarfdump --show-parents --name=child %t/classic.dwarf | FileCheck %s --implicit-check-not=DW_TAG_
+
+; RUN: dsymutil -f --linker=parallel -oso-prepend-path=%t -y %t/input.map -o %t/parallel.dwarf
+; RUN: llvm-dwarfdump --show-parents --name=child %t/parallel.dwarf | FileCheck %s --implicit-check-not=DW_TAG_
+
+; CHECK: DW_TAG_compile_unit
+; CHECK: DW_TAG_subprogram
+; CHECK-NOT: DW_AT_low_pc
+; CHECK: DW_AT_linkage_name ("parent")
+; CHECK: DW_TAG_subprogram
+; CHECK-NEXT: DW_AT_low_pc (0x0000000000001004)
+; CHECK-NEXT: DW_AT_high_pc (0x0000000000001008)
+; CHECK: DW_AT_linkage_name ("child")
+
+;--- input.ll
+target triple = "arm64-apple-darwin"
+
+define internal void @parent() noinline optnone !dbg !5 {
+entry:
+  ret void, !dbg !7
+}
+
+define void @child() noinline optnone !dbg !8 {
+entry:
+  ret void, !dbg !9
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "skip-pc-nested", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "skip-pc-nested.c", directory: "/tmp")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = distinct !DISubprogram(name: "parent", linkageName: "parent", scope: !1, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0)
+!6 = !DISubroutineType(types: !10)
+!7 = !DILocation(line: 2, column: 1, scope: !5)
+!8 = distinct !DISubprogram(name: "child", linkageName: "child", scope: !5, file: !1, line: 4, type: !6, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !0)
+!9 = !DILocation(line: 5, column: 1, scope: !8)
+!10 = !{null}
+
+;--- input.map
+# @parent is omitted from the input map, so it will not have DW_AT_low_pc
+# @child is in the input map, so it should have DW_AT_low_pc
+---
+triple: 'arm64-apple-darwin'
+objects:
+  - filename: input.o
+    symbols:
+      - { sym: _child, objAddr: 0x4, binAddr: 0x1004, size: 0x4 }
+...

>From 323506c3f9e822b03d3b2b7ab371a6bd75178000 Mon Sep 17 00:00:00 2001
From: Ellis Hoag <ellishoag at meta.com>
Date: Fri, 2 Oct 2026 16:46:19 -0700
Subject: [PATCH 2/2] fix windows test

---
 llvm/test/tools/dsymutil/AArch64/skip-pc-nested.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/tools/dsymutil/AArch64/skip-pc-nested.ll b/llvm/test/tools/dsymutil/AArch64/skip-pc-nested.ll
index efd2d69d3d186..3b7d542dc12f7 100644
--- a/llvm/test/tools/dsymutil/AArch64/skip-pc-nested.ll
+++ b/llvm/test/tools/dsymutil/AArch64/skip-pc-nested.ll
@@ -1,6 +1,6 @@
 ; RUN: rm -rf %t && split-file %s %t
 
-; RUN: %llc_dwarf -filetype=obj %t/input.ll -o %t/input.o
+; RUN: %llc_dwarf -mtriple=arm64-apple-darwin -filetype=obj %t/input.ll -o %t/input.o
 
 ; RUN: dsymutil -f --linker=classic -oso-prepend-path=%t -y %t/input.map -o %t/classic.dwarf
 ; RUN: llvm-dwarfdump --show-parents --name=child %t/classic.dwarf | FileCheck %s --implicit-check-not=DW_TAG_



More information about the llvm-commits mailing list