[llvm] a6f40ee - [DWARFLinker] Add assembly-label range handling to parallel linker (#195366)

via llvm-commits llvm-commits at lists.llvm.org
Tue May 5 09:41:25 PDT 2026


Author: Jonas Devlieghere
Date: 2026-05-05T09:41:20-07:00
New Revision: a6f40eed9b4cb1976d5c92be2700bf0931673057

URL: https://github.com/llvm/llvm-project/commit/a6f40eed9b4cb1976d5c92be2700bf0931673057
DIFF: https://github.com/llvm/llvm-project/commit/a6f40eed9b4cb1976d5c92be2700bf0931673057.diff

LOG: [DWARFLinker] Add assembly-label range handling to parallel linker (#195366)

Assembly CUs typically have DW_TAG_label entries instead of subprograms,
so the parallel linker's line-table filter saw no function ranges and
dropped every row. Mirror the classic linker: for labels in
Mips_Assembler or Assembly CUs, look up an assembly range via
getAssemblyRangeForAddress and call addFunctionRange before falling back
to addLabelLowPc.

Added: 
    

Modified: 
    llvm/lib/DWARFLinker/Parallel/DependencyTracker.cpp
    llvm/test/tools/dsymutil/asm-line-tables.test

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DWARFLinker/Parallel/DependencyTracker.cpp b/llvm/lib/DWARFLinker/Parallel/DependencyTracker.cpp
index 06ccb1ac978f3..68b01dd7ddad3 100644
--- a/llvm/lib/DWARFLinker/Parallel/DependencyTracker.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DependencyTracker.cpp
@@ -722,6 +722,16 @@ DependencyTracker::getRootForSpecifiedEntry(UnitEntryPairTy Entry) {
   return Result;
 }
 
+static void dumpKeptDIE(const DWARFDie &DIE, StringRef Kind, bool Verbose) {
+  if (!Verbose)
+    return;
+  outs() << "Keeping " << Kind << " DIE:";
+  DIDumpOptions DumpOpts;
+  DumpOpts.ChildRecurseDepth = 0;
+  DumpOpts.Verbose = Verbose;
+  DIE.dump(outs(), /*Indent=*/8, DumpOpts);
+}
+
 bool DependencyTracker::isLiveVariableEntry(const UnitEntryPairTy &Entry,
                                             bool IsLiveParent) {
   DWARFDie DIE = Entry.CU->getDIE(Entry.DieEntry);
@@ -756,13 +766,7 @@ bool DependencyTracker::isLiveVariableEntry(const UnitEntryPairTy &Entry,
   }
   Info.setHasAnAddress();
 
-  if (Entry.CU->getGlobalData().getOptions().Verbose) {
-    outs() << "Keeping variable DIE:";
-    DIDumpOptions DumpOpts;
-    DumpOpts.ChildRecurseDepth = 0;
-    DumpOpts.Verbose = Entry.CU->getGlobalData().getOptions().Verbose;
-    DIE.dump(outs(), 8 /* Indent */, DumpOpts);
-  }
+  dumpKeptDIE(DIE, "variable", Entry.CU->getGlobalData().getOptions().Verbose);
 
   return true;
 }
@@ -772,6 +776,7 @@ bool DependencyTracker::isLiveSubprogramEntry(const UnitEntryPairTy &Entry) {
   CompileUnit::DIEInfo &Info = Entry.CU->getDIEInfo(Entry.DieEntry);
   std::optional<DWARFFormValue> LowPCVal = DIE.find(dwarf::DW_AT_low_pc);
 
+  const bool Verbose = Entry.CU->getGlobalData().getOptions().Verbose;
   std::optional<uint64_t> LowPc;
   std::optional<uint64_t> HighPc;
   std::optional<int64_t> RelocAdjustment;
@@ -784,7 +789,7 @@ bool DependencyTracker::isLiveSubprogramEntry(const UnitEntryPairTy &Entry) {
 
     RelocAdjustment =
         Entry.CU->getContaingFile().Addresses->getSubprogramRelocAdjustment(
-            DIE, Entry.CU->getGlobalData().getOptions().Verbose);
+            DIE, Verbose);
     if (!RelocAdjustment)
       return false;
 
@@ -816,18 +821,26 @@ bool DependencyTracker::isLiveSubprogramEntry(const UnitEntryPairTy &Entry) {
               .value_or(UINT64_MAX) <= LowPc)
         return false;
 
+      // For assembly-language CUs there are typically no DW_TAG_subprogram
+      // DIEs, so labels are the only addresses we see. Fall back to the
+      // assembly-range lookup to recover a function range for the line-table
+      // filter; otherwise the output line table would be empty.
+      uint16_t Language = dwarf::toUnsigned(
+          Entry.CU->getOrigUnit().getUnitDIE().find(dwarf::DW_AT_language), 0);
+      if (Language == dwarf::DW_LANG_Mips_Assembler ||
+          Language == dwarf::DW_LANG_Assembly) {
+        if (auto Range = Entry.CU->getContaingFile()
+                             .Addresses->getAssemblyRangeForAddress(*LowPc))
+          Entry.CU->addFunctionRange(Range->LowPC, Range->HighPC,
+                                     *RelocAdjustment);
+      }
+
       Entry.CU->addLabelLowPc(*LowPc, *RelocAdjustment);
     }
   } else
     Info.setHasAnAddress();
 
-  if (Entry.CU->getGlobalData().getOptions().Verbose) {
-    outs() << "Keeping subprogram DIE:";
-    DIDumpOptions DumpOpts;
-    DumpOpts.ChildRecurseDepth = 0;
-    DumpOpts.Verbose = Entry.CU->getGlobalData().getOptions().Verbose;
-    DIE.dump(outs(), 8 /* Indent */, DumpOpts);
-  }
+  dumpKeptDIE(DIE, "subprogram", Verbose);
 
   if (!Info.getTrackLiveness() || DIE.getTag() == dwarf::DW_TAG_label)
     return true;

diff  --git a/llvm/test/tools/dsymutil/asm-line-tables.test b/llvm/test/tools/dsymutil/asm-line-tables.test
index d0000426b52c5..c77865dea78ef 100644
--- a/llvm/test/tools/dsymutil/asm-line-tables.test
+++ b/llvm/test/tools/dsymutil/asm-line-tables.test
@@ -5,12 +5,20 @@ $ clang -target arm64-apple-macos26 asm-line-tables.s -o asm-line-tables.o -c -g
 $ clang -target arm64-apple-macos26 -o asm-line-tables.arm64 asm-line-tables.o -nodefaultlibs -nostdlib -static -Wl,-oso_prefix,$PWD
 
 REQUIRES: aarch64-registered-target
-RUN: dsymutil --linker classic -oso-prepend-path %p/Inputs/ %p/Inputs/private/tmp/asm/asm-line-tables.arm64 -o %t.dSYM
+RUN: dsymutil --linker classic --verbose -oso-prepend-path %p/Inputs/ %p/Inputs/private/tmp/asm/asm-line-tables.arm64 -o %t.dSYM | FileCheck %s --check-prefix=VERBOSE
 RUN: llvm-dwarfdump --debug-line %t.dSYM | FileCheck %s
 
-## FIXME: Support --linker parallel
+RUN: dsymutil --linker parallel --verbose -oso-prepend-path %p/Inputs/ %p/Inputs/private/tmp/asm/asm-line-tables.arm64 -o %t.dSYM | FileCheck %s --check-prefix=VERBOSE
+RUN: llvm-dwarfdump --debug-line %t.dSYM | FileCheck %s
 
 CHECK:      0x00000001000002e8      5      0      0   0             0       0  is_stmt
 CHECK-NEXT: 0x00000001000002ec      9      0      0   0             0       0  is_stmt
 CHECK-NEXT: 0x00000001000002f0     10      0      0   0             0       0  is_stmt
 CHECK-NEXT: 0x00000001000002f4     10      0      0   0             0       0  is_stmt end_sequence
+
+VERBOSE:      Keeping subprogram DIE:
+VERBOSE-NEXT: DW_TAG_label
+VERBOSE:      DW_AT_name {{.*}}("foo")
+VERBOSE:      Keeping subprogram DIE:
+VERBOSE-NEXT: DW_TAG_label
+VERBOSE:      DW_AT_name {{.*}}("start")


        


More information about the llvm-commits mailing list