[PATCH] D153550: [DWARFVerifier] Fix verification of nameless variables.

Felipe de Azevedo Piovezan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 22 07:05:18 PDT 2023


fdeazeve created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
fdeazeve requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The verifier builds a list of all "possible" names of a variable and then
verifies that the name inside __debug_names is one of those possible names.
For a nameless variable, the list is empty, but its name in the accelerator
table is "", so that logic fails.

One could also question whether accelerator table entries with an empty name
should be valid to begin with. The specification says that:

- All other debugging information entries without a DW_AT_name attribute are
- excluded.

But it also says that:

- DW_TAG_variable debugging information entries with a DW_AT_location attribute
- that includes a DW_OP_addr or DW_OP_form_tls_address operator are included;
- otherwise, they are excluded.

So it's not clear which rules takes precedence. Changing the logic to skip
generating entries in this case is likely more complex and probably deserves its
own discussion, as such this commit proposes making the verifier "clean" first:
its logic is arguably buggy and if we want to forbid empty names the verifier
implementation should check for that explicitly, not in this very implicit way.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153550

Files:
  llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
  llvm/test/DebugInfo/Generic/debug-names-nameless-var.ll


Index: llvm/test/DebugInfo/Generic/debug-names-nameless-var.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/Generic/debug-names-nameless-var.ll
@@ -0,0 +1,23 @@
+; RUN: %llc_dwarf -debugger-tune=lldb -accel-tables=Dwarf -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-names %t | FileCheck %s
+; RUN: llvm-dwarfdump -debug-names -verify %t | FileCheck --check-prefix=VERIFY %s
+
+ at nameless_var = constant i8 0, !dbg !0
+
+; CHECK: Name count: 1
+; CHECK: String: 0x{{[0-9a-f]*}} ""
+; VERIFY: No errors
+
+!llvm.dbg.cu = !{!10}
+!llvm.module.flags = !{!14, !15}
+!llvm.ident = !{!20}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(scope: null, file: !11, line: 1, type: !5, isLocal: true, isDefinition: true)
+!5 = !DIBasicType(size: 8, encoding: DW_ATE_signed_char)
+!10 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !11, producer: "blah", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !12, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
+!11 = !DIFile(filename: "blah", directory: "blah")
+!12 = !{!0}
+!14 = !{i32 7, !"Dwarf Version", i32 5}
+!15 = !{i32 2, !"Debug Info Version", i32 3}
+!20 = !{!"blah"}
Index: llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -1417,6 +1417,9 @@
     }
 
     auto EntryNames = getNames(DIE);
+    // If the entry has no name, its name in the table will be "".
+    if (EntryNames.empty())
+      EntryNames.push_back("");
     if (!is_contained(EntryNames, Str)) {
       error() << formatv("Name Index @ {0:x}: Entry @ {1:x}: mismatched Name "
                          "of DIE @ {2:x}: index - {3}; debug_info - {4}.\n",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153550.533592.patch
Type: text/x-patch
Size: 1903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230622/8dab6623/attachment.bin>


More information about the llvm-commits mailing list