tools/bashreadline: auto-detect libreadline.so for dynamically linked bash#5517
Open
xuchunmei000 wants to merge 1 commit into
Open
tools/bashreadline: auto-detect libreadline.so for dynamically linked bash#5517xuchunmei000 wants to merge 1 commit into
xuchunmei000 wants to merge 1 commit into
Conversation
… bash On systems where /bin/bash dynamically links libreadline (which is the common case on modern distros), the `readline` symbol in the bash ELF is merely an undefined import (SHN_UNDEF, st_value=0). BCC's attach_uretprobe then fails with: Exception: could not determine address of symbol readline in /bin/bash The tool already provides a `-s` flag for users to manually specify the libreadline.so path, but this is inconvenient and breaks automated smoke tests. This patch adds automatic detection: after resolving the symbol name, it checks whether the symbol is actually defined (not just imported) in the target binary. If not, it uses `ldd /bin/bash` to find the real libreadline.so path and redirects the uprobe there. The logic is backward-compatible: - If bash statically links readline -> symbol is defined, no change - If user passes `-s` -> manual path used, no auto-detection - If bash dynamically links readline -> auto-fallback to .so
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.
On systems where /bin/bash dynamically links libreadline (which is the common case on modern distros), the
readlinesymbol in the bash ELF is merely an undefined import (SHN_UNDEF, st_value=0). BCC's attach_uretprobe then fails with:Exception: could not determine address of symbol readline in /bin/bash
The tool already provides a
-sflag for users to manually specify the libreadline.so path, but this is inconvenient and breaks automated smoke tests.This patch adds automatic detection: after resolving the symbol name, it checks whether the symbol is actually defined (not just imported) in the target binary. If not, it uses
ldd /bin/bashto find the real libreadline.so path and redirects the uprobe there.The logic is backward-compatible:
-s-> manual path used, no auto-detectionDescription
Why this approach
Checklist
tools/toolname:,libbpf-tools/toolname:,src/cc:,docs:,build:,tests/python:)For new tools only
man/man8/) with an OVERHEAD section*_example.txt)tests/python/test_tools_smoke.py