public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Hengqi Chen <hengqi.chen@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org, alan.maguire@oracle.com, olsajiri@gmail.com
Subject: Re: [PATCH bpf-next v2 1/3] libbpf: Resolve symbol conflicts at the same offset for uprobe
Date: Sun, 10 Sep 2023 11:53:14 +0200	[thread overview]
Message-ID: <ZP2SCuwKVRf14atN@krava> (raw)
In-Reply-To: <20230905151257.729192-2-hengqi.chen@gmail.com>

On Tue, Sep 05, 2023 at 03:12:55PM +0000, Hengqi Chen wrote:
> Dynamic symbols in shared library may have the same name, for example:
> 
>     $ nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep rwlock_wrlock
>     000000000009b1a0 T __pthread_rwlock_wrlock@GLIBC_2.2.5
>     000000000009b1a0 T pthread_rwlock_wrlock@@GLIBC_2.34
>     000000000009b1a0 T pthread_rwlock_wrlock@GLIBC_2.2.5
> 
>     $ readelf -W --dyn-syms /lib/x86_64-linux-gnu/libc.so.6 | grep rwlock_wrlock
>      706: 000000000009b1a0   878 FUNC    GLOBAL DEFAULT   15 __pthread_rwlock_wrlock@GLIBC_2.2.5
>     2568: 000000000009b1a0   878 FUNC    GLOBAL DEFAULT   15 pthread_rwlock_wrlock@@GLIBC_2.34
>     2571: 000000000009b1a0   878 FUNC    GLOBAL DEFAULT   15 pthread_rwlock_wrlock@GLIBC_2.2.5
> 
> Currently, users can't attach a uprobe to pthread_rwlock_wrlock because
> there are two symbols named pthread_rwlock_wrlock and both are global
> bind. And libbpf considers it as a conflict.
> 
> Since both of them are at the same offset we could accept one of them
> harmlessly. Note that we already does this in elf_resolve_syms_offsets.
> 
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

> ---
>  tools/lib/bpf/elf.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/lib/bpf/elf.c b/tools/lib/bpf/elf.c
> index 9d0296c1726a..5c9e588b17da 100644
> --- a/tools/lib/bpf/elf.c
> +++ b/tools/lib/bpf/elf.c
> @@ -214,7 +214,10 @@ long elf_find_func_offset(Elf *elf, const char *binary_path, const char *name)
> 
>  			if (ret > 0) {
>  				/* handle multiple matches */
> -				if (last_bind != STB_WEAK && cur_bind != STB_WEAK) {
> +				if (elf_sym_offset(sym) == ret) {
> +					/* same offset, no problem */
> +					continue;
> +				} else if (last_bind != STB_WEAK && cur_bind != STB_WEAK) {
>  					/* Only accept one non-weak bind. */
>  					pr_warn("elf: ambiguous match for '%s', '%s' in '%s'\n",
>  						sym->name, name, binary_path);
> --
> 2.34.1

  parent reply	other threads:[~2023-09-10  9:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-05 15:12 [PATCH bpf-next v2 0/3] libbpf: Support symbol versioning for uprobe Hengqi Chen
2023-09-05 15:12 ` [PATCH bpf-next v2 1/3] libbpf: Resolve symbol conflicts at the same offset " Hengqi Chen
2023-09-08 14:30   ` Alan Maguire
2023-09-10  9:53   ` Jiri Olsa [this message]
2023-09-05 15:12 ` [PATCH bpf-next v2 2/3] libbpf: Support symbol versioning " Hengqi Chen
2023-09-08 15:07   ` Alan Maguire
2023-09-10 12:39     ` Hengqi Chen
2023-09-10  9:53   ` Jiri Olsa
2023-09-10 12:42     ` Hengqi Chen
2023-09-05 15:12 ` [PATCH bpf-next v2 3/3] selftests/bpf: Add tests for " Hengqi Chen
2023-09-08 14:40   ` Alan Maguire
2023-09-10  9:53   ` Jiri Olsa

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=ZP2SCuwKVRf14atN@krava \
    --to=olsajiri@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hengqi.chen@gmail.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