Issue 244346
Summary [DWARFVerifier] `--verify` requires a .debug_names entry for a local whose pieces are a constant address value and a stack slot
Labels new issue
Assignees
Reporter clackary
    ## Summary

This is a false positive in the DWARF verifier (`llvm-dwarfdump --verify` / `dsymutil --verify-dwarf`). It's neither a crash nor a miscompile: the generated DWARF is valid, but the verifier rejects it, and that fails dsymutil's output verification.

Since #228574 ("[DWARF] Don't index variables whose address is only their value"), `isVariableIndexable` treats a variable as static storage when both of these are true:

1. `_expression_.isMemoryLocation()`, meaning any piece of the location is a memory location, and
2. the _expression_ contains `DW_OP_addr` (or a TLS op) anywhere in the _expression_.

The two checks are evaluated independently, so they can be satisfied by different pieces. A local whose location is

```
DW_OP_addr X, DW_OP_stack_value, DW_OP_piece 8,   <- constant value (an address used as a value)
DW_OP_breg29 -152, DW_OP_piece 8    <- memory, but a stack slot
```

has no piece at a static address, but the verifier still requires it to be in `.debug_names`. DWARFLinker (correctly) doesn't index it, so `dsymutil`'s output verification fails:

```
error: Name Index @ 0x0: Entry for DIE @ 0x788ed (DW_TAG_variable) with name expectedMultiplied missing.
error: Name Index @ 0x0: Entry for DIE @ 0x78943 (DW_TAG_variable) with name expectedDivided missing.
error: Name Index @ 0x0: Entry for DIE @ 0x784fb (DW_TAG_variable) with name expectedMultiplied missing.
error: Name Index @ 0x0: Entry for DIE @ 0x78551 (DW_TAG_variable) with name expectedDivided missing.
error: output verification failed for arm64
```

The comment on the existing `var_mixed_piece` test case states the intended rule: "a piece that does live at an address does [call for an index entry]". Every existing test case has either no memory piece or a memory piece that *is* the `DW_OP_addr`. None has a non-static memory piece next to an `addr; stack_value` piece, so this case isn't covered.


## Reproducer

This needs `llvm-mc` and `llvm-dwarfdump` from a build that includes #228574, such as current `main`. Older versions use the previous rule and also report `value_and_register`. `repro.s` (below) has two locals. Each is made of two 8-byte pieces, and the first piece of each is a constant address used as a value (`DW_OP_addr; DW_OP_stack_value`). The second piece is a stack slot in one variable and a register in the other. Neither variable has static storage, so neither needs a `.debug_names` entry.

```sh
llvm-mc -triple x86_64-pc-linux -filetype=obj repro.s -o repro.o
llvm-dwarfdump --verify repro.o
```

Expected: no errors. Only the usual `Name Index @ 0x0 does not contain a hash table` warning should appear.

Actual: the variable with the stack-slot piece is reported, and the one with the register piece isn't:

```
Verifying .debug_names...
warning: Name Index @ 0x0 does not contain a hash table.
error: Name Index @ 0x0: Entry for DIE @ 0xc (DW_TAG_variable) with name value_and_stack_slot missing.
error: Aggregated error counts:
error: Name Index DIE entry missing name occurred 1 time(s).
Errors detected.
```

This output is from `llvm-mc` and `llvm-dwarfdump` built from swiftlang/llvm-project at the tag `swift-DEVELOPMENT-SNAPSHOT-2026-11-01-a`, on arm64 macOS. The verifier code involved (`isVariableIndexable`, which uses `DWARFExpression::isMemoryLocation`) is identical on llvm/llvm-project `main`.

<details>
<summary><code>repro.s</code></summary>

