Repository navigation
[rocprofiler-sdk-rocattach] Fix wrong library base in find_library() - #5413
Merged
adjordje-amd merged 1 commit intoApr 27, 2026
Merged
Conversation
find_library() scans /proc/<pid>/maps and returns the start address of the first line whose path contains the library name. A shared library normally has multiple maps entries (one per page-protection segment), of which only the segment whose file offset is 0 is the actual library load base. When the runtime adds extra writable file-backed mappings of the same library at non-zero file offsets (e.g. for code patching) at addresses below the original load mapping, those entries appear first in the maps file (which is sorted by address) and the linear scan returns the wrong base. Symbol resolution then computes target_addr = wrong_base + offset, which lands in unrelated memory and SIGSEGVs the injected call. Filter the scan to lines whose file offset (the third whitespace- separated field) is 0. There is exactly one such mapping per loaded library, regardless of any extra shadow mappings at other offsets.
adjordje-amd
force-pushed
the
users/adjordje-amd/rocattach-symbol-lookup-fix
branch
from
April 24, 2026 11:17
e310e10 to
70783d9
Compare
3 tasks done
adjordje-amd
marked this pull request as ready for review
April 24, 2026 14:15
ammarwa
approved these changes
Apr 27, 2026
meserve-amd
approved these changes
Apr 27, 2026
meserve-amd
left a comment
Contributor
There was a problem hiding this comment.
Seems sensible. The old code assumed the entries would be in order but that is not a guarantee. Good find.
CI failure in rhel is intermittent and unrelated; I reran it to get a pass.
adjordje-amd
added a commit
that referenced
this pull request
Oct 12, 2026
…h/re-attach) (#5414) ## Motivation `rocprof-sys-attach` (the rocattach codepath) had no automated test coverage. This PR adds a parametrized pytest exercising attach, detach, and re-attach against a long-running HIP target. ## Technical Details - `tests/pytest/test_rocattach.py` (new): spawns `transpose` in infinite mode, runs `n_sessions` attach sessions (`n_sessions = 1, 2, 3`) via `rocprof-sys-attach`, asserts each session produces an output directory containing a perfetto trace and that the target survives. - `tests/pytest/rocprofsys/config.py`: adds optional `rocprofsys_attach: Path` field; tests that need it skip when the binary is not built. - `source/bin/rocprof-sys-attach/rocprof-sys-attach.cpp`: adds `--detach-after <seconds>` flag for non-interactive use; sleeps instead of waiting for ENTER on stdin. - `examples/transpose/transpose.cpp`: passing `0` for `NUM_ITERATION` enables infinite mode; `SIGTERM`/`SIGINT` stops the loop cleanly. ## Dependencies - #5413 - `find_library()` fix in `rocprofiler-sdk-rocattach`. Required for `n_sessions = 1` to pass. - An additional ptrace state-machine failure in the rocattach detach path that prevents `n_sessions = 2` and `n_sessions = 3` from passing. Root cause not yet identified; tracking separately. ## JIRA N/A ## Test Plan ```bash ctest --test-dir <BUILD_DIR> -R rocattach -V ``` Verify all three parametrized cases (`n_sessions = 1, 2, 3`) pass. ## Test Result ## Checklist - [x] Test added under `tests/pytest/test_rocattach.py` - [x] CHANGELOG entry - [x] Test skips gracefully when GPU is unavailable, `ptrace_scope` is non-zero, or the `rocprof-sys-attach` binary is not built
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.
Motivation
find_library()returns the wrong load base when multiple/proc/<pid>/mapslines mention the library. The current code takes the first match. By definition, the load base is the line whose file offset is0.When the runtime adds extra file-backed mappings of the same library at non-zero file offsets at addresses below the original load (observed during attach setup of
librocprofiler-register.so), symbol resolution computeswrong_base + symbol_offset, lands in unrelated memory, and SIGSEGVs the injected ptrace call. The dying thread leaves the ptrace state machine unrecoverable,PTraceSession::~PTraceSessionthrows during cleanup, and the attacher aborts.Technical Details
Filter the
/proc/<pid>/mapsscan to entries whose file offset is0. This is the unique discriminator for the library load base, robust to any number of extra shadow mappings at other offsets.Replace the implicit
if (!maps)no-match detection with an explicitfoundflag. The new filter would otherwise let a substring-matching but offset-nonzero line reachstd::stoull(line, ...)and silently return a wrong address.JIRA
N/A
Test Plan
Manual repro with
rocprof-sys-attach -p <PID> -d 5against a HIP target launched withROCP_TOOL_ATTACH=1.Test Result
rocattach_detachSIGSEGVs in target on first detach, attacher dies with SIGABRT.Checklist