From: Tony Ambardar <tony.ambardar@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
netdev@vger.kernel.org, "Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
"Mykola Lysenko" <mykolal@fb.com>,
"Shuah Khan" <shuah@kernel.org>, "Björn Töpel" <bjorn@kernel.org>,
"Magnus Karlsson" <magnus.karlsson@intel.com>,
"Maciej Fijalkowski" <maciej.fijalkowski@intel.com>,
"Jonathan Lemon" <jonathan.lemon@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
"Yan Zhai" <yan@cloudflare.com>
Subject: Re: [PATCH bpf-next v1 6/8] selftests/bpf: Fix compile if backtrace support missing in libc
Date: Fri, 26 Jul 2024 20:48:02 -0700 [thread overview]
Message-ID: <ZqRt8jdbWj6oQHov@kodidev-ubuntu> (raw)
In-Reply-To: <CAEf4Bza_y15T4gU=Kiu2d+RbWpxEzrLe6T71bCpK383xHD8JMg@mail.gmail.com>
On Thu, Jul 25, 2024 at 01:22:37PM -0700, Andrii Nakryiko wrote:
> On Thu, Jul 25, 2024 at 3:39 AM Tony Ambardar <tony.ambardar@gmail.com> wrote:
> >
> > From: Tony Ambardar <tony.ambardar@gmail.com>
> >
> > Use backtrace functions only with glibc and otherwise provide stubs in
> > test_progs.c. This avoids compile errors (e.g. with musl libc) like:
> >
> > test_progs.c:13:10: fatal error: execinfo.h: No such file or directory
> > 13 | #include <execinfo.h> /* backtrace */
> > | ^~~~~~~~~~~~
> > test_progs.c: In function 'crash_handler':
> > test_progs.c:1034:14: error: implicit declaration of function 'backtrace' [-Werror=implicit-function-declaration]
> > 1034 | sz = backtrace(bt, ARRAY_SIZE(bt));
> > | ^~~~~~~~~
> > test_progs.c:1045:9: error: implicit declaration of function 'backtrace_symbols_fd' [-Werror=implicit-function-declaration]
> > 1045 | backtrace_symbols_fd(bt, sz, STDERR_FILENO);
> > | ^~~~~~~~~~~~~~~~~~~~
> >
> > Fixes: 9fb156bb82a3 ("selftests/bpf: Print backtrace on SIGSEGV in test_progs")
> > Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
> > ---
> > tools/testing/selftests/bpf/test_progs.c | 9 ++++++++-
> > 1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
> > index 60c5ec0f6abf..f6cfc6a8e8f0 100644
> > --- a/tools/testing/selftests/bpf/test_progs.c
> > +++ b/tools/testing/selftests/bpf/test_progs.c
> > @@ -10,7 +10,6 @@
> > #include <sched.h>
> > #include <signal.h>
> > #include <string.h>
> > -#include <execinfo.h> /* backtrace */
> > #include <sys/sysinfo.h> /* get_nprocs */
> > #include <netinet/in.h>
> > #include <sys/select.h>
> > @@ -19,6 +18,14 @@
> > #include <bpf/btf.h>
> > #include "json_writer.h"
> >
> > +#ifdef __GLIBC__
> > +#include <execinfo.h> /* backtrace */
> > +#else
> > +#define backtrace(...) (0)
> > +#define backtrace_symbols_fd(bt, sz, fd) \
> > + dprintf(fd, "<backtrace not supported>\n", bt, sz)
> > +#endif
>
> First, let's define backtrace() and backtrace_symbols_fd() as proper
> functions, not a macro?
>
> And second, what if we then make those functions __weak, so they
> provide default implementations if libc doesn't provide those
> functions?
>
> This parts seems unavoidable, though:
>
> #ifdef __GLIBC__
> #include <execinfo.h>
> #endif
>
I agree that would be cleaner, will work on a v2 with this.
Out of curiosity, I saw that tools/build includes feature-detection code
(incl backtrace) and wondered if selftests/bpf ever used this facility?
>
> > +
> > static bool verbose(void)
> > {
> > return env.verbosity > VERBOSE_NONE;
> > --
> > 2.34.1
> >
next prev parent reply other threads:[~2024-07-27 3:48 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-25 10:35 [PATCH bpf-next v1 0/8] selftests/bpf: Improve libc portability / musl support (part 2) Tony Ambardar
2024-07-25 10:35 ` [PATCH bpf-next v1 1/8] selftests/bpf: Use portable POSIX basename() Tony Ambardar
2024-07-25 10:35 ` [PATCH bpf-next v1 2/8] selftests/bpf: Fix arg parsing in veristat, test_progs Tony Ambardar
2024-07-25 20:09 ` Andrii Nakryiko
2024-07-27 3:34 ` Tony Ambardar
2024-07-25 10:35 ` [PATCH bpf-next v1 3/8] selftests/bpf: Fix error compiling test_lru_map.c Tony Ambardar
2024-07-25 10:35 ` [PATCH bpf-next v1 4/8] selftests/bpf: Fix C++ compile error from missing _Bool type Tony Ambardar
2024-07-25 10:35 ` [PATCH bpf-next v1 5/8] selftests/bpf: Fix order-of-include compile errors in lwt_reroute.c Tony Ambardar
2024-07-25 20:18 ` Andrii Nakryiko
2024-07-27 3:56 ` Tony Ambardar
2024-07-25 10:35 ` [PATCH bpf-next v1 6/8] selftests/bpf: Fix compile if backtrace support missing in libc Tony Ambardar
2024-07-25 20:22 ` Andrii Nakryiko
2024-07-27 3:48 ` Tony Ambardar [this message]
2024-07-29 17:50 ` Andrii Nakryiko
2024-07-25 10:35 ` [PATCH bpf-next v1 7/8] selftests/bpf: Fix using stdout, stderr as struct field names Tony Ambardar
2024-07-25 20:27 ` Andrii Nakryiko
2024-07-27 4:22 ` Tony Ambardar
2024-07-29 8:48 ` Tony Ambardar
2024-07-25 10:36 ` [PATCH bpf-next v1 8/8] selftests/bpf: Fix error compiling tc_redirect.c with musl libc Tony Ambardar
2024-07-29 9:24 ` [PATCH bpf-next v2 0/8] selftests/bpf: Improve libc portability / musl support (part 2) Tony Ambardar
2024-07-29 9:24 ` [PATCH bpf-next v2 1/8] selftests/bpf: Use portable POSIX basename() Tony Ambardar
2024-07-30 20:50 ` patchwork-bot+netdevbpf
2024-07-29 9:24 ` [PATCH bpf-next v2 2/8] selftests/bpf: Fix arg parsing in veristat, test_progs Tony Ambardar
2024-07-29 9:24 ` [PATCH bpf-next v2 3/8] selftests/bpf: Fix error compiling test_lru_map.c Tony Ambardar
2024-07-29 9:24 ` [PATCH bpf-next v2 4/8] selftests/bpf: Fix C++ compile error from missing _Bool type Tony Ambardar
2024-07-29 9:24 ` [PATCH bpf-next v2 5/8] selftests/bpf: Fix redefinition errors compiling lwt_reroute.c Tony Ambardar
2024-07-29 9:24 ` [PATCH bpf-next v2 6/8] selftests/bpf: Fix compile if backtrace support missing in libc Tony Ambardar
2024-07-29 9:24 ` [PATCH bpf-next v2 7/8] selftests/bpf: Fix using stdout, stderr as struct field names Tony Ambardar
2024-07-29 9:24 ` [PATCH bpf-next v2 8/8] selftests/bpf: Fix error compiling tc_redirect.c with musl libc Tony Ambardar
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=ZqRt8jdbWj6oQHov@kodidev-ubuntu \
--to=tony.ambardar@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=jonathan.lemon@gmail.com \
--cc=kpsingh@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=netdev@vger.kernel.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yan@cloudflare.com \
--cc=yonghong.song@linux.dev \
/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