Skip to content

tools/bashreadline: auto-detect libreadline.so for dynamically linked bash#5517

Open
xuchunmei000 wants to merge 1 commit into
iovisor:masterfrom
xuchunmei000:master
Open

tools/bashreadline: auto-detect libreadline.so for dynamically linked bash#5517
xuchunmei000 wants to merge 1 commit into
iovisor:masterfrom
xuchunmei000:master

Conversation

@xuchunmei000
Copy link
Copy Markdown
Contributor

@xuchunmei000 xuchunmei000 commented Jun 1, 2026

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

Description

Why this approach


Checklist

  • Commit prefix matches changed area (e.g., tools/toolname:, libbpf-tools/toolname:, src/cc:, docs:, build:, tests/python:)
  • Commit body explains why this change is needed

For new tools only

  • Explains why this tool is needed and what existing tools cannot cover this use case
  • Includes at least one real production use case
  • Man page (man/man8/) with an OVERHEAD section
  • Example output file (*_example.txt)
  • README.md entry added
  • Smoke test added to tests/python/test_tools_smoke.py

About AI Code Review: This project uses GitHub Copilot to assist with code review.
If a Copilot review is added, treat its feedback as you would any reviewer comment — you can
agree, disagree (with explanation), or ask questions. The maintainer makes all final decisions.

… 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
@xuchunmei000 xuchunmei000 changed the title bashreadline: auto-detect libreadline.so for dynamically linked bash tools/bashreadline: auto-detect libreadline.so for dynamically linked bash Jun 1, 2026
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