Skip to content

Commit

Permalink
[DWARFDump] Make --verify handle all sections by default (#81559)
Browse files Browse the repository at this point in the history
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
#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".
  • Loading branch information
felipepiovezan committed Feb 13, 2024
1 parent 2400f70 commit 5296149
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion llvm/test/DebugInfo/X86/dwarfdump-str-offsets.s
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/DebugInfo/X86/skeleton-unit-verify.s
Original file line number Diff line number Diff line change
Expand Up @@ -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,"",@progbits
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/tools/llvm-dwarfdump/X86/verify_file_encoding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 5 additions & 2 deletions llvm/test/tools/llvm-dwarfutil/ELF/X86/dwarf5-macro.test
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ int main(int argc, char **argv) {
if (DumpAll)
DumpType = DIDT_All;
if (DumpType == DIDT_Null) {
if (Verbose)
if (Verbose || Verify)
DumpType = DIDT_All;
else
DumpType = DIDT_DebugInfo;
Expand Down

0 comments on commit 5296149

Please sign in to comment.