```asm
# Two locals, each made of two 8-byte pieces. The first piece of each is a
# constant address used as a value (DW_OP_addr; DW_OP_stack_value). The second
# piece is a stack slot in one variable and a register in the other. Neither
# variable has static storage, so neither needs a .debug_names entry.
#
#   llvm-mc -triple x86_64-pc-linux -filetype=obj repro.s -o repro.o
#   llvm-dwarfdump --verify repro.o

        .section .debug_abbrev,"",@progbits
        .byte   1                       # Abbreviation Code
        .byte   17                      # DW_TAG_compile_unit
        .byte   1                       # DW_CHILDREN_yes
        .byte   0                       # EOM(1)
 .byte   0                       # EOM(2)
        .byte   2 # Abbreviation Code
        .byte   52                      # DW_TAG_variable
        .byte   0                       # DW_CHILDREN_no
 .byte   3                       # DW_AT_name
        .byte   8 # DW_FORM_string
        .byte   2                       # DW_AT_location
        .byte   24                      # DW_FORM_exprloc
 .byte   0                       # EOM(1)
        .byte   0 # EOM(2)
        .byte   0                       # EOM(3)

 .section        .debug_info,"",@progbits
.Lcu_begin0:
        .long .Lcu_end0-.Lcu_start0   # Length of Unit
.Lcu_start0:
        .short  4 # DWARF version number
        .long   .debug_abbrev # Offset Into Abbrev. Section
        .byte   8                       # Address Size (in bytes)
        .byte   1                       # Abbrev [1] DW_TAG_compile_unit

        .byte   2                       # Abbrev [2] DW_TAG_variable
        .asciz  "value_and_stack_slot"  # DW_AT_name
 .byte   .Lloc1_end-.Lloc1       # DW_AT_location
.Lloc1:
        .byte 0x03                    # DW_OP_addr
        .quad   0x47
        .byte 0x9f                    # DW_OP_stack_value
        .byte   0x93, 8 # DW_OP_piece 8
        .byte   0x77, 0x78              # DW_OP_breg7 RSP-8
        .byte   0x93, 8                 # DW_OP_piece 8
.Lloc1_end:

        .byte   2                       # Abbrev [2] DW_TAG_variable
        .asciz  "value_and_register"    # DW_AT_name
 .byte   .Lloc2_end-.Lloc2       # DW_AT_location
.Lloc2:
        .byte 0x03                    # DW_OP_addr
        .quad   0x47
        .byte 0x9f                    # DW_OP_stack_value
        .byte   0x93, 8 # DW_OP_piece 8
        .byte   0x50                    # DW_OP_reg0 RAX
        .byte   0x93, 8                 # DW_OP_piece 8
.Lloc2_end:

 .byte   0                       # End Of Children Mark
.Lcu_end0:

 .section        .debug_names,"",@progbits
        .long .Lnames_end0-.Lnames_start0 # Header: contribution length
.Lnames_start0:
 .short  5                       # Header: version
        .short  0 # Header: padding
        .long   1 # Header: compilation unit count
        .long   0                       # Header: local type unit count
        .long   0                       # Header: foreign type unit count
        .long   0                       # Header: bucket count
        .long   0                       # Header: name count
        .long   .Lnames_abbrev_end0-.Lnames_abbrev_start0 # Header: abbreviation table size
        .long   0                       # Header: augmentation length
        .long   .Lcu_begin0             # Compilation unit 0
.Lnames_abbrev_start0:
        .byte   0                       # End of abbrev list
.Lnames_abbrev_end0:
.Lnames_end0:
```

</details>

### Real-world (Swift, dsymutil)

Found with `swift-DEVELOPMENT-SNAPSHOT-2026-11-01-a` building a package's tests with `swift build --build-tests -c release` on arm64 macOS (Xcode 27.1 SDK). Release only; debug builds are fine.

The test code holds the result of a derivative function, a `(value: T, pullback: (T) -> (T, T))` tuple, in a local. The pullback closure captures two values, and at `-O` its context gets saved to the stack. The local's location list in the linked dSYM:

```
0x000784fb: DW_TAG_variable
  DW_AT_location (0x00000535:
 [0xbef8, 0xbf04): DW_OP_piece 0x10, DW_OP_reg0 W0, DW_OP_piece 0x8
 [0xbf04, 0xbf20): DW_OP_constu 0xbff2000000000000, DW_OP_stack_value, DW_OP_piece 0x8, DW_OP_addr 0xe124, DW_OP_stack_value, DW_OP_piece 0x8, DW_OP_reg0 W0, DW_OP_piece 0x8
     [0xbf20, 0xc068): DW_OP_constu 0xbff2000000000000, DW_OP_stack_value, DW_OP_piece 0x8, DW_OP_addr 0xe124, DW_OP_stack_value, DW_OP_piece 0x8, DW_OP_reg24 W24, DW_OP_piece 0x8
 [0xc068, 0xc6ec): DW_OP_constu 0xbff2000000000000, DW_OP_stack_value, DW_OP_piece 0x8, DW_OP_addr 0xe124, DW_OP_stack_value, DW_OP_piece 0x8, DW_OP_breg29 W29-152, DW_OP_piece 0x8)
  DW_AT_name ("expectedMultiplied")
```

`0xe124` is a partial-apply forwarder (`$sS3dIegnrr_S3dIegydd_TRTA`), i.e. the closure's function pointer, used as a value. Only the last range has a memory piece (`breg29`), and that range is enough to trigger the error.

Similar locals in the same function confirm the pattern; none of them is flagged:
- Closures that capture nothing have a `DW_OP_lit0` context piece.
- Closures that capture one value keep the context in a register (`reg23`/`reg24`) for the whole range.

Exactly the four DIEs that have an `addr; stack_value` piece next to a `breg` piece are flagged.

## Workaround for users

Build without full debug info for affected targets (`-gline-tables-only`, or skip dSYM generation).

## AI assistance

I found the original failure in a real project build, and used the robot to distill a representative reproducer, which I ran myself to validate. It was used to generate this issue, which I have reviewed and curated for relevance. I am more familiar with the swiftlang dev process, but I have reviewed LLVM's bug report and AI policy docs before submitting.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to