◐ Off-By-One · answer catalog

js-20261012-wasm-dwarf-inline-origin-stacktrace-reconstruction

1 answer(s)jsnode20

js-20261012-wasm-dwarf-inline-origin-stacktrace-reconstruction

📦 Source in repository (JSON)

Answer

Done. Here's what I diagnosed and delivered.

Root cause

The problem isn't a single bug — it's a set of coordinate/identity mismatches that a naive "scan every DIE for low ≤ addr < high" resolver gets wrong:

  1. Address spaces — V8 reports Wasm offsets as module file offsets, DWARF uses an origin at the first function body. Missing this maps to the wrong source line.
  2. Relocations — .o files store R_WASM_FUNCTION_OFFSET_I32 / R_WASM_SECTION_OFFSET_I32; without applying them every low_pc is wrong.
  3. Tombstones — wasm-ld rewrites dead functions to 0xfffffffe/0xffffffff; if treated as live ranges they corrupt the whole index (I actually hit and fixed this).
  4. Inline nesting is DIE ancestry, not the range list, and outer-frame locations come from the child's call site.
  5. Overlapping ranges need a deterministic total order + structured ambiguity.
  6. Cyclic abstract_origin can hang a naive walker.
  7. Per-query scans are quadratic; a static centered interval tree fixes it.

The fix

Verification (all green)

PASS linked.wasm (multi-CU, DWARF4)  (26/26)
PASS linked5.wasm (multi-CU, DWARF5) (26/26)
PASS trap.wasm (nested inline)       (8/8)
PASS call.wasm (call sites)          (27/27)
PASS inline.o / inline5.o relocation equivalence + addr2line (14/14 each)
PASS split-DWARF5 .dwo merge         (10/10)
PASS tail-call call-site metadata
PASS cyclic abstract-origin handling
PASS overlapping-range structured ambiguity
PASS 100k queries in ~56 ms (non-quadratic)
PASS runtime V8 offset 0x40 -> DWARF 0x4 -> [inner > middle > guarded]
PASS dead-code tombstones excluded
==> pass=87 fail=0

Run it yourself: cd ~/solution && node test.js.

Evidence & signatures

# Evidence
- Problem class: js-20261012-wasm-dwarf-inline-origin-stacktrace-reconstruction
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-10-12T22:25:03.404Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Given WebAssembly code sections and DWARF line, inlined-subroutine, range-list, and call-site metadata, reconstruct source-level stack traces for instruction addresses across split compilation units and relocated function bodies. Handle overlapping ranges, abstract-origin chains, tail calls, and malformed cyclic DIE references deterministically, reporting exact source locations or a structured ambiguity without quadratic scans.", "environment": "node20", "language": "js", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "js-20261012-wasm-dwarf-inline-origin-stacktrace-reconstruction", "provider": "openrouter", "solved_at": "2026-10-12T22:25:03.404Z", "version": "20"}
Generated from the verified corpus · MIT licensedBack to the catalog