[llvm] [DWARFDump] Make --verify handle all sections by default (PR #81559)

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 08:36:49 PST 2024


https://github.com/felipepiovezan updated https://github.com/llvm/llvm-project/pull/81559

>From 505e49211e612066aa37d6c9b345850af2c8d061 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Mon, 12 Feb 2024 16:33:42 -0800
Subject: [PATCH 1/2] [DWARFDump] Make --verify handle all sections by default

The current behavior of --verify is that it only verifies debug_info,
debug_abbrev and debug_names. This seems fairly arbitrary and might have been
unintentional, as originally the absence of any section flags implied "all".

This patch changes the behavior so that the verifier now verifies everything by
default. It revealed two tests that had potentially invalid DWARF:

1. dwarfdump-str-offsets.s is adding padding between two debug_str_offset
contributions. The standard does not explicitly allow this behavior. See issue
https://github.com/llvm/llvm-project/issues/81558

2. dwarf5-macro.test uses a checked-in binary that has invalid
debug_str_offsets. One of its entries points to the _middle_ of the string
section:

error: .debug_str_offsets: contribution 0x0: index 0x4: invalid string offset
*0x18 == 0x455D, is neither zero nor immediately following a null character

If we look at the closest offset to 0x455D in debug_str:

```
0x0000454e: "__SLONG32_TYPE int"
```

0x455D points to "int".
---
 llvm/test/DebugInfo/X86/dwarfdump-str-offsets.s            | 5 ++++-
 llvm/test/DebugInfo/X86/skeleton-unit-verify.s             | 2 ++
 .../tools/llvm-dwarfdump/X86/verify_file_encoding.yaml     | 2 ++
 llvm/test/tools/llvm-dwarfutil/ELF/X86/dwarf5-macro.test   | 7 +++++--
 llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp               | 3 ++-
 5 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/llvm/test/DebugInfo/X86/dwarfdump-str-offsets.s b/llvm/test/DebugInfo/X86/dwarfdump-str-offsets.s
index 1725813aac7707..66dfb5f83acb3e 100644
--- a/llvm/test/DebugInfo/X86/dwarfdump-str-offsets.s
+++ b/llvm/test/DebugInfo/X86/dwarfdump-str-offsets.s
@@ -1,6 +1,9 @@
 # RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o %t.o
 # RUN: llvm-dwarfdump -v %t.o 2> %t.err | FileCheck --check-prefixes=COMMON,SPLIT,OFFSETS %s
-# RUN: llvm-dwarfdump -verify %t.o | FileCheck --check-prefix=VERIFY %s
+
+# FIXME: the verifier does not accept padding between debug-str-offset
+# sections, which this test uses.
+# RUN: llvm-dwarfdump -verify --debug-info %t.o | FileCheck --check-prefix=VERIFY %s
 # RUN: llvm-dwarfdump -debug-str-offsets %t.o | FileCheck --check-prefix=OFFSETS %s
 # 
 # Check that we don't report an error on a non-existent range list table.
diff --git a/llvm/test/DebugInfo/X86/skeleton-unit-verify.s b/llvm/test/DebugInfo/X86/skeleton-unit-verify.s
index 92a3df486da39d..6aaac18169b604 100644
--- a/llvm/test/DebugInfo/X86/skeleton-unit-verify.s
+++ b/llvm/test/DebugInfo/X86/skeleton-unit-verify.s
@@ -11,6 +11,8 @@
 # CHECK-NEXT: DW_TAG_skeleton_unit
 # CHECK-NEXT: error: Skeleton compilation unit has children.
 # CHECK-NEXT: Verifying dwo Units...
+# CHECK-NEXT: Verifying .debug_line...
+# CHECK-NEXT: Verifying .debug_str_offsets...
 # CHECK-NEXT: Errors detected.
 
         .section .debug_abbrev,"", at progbits
diff --git a/llvm/test/tools/llvm-dwarfdump/X86/verify_file_encoding.yaml b/llvm/test/tools/llvm-dwarfdump/X86/verify_file_encoding.yaml
index fe31436e9f6e35..4afb7758214414 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/verify_file_encoding.yaml
+++ b/llvm/test/tools/llvm-dwarfdump/X86/verify_file_encoding.yaml
@@ -51,6 +51,8 @@
 # CHECK-NEXT:               DW_AT_call_file   [DW_FORM_sdata] (4)
 # CHECK-NEXT:               DW_AT_call_line   [DW_FORM_sdata] (5){{[[:space:]]}}
 # CHECK-NEXT: Verifying dwo Units...
+# CHECK-NEXT: Verifying .debug_line...
+# CHECK-NEXT: Verifying .debug_str_offsets...
 # CHECK-NEXT: error: Aggregated error counts:
 # CHECK-NEXT: error: Invalid encoding in DW_AT_decl_file occurred 4 time(s).
 # CHECK-NEXT: error: Invalid file index in DW_AT_call_line occurred 1 time(s).
diff --git a/llvm/test/tools/llvm-dwarfutil/ELF/X86/dwarf5-macro.test b/llvm/test/tools/llvm-dwarfutil/ELF/X86/dwarf5-macro.test
index 518244a01ab5fa..0c5cbe46b7c6c8 100644
--- a/llvm/test/tools/llvm-dwarfutil/ELF/X86/dwarf5-macro.test
+++ b/llvm/test/tools/llvm-dwarfutil/ELF/X86/dwarf5-macro.test
@@ -45,12 +45,15 @@
 
 ## Check that macro table preserved during simple copying.
 #
+# FIXME: the input of this test is itself invalid w.r.t. debug_str_offsets,
+# which also causes the next two calls to --verify to fail, so we only verify
+# debug_info on those.
 #RUN: llvm-dwarfutil --no-garbage-collection %p/Inputs/dwarf5-macro.out %t1
-#RUN: llvm-dwarfdump -verify %t1 | FileCheck %s
+#RUN: llvm-dwarfdump -verify --debug-info %t1 | FileCheck %s
 #RUN: llvm-dwarfdump -a  %t1 | FileCheck %s --check-prefix=MACRO
 
 #RUN: llvm-dwarfutil --linker parallel --no-garbage-collection %p/Inputs/dwarf5-macro.out %t1
-#RUN: llvm-dwarfdump -verify %t1 | FileCheck %s
+#RUN: llvm-dwarfdump -verify %t1 --debug-info | FileCheck %s
 #RUN: llvm-dwarfdump -a  %t1 | FileCheck %s --check-prefix=MACRO
 
 ## Check that macro table preserved during updating accelerator tables.
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index 8cdd84bcc867cb..f745c0a51ac882 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -866,7 +866,8 @@ int main(int argc, char **argv) {
     if (Verbose)
       DumpType = DIDT_All;
     else
-      DumpType = DIDT_DebugInfo;
+      // If no options are passed, verify everything but dump only debug_info.
+      DumpType = Verify ? DIDT_All : DIDT_DebugInfo;
   }
 
   // Unless dumping a specific DIE, default to --show-children.

>From ef33216ac874bf635041c591f9de274d3e8863e1 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Tue, 13 Feb 2024 08:36:36 -0800
Subject: [PATCH 2/2] fixup! rework if/else logic

---
 llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index f745c0a51ac882..2b438a8b134613 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -863,11 +863,10 @@ int main(int argc, char **argv) {
   if (DumpAll)
     DumpType = DIDT_All;
   if (DumpType == DIDT_Null) {
-    if (Verbose)
+    if (Verbose || Verify)
       DumpType = DIDT_All;
     else
-      // If no options are passed, verify everything but dump only debug_info.
-      DumpType = Verify ? DIDT_All : DIDT_DebugInfo;
+      DumpType = DIDT_DebugInfo;
   }
 
   // Unless dumping a specific DIE, default to --show-children.



More information about the llvm-commits mailing list