Skip to content

Addr2line enhance 4#4976

Open
TianlongLiang wants to merge 2 commits into
bytecodealliance:mainfrom
TianlongLiang:addr2line_enhance_4
Open

Addr2line enhance 4#4976
TianlongLiang wants to merge 2 commits into
bytecodealliance:mainfrom
TianlongLiang:addr2line_enhance_4

Conversation

@TianlongLiang

Copy link
Copy Markdown
Contributor

No description provided.

…able overlay

Refactor the wasm symbolicator to make its DWARF workaround explicit
and unconditional. addr2line.py runs one llvm-symbolizer -f -i call
per address, then overlays the outermost frame's function name from a
startup-built DWARF interval table.

The overlay exists because llvm-symbolizer returns the wrong outermost
function name on wasm targets for two independent, source-verified
reasons:

- Symbol-table override on the outermost frame (LLVM design, not a
  bug). symbolizeInlinedCode in llvm/lib/DebugInfo/Symbolize/
  SymbolizableObjectFile.cpp unconditionally rewrites the outermost
  frame's FunctionName from getNameFromSymbolTable when
  FunctionNameKind::LinkageName and UseSymbolTable are both set, which
  is the default. Inline frames come from getInliningInfoForAddress
  (a different code path) and are provably immune.

- AddrDieMap invariant violation from wasm-opt -Oz -g DCE ghosts.
  LocationUpdater::getNewFuncStart in binaryen's src/wasm/wasm-debug.cpp
  returns 0 as a tombstone when an old address doesn't map to a
  surviving IR node, and updateDIE writes it into DW_AT_low_pc without
  removing the DW_TAG_subprogram. LLVM's updateAddressDieMap in
  DWARFUnit.cpp requires child ranges ⊆ parent ranges; these ghosts
  break that invariant so the map's upper_bound − 1 lookup returns
  an insertion-order-dependent DIE.

Both mechanisms produce the same "wrong outermost frame name" symptom
and both apply on any supported wasi-sdk, so the overlay runs on every
resolution. build_subprogram_intervals filters three DIE classes at
parse time: DW_AT_declaration=true (forward decls), low_pc == 0
(DWARF Code-section-relative zero is the function-count LEB, not a
real body — this is the DCE-ghost pattern), and high_pc <= low_pc
(degenerate ranges). The innermost covering DW_TAG_subprogram wins.

Also includes accumulated tool improvements:
- --mode flag {interp,aot,fast-interp} for different runtime offset
  conventions (interp post-advance, aot at-instruction-start,
  fast-interp's transformed in-memory bytecode)
- Inline frame annotation "(inlined into <next>)" for clarity
- llvm-symbolizer preferred over llvm-addr2line for column info
- Fallback for offset=0 (trap at function entry; frame_ip not captured)
- Last-resort function-index name fallback when DWARF lacks PC ranges

Full design rationale, source citations, and empirical truth table in
test-tools/addr2line/README.md.
New test suite at test-tools/addr2line/tests/ exercising addr2line.py
against purpose-built C/C++ sources covering the interval-table
overlay contract and the tool's other behaviors:

- Baseline single-function resolution
- Inline expansion (always_inline, 4-level deep chain)
- Cross-TU LTO inlining (multi-file recursion + wasm-opt -Oz -g,
  which exercises both LLVM outermost-name failure modes)
- Trap inside loop body (DWARF line-table edge case)
- Multi-frame call stack
- C++ symbol demangling
- AOT mode offset math
- fast-interp / --no-addr fallbacks
- offset=0 fallback (trap at function entry)
- Empty input
- Skip-guard invariant on build_subprogram_intervals
  (test_build_subprogram_intervals_filters_invalid_dies): rejects
  DW_AT_declaration=true DIEs, low_pc == 0 (wasm-opt DCE ghosts),
  and high_pc <= low_pc entries at parse time.

Layout:
  test-tools/addr2line/tests/
  ├── README.md              -- documentation
  ├── conftest.py            -- pytest fixtures (sdk discovery, build,
  │                            run_addr2line invocation, multi-sdk
  │                            parametrization)
  ├── test_addr2line.py      -- 12 test cases
  ├── pytest.ini             -- marker definitions (slow, multi_sdk)
  ├── run_tests.sh           -- thin pytest wrapper
  ├── apps/                  -- 8 purpose-built C/C++ sources
  └── fixtures/              -- 3 plaintext call-stack inputs

Sources under apps/ are NOT copied from samples/; they target specific
edge cases independent of sample evolution.

Multi-SDK mode (--multi-sdk) parametrizes build-based tests over every
detected wasi-sdk under /opt to catch DWARF-encoding differences
between clang versions.

Depends on the addr2line.py refactor.
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