Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uprobes: automatic resolution of library paths #1971

Merged
merged 3 commits into from
Aug 17, 2021

Conversation

viktormalik
Copy link
Contributor

@viktormalik viktormalik commented Aug 11, 2021

This introduces an option to attach to library functions by specifying just the library name instead of a full path. For example:

# bpftrace -e 'uprobe:libc:malloc { printf("Allocated %d bytes\n", arg0); }'
Allocated 4 bytes                              
...  

One of the use-cases is a better portability of scripts that attach to library functions (as the full library paths may differ across systems). For example, the current tools/gethostlatency.bt doesn't work on Fedora.

Unfortunately, our shipped tools cannot be updated right away since this feature relies on BCC's bcc_procutils_which_so which is not available on old BCC versions, especially not those used in the CI. If #1933 was resolved, it would be possible.

Checklist
  • Language changes are updated in man/adoc/bpftrace.adoc and if needed in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

@vchuravy
Copy link

Does this also work for libraries that are dlopened?

@viktormalik
Copy link
Contributor Author

Does this also work for libraries that are dlopened?

The library paths are searched for in /etc/ld.so.cache so it depends whether the dlopen'ed library's there. According to the man page, the cache should contain libraries from standard paths and from directories listed in /etc/ld.so.conf.

Copy link
Member

@danobi danobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feature!

Comment on lines 1111 to 1112
When tracing libraries, it is sufficient to specify the library name instead of
a full path.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also mention the lookup is done via ldcache? This may be important for systems that have multiple versions of a library installed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont forget to mirror this to the manpage too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points. Updated, please check.

@@ -115,7 +115,7 @@ def __read_test_struct(test, test_suite):
elif item_name == 'ARCH':
arch = [x.strip() for x in line.split("|")]
elif item_name == 'REQUIRES_FEATURE':
features = {"loop", "btf", "probe_read_kernel", "dpath", "uprobe_refcount", "signal", "iter:task", "iter:task_file"}
features = {"loop", "btf", "probe_read_kernel", "dpath", "uprobe_refcount", "signal", "iter:task", "iter:task_file", "libpath_resolv"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you break this up into multiple lines, please?

RUN {{BPFTRACE}} -e 'uprobe:libc:write { printf("size: %d\n", arg0); exit(); }'
EXPECT size: [0-9]+
TIMEOUT 5
AFTER cat /etc/passwd > /dev/null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write a testprog for this instead? Don't want this test to flake out on us in the future if cat changes.

Uses BCC to resolve a library name into its full path. We require that
the library XXX is specified in the form "libXXX".
Example: "uprobe:libc:malloc".
Since automatic resolution depends on a BCC capability, a new feature
had to be added to the runtime tests framework.

Also, embedded Alpine builds do not have a shared libc so we must
disable the new test for them.
@viktormalik viktormalik requested review from fbs and danobi August 16, 2021 14:36
@fbs fbs merged commit 17fc5e9 into bpftrace:master Aug 17, 2021
@viktormalik viktormalik deleted the uprobe-libs-resolve branch November 24, 2021 12:31
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.

4 participants