[llvm] [DWARFVerifier] Verify that DW_AT_LLVM_stmt_sequence is set correctly (PR #152807)

Greg Clayton via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 13 16:38:03 PDT 2025


================
@@ -851,6 +851,52 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
     }
     break;
   }
+  case DW_AT_LLVM_stmt_sequence: {
+    // Make sure the offset in the DW_AT_LLVM_stmt_sequence attribute is valid
+    // and points to a valid sequence start in the line table.
+    auto SectionOffset = AttrValue.Value.getAsSectionOffset();
+    if (!SectionOffset) {
+      ReportError("Invalid DW_AT_LLVM_stmt_sequence encoding",
+                  "DIE has invalid DW_AT_LLVM_stmt_sequence encoding:");
+      break;
+    }
+    if (*SectionOffset >= U->getLineSection().Data.size()) {
+      ReportError(
+          "DW_AT_LLVM_stmt_sequence offset out of bounds",
+          "DW_AT_LLVM_stmt_sequence offset is beyond .debug_line bounds: " +
----------------
clayborg wrote:

This should probably check if the DW_AT_LLVM_stmt_sequence is inside the current line table only? The .debug_line section conttains multiple line tables, each one has a prologue and then N sequences. We want to make sure the `*SectionOffset` is after the prologue and before the end of all sequences. Each line table prologue contains:

```
dwarfdump --debug-line a.out.dSYM -v
a.out.dSYM/Contents/Resources/DWARF/a.out:	file format Mach-O arm64

.debug_line contents:
debug_line[0x00000000]
Line table prologue:
    total_length: 0x00000055
          format: DWARF32
         version: 5
    address_size: 8
 seg_select_size: 0
 prologue_length: 0x00000037
```
The `total_length` tells us where the this line table's data ends. And the `prologue_length` tells us where the prologue ends. So we want to make sure that the `*SectionOffset` is between the end of the prologue and the and of the current line table, not the entire .debug_line section

https://github.com/llvm/llvm-project/pull/152807


More information about the llvm-commits mailing list