[PATCH] D45367: [CodeGen/AccelTable]: Don't emit accelerator entries for functions with no names

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 6 06:56:16 PDT 2018


labath created this revision.
labath added reviewers: JDevlieghere, aprantl, dblaikie.

We were emitting accelerator entries for functions with no name, which
is contrary to the DWARF v5 spec: "All other (i.e., *not*
DW_TAG_namespace) debugging information entries without a DW_AT_name
attribute are excluded." Besides that, a name table entry with an empty
string as a key is fairly useless.

We can sometimes end up with functions which have a DW_AT_linkage_name but no
DW_AT_name. One such example is the global-constructor-initialization functions,
which C++ compilers synthesize for each compilation unit with global
constructors.
A very strict reading of the DWARF v5 spec would suggest that we should not even
emit the accelerator entry for the linkage name in this case, but I don't think
we should go that far.

I found this when running the dwarf verifier over llvm codebase compiled
with DWARF v5 accelerator tables.


Repository:
  rL LLVM

https://reviews.llvm.org/D45367

Files:
  lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  test/DebugInfo/Generic/debug-names-empty-name.ll


Index: test/DebugInfo/Generic/debug-names-empty-name.ll
===================================================================
--- /dev/null
+++ test/DebugInfo/Generic/debug-names-empty-name.ll
@@ -0,0 +1,38 @@
+; REQUIRES: object-emission
+; RUN: %llc_dwarf -accel-tables=Dwarf -filetype=obj -o %t < %s
+; RUN: llvm-dwarfdump -find=_GLOBAL__sub_I__ %t | FileCheck --check-prefix=INFO %s
+; RUN: llvm-dwarfdump -debug-names %t | FileCheck --check-prefix=NAMES %s
+; RUN: llvm-dwarfdump -debug-names -verify %t | FileCheck --check-prefix=VERIFY %s
+
+; The debug info entry should not have a DW_AT_name, only a DW_AT_linkage_name.
+; INFO: DW_TAG_subprogram
+; INFO-NOT: DW_AT_name
+; INFO:     DW_AT_linkage_name	("_GLOBAL__sub_I__")
+; INFO-NOT: DW_AT_name
+
+; The accelerator table should contain only one entry.
+; NAMES: Name count: 1
+; And it should be the linkage name.
+; CHECK: String: 0x{{[0-9a-f]*}} "_GLOBAL__sub_I__"
+
+; Verification should succeed.
+; VERIFY: No errors.
+
+define internal void @_GLOBAL__sub_I__() section ".text.startup" !dbg !7 {
+entry:
+  ret void
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 7.0.0 (trunk 329378) (llvm/trunk 329379)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !2)
+!1 = !DIFile(filename: "-", directory: "/usr/local/google/home/labath/ll/build/opt")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 7.0.0 (trunk 329378) (llvm/trunk 329379)"}
+!7 = distinct !DISubprogram(linkageName: "_GLOBAL__sub_I__", scope: !1, file: !1, type: !8, isLocal: true, isDefinition: true, flags: DIFlagArtificial, isOptimized: false, unit: !0, variables: !2)
+!8 = !DISubroutineType(types: !2)
Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -392,7 +392,9 @@
 void DwarfDebug::addSubprogramNames(const DISubprogram *SP, DIE &Die) {
   if (!SP->isDefinition())
     return;
-  addAccelName(SP->getName(), Die);
+
+  if (SP->getName() != "")
+    addAccelName(SP->getName(), Die);
 
   // If the linkage name is different than the name, go ahead and output
   // that as well into the name table.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45367.141337.patch
Type: text/x-patch
Size: 2466 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180406/76b2981a/attachment.bin>


More information about the llvm-commits mailing list