[llvm] 7424655 - [DWARFv5][DWARFLinker] avoid stripping template names for .debug_names.

Alexey Lapshin via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 03:08:09 PDT 2023


Author: Alexey Lapshin
Date: 2023-06-28T12:05:42+02:00
New Revision: 7424655c2646c5b39127df39694a18f9e76c5567

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

LOG: [DWARFv5][DWARFLinker] avoid stripping template names for .debug_names.

DWARFLinker puts three names for subprograms into the .apple_names and
.debug_names: short name, linkage name, name without template parameters.

DW_TAG_subprogram
   DW_AT_linkage_name "_Z3fooIcEvv"
   DW_AT_name "foo<char>"

short name: "foo<char>"
linkage name: "_Z3fooIcEvv"
name without template parameters: "foo"

DWARFv5 does not require stripping template parameters for subprogram name.
Current llvm-dwarfdump --verify reports the error if names stored in
accelerator table do not match with DIE name(name with stripped template
parameters stored in accelerator table does not match with original DIE name).
This patch does not store name without template parameters into the .debug_names table.

Differential Revision: https://reviews.llvm.org/D153869

Added: 
    llvm/test/tools/dsymutil/X86/Inputs/dwarf5-accel.o
    llvm/test/tools/dsymutil/X86/dwarf5-accel.test

Modified: 
    llvm/include/llvm/DWARFLinker/DWARFLinker.h
    llvm/lib/DWARFLinker/DWARFLinker.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DWARFLinker/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/DWARFLinker.h
index eaf0bbb94e34a..8f1d2d079c16b 100644
--- a/llvm/include/llvm/DWARFLinker/DWARFLinker.h
+++ b/llvm/include/llvm/DWARFLinker/DWARFLinker.h
@@ -361,6 +361,9 @@ class DWARFLinker {
   void addAccelTableKind(AccelTableKind Kind) {
     assert(!llvm::is_contained(Options.AccelTables, Kind));
     Options.AccelTables.emplace_back(Kind);
+
+    if (Kind == AccelTableKind::Apple)
+      Options.CanStripTemplateName = true;
   }
 
   /// Set prepend path for clang modules.
@@ -882,6 +885,7 @@ class DWARFLinker {
 
     /// The accelerator table kinds
     SmallVector<AccelTableKind, 1> AccelTables;
+    bool CanStripTemplateName = false;
 
     /// Prepend path for the clang modules.
     std::string PrependPath;

diff  --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp
index 349be17301aea..206ba9d409904 100644
--- a/llvm/lib/DWARFLinker/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp
@@ -192,7 +192,8 @@ bool DWARFLinker::DIECloner::getDIENames(const DWARFDie &Die,
   if (!Info.MangledName)
     Info.MangledName = Info.Name;
 
-  if (StripTemplate && Info.Name && Info.MangledName != Info.Name) {
+  if (StripTemplate && Linker.Options.CanStripTemplateName && Info.Name &&
+      Info.MangledName != Info.Name) {
     StringRef Name = Info.Name.getString();
     if (std::optional<StringRef> StrippedName = StripTemplateParameters(Name))
       Info.NameWithoutTemplate = StringPool.getEntry(*StrippedName);

diff  --git a/llvm/test/tools/dsymutil/X86/Inputs/dwarf5-accel.o b/llvm/test/tools/dsymutil/X86/Inputs/dwarf5-accel.o
new file mode 100644
index 0000000000000..1620b85a7fd83
Binary files /dev/null and b/llvm/test/tools/dsymutil/X86/Inputs/dwarf5-accel.o 
diff er

diff  --git a/llvm/test/tools/dsymutil/X86/dwarf5-accel.test b/llvm/test/tools/dsymutil/X86/dwarf5-accel.test
new file mode 100644
index 0000000000000..621fd80e623a6
--- /dev/null
+++ b/llvm/test/tools/dsymutil/X86/dwarf5-accel.test
@@ -0,0 +1,34 @@
+## This test checks that DIE name with stripped template parameters
+## is not stored into .debug_name section.
+
+## cat dwarf5-accel.cpp
+##
+## template<typename A> void foo() {};
+##
+## int main ( void ) {
+##   foo<char>();
+##   return 0;
+## }
+
+## $ clang -gdwarf-5 dwarf5-accel.cpp -c -o dwarf5-accel.o
+
+#RUN: dsymutil -accelerator=Dwarf -oso-prepend-path %p/Inputs -y %s -o %t.dSYM
+#RUN: llvm-dwarfdump --verify  %t.dSYM | FileCheck %s --check-prefix VERIFY
+#RUN: llvm-dwarfdump -a --verbose  %t.dSYM | FileCheck %s
+
+#VERIFY: No errors.
+
+#CHECK: .debug_names
+#CHECK-NOT: "foo"
+#CHECK: _Z3fooIcEvv
+#CHECK-NOT: "foo"
+#CHECK: "foo<char>"
+
+---
+triple:          'x86_64-apple-darwin'
+objects:
+  - filename:        'dwarf5-accel.o'
+    timestamp:       1676048242
+    symbols:
+      - { sym: _main, objAddr: 0x0000000000000000, binAddr: 0x0000000100000AB0, size: 0x00000008 }
+      - { sym: __Z3fooIcEvv, objAddr: 0x0000000000000020, binAddr: 0x0000000100000BB0, size: 0x00000008 }


        


More information about the llvm-commits mailing list