addr2line: enhance call-stack symbolicator, samples, tests, and CI#4972
Open
TianlongLiang wants to merge 1 commit into
Open
addr2line: enhance call-stack symbolicator, samples, tests, and CI#4972TianlongLiang wants to merge 1 commit into
TianlongLiang wants to merge 1 commit into
Conversation
Contributor
Author
|
This is all in one PR; I will break it into a series of PRs so it is easier to review |
c5c05bd to
8f161d0
Compare
…nd CI
Refactor test-tools/addr2line/addr2line.py to make its DWARF workaround
explicit and unconditional, add two verify.sh-backed samples that
exercise it end-to-end, add a pytest suite, and wire the whole thing
into CI.
## addr2line.py
Every resolution 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:
1. 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.
2. `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 any
real function body — 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 rationale, source citations, and empirical truth table in
test-tools/addr2line/README.md.
## samples/debug-tools (refresh)
- README documents the --mode flag, inline expansion behavior, and
points at the tool README for the overlay rationale.
- symbolicate.sh passes --mode aot for the AOT call-stack invocation.
- verify.sh (new): assertion-based smoke test that runs symbolicate.sh
and grep-checks for inline expansion (trap_helper) in both wasm and
AOT outputs. Replaces the inline CI assertions.
- wasm-apps/trap.c adds a trap_helper marked always_inline that the
trap site falls inside, so addr2line.py can demonstrate inline-frame
annotation against this sample.
## samples/debug-tools-optimized (new)
Self-contained sample demonstrating the full production-debug workflow
for optimized WASM:
- 4-step build pipeline (clang -Oz -g -flto → wasm-opt -Oz -g →
llvm-strip → wamrc) producing prod.wasm + prod.aot + debug.wasm
companion artifacts.
- Two test apps (oob, stackoverflow) split into multi-file C sources
to exercise cross-TU LTO inlining.
- USE_FAST_INTERP CMake option to build iwasm in classic or fast-interp
mode.
- symbolicate.sh: end-to-end driver.
- verify.sh: per-(app, mode) assertion that the symbolicated output
contains the expected source files.
## test-tools/addr2line/tests (new)
pytest suite at test-tools/addr2line/tests/ exercising addr2line.py
against purpose-built C/C++ sources covering:
- Baseline single-function resolution
- Inline expansion (always_inline, 4-level 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: rejects
DW_AT_declaration=true DIEs, low_pc == 0 (wasm-opt DCE ghosts),
and high_pc <= low_pc entries at parse time.
Multi-SDK mode (--multi-sdk) parametrizes build-based tests over every
detected wasi-sdk under /opt to catch DWARF-encoding differences
between clang versions.
## CI
compilation_on_android_ubuntu.yml:
- Existing build_samples_others step (debug-tools) now calls verify.sh
instead of inline grep assertions.
- New build_samples_debug_tools_optimized job: builds the new sample
twice (classic-interp and fast-interp) and runs verify.sh
oob/stackoverflow × wasm/aot for each.
- New addr2line_tests job: runs the pytest suite against the default
wasi-sdk on every PR.
nightly_run.yml:
- New addr2line_tests_multi_sdk job: installs wasi-sdk 29.0 (clang 21)
and 33.0 (clang 22) side by side and runs the test suite with
--multi-sdk.
8f161d0 to
8f033d9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor test-tools/addr2line/addr2line.py to reliably symbolicate WAMR call stacks across the wasi-sdk versions WAMR supports (29+), and add test infrastructure plus two end-to-end debug-tools samples that exercise the workflow.
addr2line.py:
recursereported asfree) for addresses overlapping wasi-libc declarations.--no-addr(function-name lookup) prefers non-sysroot candidates so short user-code names (a,b,c) don't collide with wasi-libc helpers in the DWARF.-v/--verbosegates the dispatch-decision log; default silent.samples/debug-tools (refresh):
make -jrace in wasm-apps/CMakeLists.txt (explicit add_dependencies for the AOT custom target).samples/debug-tools-optimized (new):
clang -Oz -g -fltothenwasm-opt -Oz -gto produce a stripped .prod.wasm plus a DWARF companion (.debug.wasm) with byte-identical code.test-tools/addr2line/tests (new):
CI:
wasi_sdk_versioninput lets callers pin a version when needed.Documentation: