From: Alan Maguire <alan.maguire@oracle.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alan Maguire <alan.maguire@oracle.com>,
Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, Martin Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
john fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
Yucong Sun <sunyucong@gmail.com>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH v3 bpf-next 1/4] libbpf: support function name-based attach uprobes
Date: Fri, 25 Feb 2022 16:12:14 +0000 (GMT) [thread overview]
Message-ID: <alpine.LRH.2.23.451.2202251559000.14550@MyRouter.home> (raw)
In-Reply-To: <CAEf4BzY-Q1SbrKXg-9GZ=2=Gh9kxocmzksn8Xib+rJYs+WSGiQ@mail.gmail.com>
On Fri, 4 Feb 2022, Andrii Nakryiko wrote:
> On Mon, Jan 31, 2022 at 8:13 AM Alan Maguire <alan.maguire@oracle.com> wrote:
> >
> > kprobe attach is name-based, using lookups of kallsyms to translate
> > a function name to an address. Currently uprobe attach is done
> > via an offset value as described in [1]. Extend uprobe opts
> > for attach to include a function name which can then be converted
> > into a uprobe-friendly offset. The calcualation is done in
> > several steps:
> >
> > 1. First, determine the symbol address using libelf; this gives us
> > the offset as reported by objdump; then, in the case of local
> > functions
> > 2. If the function is a shared library function - and the binary
> > provided is a shared library - no further work is required;
> > the address found is the required address
> > 3. If the function is a shared library function in a program
> > (as opposed to a shared library), the Procedure Linking Table
> > (PLT) table address is found (it is indexed via the dynamic
> > symbol table index). This allows us to instrument a call
> > to a shared library function locally in the calling binary,
> > reducing overhead versus having a breakpoint in global lib.
> > 4. Finally, if the function is local, subtract the base address
> > associated with the object, retrieved from ELF program headers.
> >
> > The resultant value is then added to the func_offset value passed
> > in to specify the uprobe attach address. So specifying a func_offset
> > of 0 along with a function name "printf" will attach to printf entry.
> >
> > The modes of operation supported are then
> >
> > 1. to attach to a local function in a binary; function "foo1" in
> > "/usr/bin/foo"
> > 2. to attach to a shared library function in a binary;
> > function "malloc" in "/usr/bin/foo"
> > 3. to attach to a shared library function in a shared library -
> > function "malloc" in libc.
> >
> > [1] https://www.kernel.org/doc/html/latest/trace/uprobetracer.html
> >
> > Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> > ---
>
> This looks great and very clean. I left a few nits, but otherwise it
> looks ready (still need to go through the rest of the patches)
>
> > tools/lib/bpf/libbpf.c | 250 +++++++++++++++++++++++++++++++++++++++++++++++++
> > tools/lib/bpf/libbpf.h | 10 +-
> > 2 files changed, 259 insertions(+), 1 deletion(-)
> >
>
<snip>
> if both the symbol name and requested function name have @ in them,
> what should be the comparison rule? Shouldn't it be an exact match
> including '@@' and part after it?
>
In this case, we might want to support matching on malloc@GLIBC and
malloc@GLIBC_2.3.4; in other words letting the caller decide how
specific they want to be makes sense I think. So the caller dictates
the matching length via the argument they provide - with the proviso that
if it's just a function name without a "@LIBRARY" suffix it must match
fully. The problem with the version numbers associated with functions is
they're the versions from the mapfiles, so the same library version has
malloc@GLIBC_2.2.5, epoll_ctl@GLIBC_2.3.2 etc.
Thanks for the review! I'm working on incorporating all of these changes
into v4 now.
Alan
next prev parent reply other threads:[~2022-02-25 16:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-31 16:12 [PATCH v3 bpf-next 0/4] libbpf: name-based u[ret]probe attach Alan Maguire
2022-01-31 16:12 ` [PATCH v3 bpf-next 1/4] libbpf: support function name-based attach uprobes Alan Maguire
2022-02-04 19:17 ` Andrii Nakryiko
2022-02-25 16:12 ` Alan Maguire [this message]
2022-01-31 16:12 ` [PATCH v3 bpf-next 2/4] libbpf: add auto-attach for uprobes based on section name Alan Maguire
2022-02-04 19:22 ` Andrii Nakryiko
2022-02-23 9:32 ` Alan Maguire
2022-02-24 1:49 ` Andrii Nakryiko
2022-02-24 15:39 ` Alan Maguire
2022-03-01 1:45 ` Andrii Nakryiko
2022-01-31 16:12 ` [PATCH v3 bpf-next 3/4] selftests/bpf: add get_lib_path() helper Alan Maguire
2022-02-04 19:24 ` Andrii Nakryiko
2022-01-31 16:12 ` [PATCH v3 bpf-next 4/4] selftests/bpf: add tests for u[ret]probe attach by name Alan Maguire
2022-02-04 19:30 ` Andrii Nakryiko
2022-02-26 16:00 ` Jiri Olsa
2022-02-01 8:52 ` [PATCH v3 bpf-next 0/4] libbpf: name-based u[ret]probe attach Daniel Borkmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LRH.2.23.451.2202251559000.14550@MyRouter.home \
--to=alan.maguire@oracle.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=sunyucong@gmail.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox