bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next] libbpf: Support Debian in resolve_full_path()
Date: Tue, 05 Apr 2022 00:22:13 +0200	[thread overview]
Message-ID: <94ea750cd20efa203a5253b4d6f40a7c7661c87e.camel@linux.ibm.com> (raw)
In-Reply-To: <CAEf4BzZfSUTNAXQM6BcXF6rQGe6LaSfpgiA9uQXu8Fvb3Kk-KQ@mail.gmail.com>

On Mon, 2022-04-04 at 14:58 -0700, Andrii Nakryiko wrote:
> On Mon, Apr 4, 2022 at 3:29 AM Ilya Leoshkevich <iii@linux.ibm.com>
> wrote:
> > 
> > attach_probe selftest fails on Debian-based distros with `failed to
> > resolve full path for 'libc.so.6'`. The reason is that these
> > distros
> > embraced multiarch to the point where even for the "main"
> > architecture
> > they store libc in /lib/<triple>.
> > 
> > This is configured in /etc/ld.so.conf and in theory it's possible
> > to
> > replicate the loader's parsing and processing logic in libbpf,
> > however
> > a much simpler solution is to just enumerate the known library
> > paths.
> > 
> > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> > ---
> >  tools/lib/bpf/libbpf.c | 54 ++++++++++++++++++++++++++++++++++++--
> > ----
> >  1 file changed, 47 insertions(+), 7 deletions(-)
> > 
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index 6d2be53e4ba9..4f616b11564f 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -10707,21 +10707,61 @@ static long elf_find_func_offset(const
> > char *binary_path, const char *name)
> >         return ret;
> >  }
> > 
> > +static void add_debian_library_paths(const char **search_paths,
> > int *n)
> > +{
> > +       /*
> > +        * Based on https://packages.debian.org/sid/libc6.
> > +        *
> > +        * Assume that the traced program is built for the same
> > architecture
> > +        * as libbpf, which should cover the vast majority of
> > cases.
> > +        */
> > +#if defined(__x86_64__)
> 
> can you please also drop defined() where possible, it looks cleaner
> to me:
> 
> #if __x86_64__
> 
> vs
> 
> #if defined(__x86_64__)

The consensus in the existing kernel and tools code (including libbpf
itself) seems to be to use #if defined() or #ifdef for such macros:

$ git grep __x86_64__ | wc -l
306

$ git grep __x86_64__ | grep -v \
    -e '#\s*ifdef __x86_64__' \
    -e 'defined\s*(__x86_64__)' \
    -e '#\s*ifndef __x86_64__' \
    -e '#\s*else' \
    -e '#\s*endif'
arch/x86/Makefile:        CHECKFLAGS += -D__x86_64__
arch/x86/Makefile.um:CHECKFLAGS  += -m64 -D__x86_64__
tools/lib/bpf/libbpf.c:#if __x86_64__
tools/testing/selftests/ipc/Makefile:	CFLAGS := -DCONFIG_X86_64 -
D__x86_64__
tools/testing/selftests/rcutorture/bin/mkinitrd.sh:if echo -e "#if
__x86_64__||__i386__||__i486__||__i586__||__i686__" \
tools/testing/selftests/x86/mov_ss_trap.c:#if __x86_64__

I think `#if __x86_64__` should work in most cases, but I'd rather
stick with the existing style if you don't mind.

  reply	other threads:[~2022-04-04 23:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-04 10:29 [PATCH bpf-next] libbpf: Support Debian in resolve_full_path() Ilya Leoshkevich
2022-04-04 21:40 ` Andrii Nakryiko
2022-04-04 21:58 ` Andrii Nakryiko
2022-04-04 22:22   ` Ilya Leoshkevich [this message]
2022-04-04 22:59     ` Andrii Nakryiko

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=94ea750cd20efa203a5253b4d6f40a7c7661c87e.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.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;
as well as URLs for NNTP newsgroup(s).