Skip to content

feat(dwarf): AddressRemap engine (#143 DWARF Phase 2 inc 3a)#204

Merged
avrabe merged 1 commit into
mainfrom
feat/dwarf-phase2-inc3-gimli-remap
May 29, 2026
Merged

feat(dwarf): AddressRemap engine (#143 DWARF Phase 2 inc 3a)#204
avrabe merged 1 commit into
mainfrom
feat/dwarf-phase2-inc3-gimli-remap

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented May 29, 2026

Summary

The mathematical core of DWARF address remapping. Composes the two anchors already released:

  • v0.16.0 (inc 1): per-function base — component-provenance v2 code_range
  • v0.17.0 (inc 2): intra-function InstrOffsetMap — LEB-drift tracking

into AddressRemap::translate(input_addr) -> Option<output_addr>: an input code-section-relative DWARF address → its fused-output address.

The three offset spaces (the whole game)

meld-core/src/dwarf.rs reconciles:

  1. Input DWARF address — code-section-relative in the source component
  2. Instruction-stream offset — relative to the first instruction (after the locals vector); what InstrOffsetMap keys on
  3. Output DWARF address — merged function base + locals prefix + new instruction-stream offset

The locals-prefix length is identical input↔output (locals are preserved verbatim in the DWARF-remap path), so it cancels — recorded once per FunctionSpan.

Tests (6)

identity offsets · instruction-offset shift (LEB growth) · locals-prefix handling · multi-function selection via BTreeMap range lookup · miss cases (outside functions / mid-instruction / past end) · locals-prefix underflow guard

Scope

This is increment 3a — the engine. Increment 3b wires it into a gimli::write::Dwarf::from(convert_address) rewrite of the .debug_* sections behind a new DwarfHandling::Remap mode. gimli was added then removed in this PR to avoid shipping an unused dependency; it returns in 3b where it's actually used.

Test plan

  • 6 new dwarf::tests green
  • 301 lib tests green, clippy + fmt clean
  • CI green

🤖 Generated with Claude Code

The mathematical core of DWARF address remapping: composes the two
anchors from v0.16.0 (per-function base via component-provenance v2
code_range) and v0.17.0 (intra-function InstrOffsetMap) into one
input→output code-address translation.

  - meld-core/src/dwarf.rs: FunctionSpan + AddressRemap with
    translate(input_addr) -> Option<output_addr>
  - reconciles the three byte-offset spaces (input DWARF address,
    instruction-stream offset, output DWARF address), accounting for
    the locals-prefix length that cancels between input and output
  - BTreeMap range lookup picks the containing function span; misses
    (outside any function, off an instruction boundary, inside the
    locals prefix) return None so the gimli converter drops the
    address rather than emitting a wrong one

6 unit tests: identity offsets, instruction-offset shift (LEB
growth), locals-prefix handling, multi-function selection, miss
cases, and locals-prefix underflow guard.

This is increment 3a (the engine). Increment 3b wires it into a
gimli write::Dwarf::from(convert_address) rewrite of the .debug_*
sections behind a new DwarfHandling::Remap mode. gimli was added then
removed here to avoid shipping an unused dependency — it returns in
3b where it is actually used.

301 lib tests green, clippy + fmt clean.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

LS-N verification gate

⚠️ 35/37 verified — 2 missing regression tests

count
Passed (≥1 test, all green) 35
Failed (≥1 test failure) 0
Missing (no ls_*_NN_* test found) 2

Approved loss-scenarios.yaml entries are expected to have a
regression test named ls_<letter>_<num>_* (e.g. LS-A-11
ls_a_11_*). The gate runs each prefix via cargo test --lib --no-fail-fast and aggregates pass/fail/missing.

Failed LS entries

(none)

Missing regression tests
  • LS-R-13
  • LS-M-6

Updated automatically by tools/post_verification_comment.py.
Source of truth: safety/stpa/loss-scenarios.yaml.

@avrabe avrabe merged commit 58e2c2d into main May 29, 2026
13 of 14 checks passed
@avrabe avrabe deleted the feat/dwarf-phase2-inc3-gimli-remap branch May 29, 2026 06:19
@avrabe avrabe mentioned this pull request May 29, 2026
4 tasks
avrabe added a commit that referenced this pull request May 29, 2026
DWARF Phase 2 increment 3a (#143, #204): the AddressRemap engine —
composes the per-function base (provenance v2 code_range, v0.16.0)
and intra-function InstrOffsetMap (v0.17.0) into input→output
code-address translation. The mathematical core of DWARF address
remapping.

Increment 3b (gimli write::Dwarf::from section rewrite +
DwarfHandling::Remap mode) follows in a later release.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant