bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 1/2] libbpf: Do not use btf_dump__new macro for c++ objects
@ 2021-12-23 13:17 Jiri Olsa
  2021-12-23 13:17 ` [PATCH bpf-next 2/2] selftests/bpf: Add btf_dump__new to test_cpp Jiri Olsa
  2021-12-23 16:13 ` [PATCH bpf-next 1/2] libbpf: Do not use btf_dump__new macro for c++ objects Yonghong Song
  0 siblings, 2 replies; 5+ messages in thread
From: Jiri Olsa @ 2021-12-23 13:17 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: netdev, bpf, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh

As reported in here [0], C++ compilers don't support __builtin_types_compatible_p(),
so at least don't screw up compilation for them and let C++ users
pick btf_dump__new vs btf_dump__new_deprecated explicitly.

[0] https://github.com/libbpf/libbpf/issues/283#issuecomment-986100727
Fixes: 6084f5dc928f ("libbpf: Ensure btf_dump__new() and btf_dump_opts are future-proof")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/lib/bpf/btf.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 742a2bf71c5e..061839f04525 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -313,12 +313,18 @@ LIBBPF_API struct btf_dump *btf_dump__new_deprecated(const struct btf *btf,
  *
  * The rest works just like in case of ___libbpf_override() usage with symbol
  * versioning.
+ *
+ * C++ compilers don't support __builtin_types_compatible_p(), so at least
+ * don't screw up compilation for them and let C++ users pick btf_dump__new
+ * vs btf_dump__new_deprecated explicitly.
  */
+#ifndef __cplusplus
 #define btf_dump__new(a1, a2, a3, a4) __builtin_choose_expr(				\
 	__builtin_types_compatible_p(typeof(a4), btf_dump_printf_fn_t) ||		\
 	__builtin_types_compatible_p(typeof(a4), void(void *, const char *, va_list)),	\
 	btf_dump__new_deprecated((void *)a1, (void *)a2, (void *)a3, (void *)a4),	\
 	btf_dump__new((void *)a1, (void *)a2, (void *)a3, (void *)a4))
+#endif
 
 LIBBPF_API void btf_dump__free(struct btf_dump *d);
 
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH bpf-next 2/2] selftests/bpf: Add btf_dump__new to test_cpp
  2021-12-23 13:17 [PATCH bpf-next 1/2] libbpf: Do not use btf_dump__new macro for c++ objects Jiri Olsa
@ 2021-12-23 13:17 ` Jiri Olsa
  2021-12-23 16:14   ` Yonghong Song
  2021-12-23 16:13 ` [PATCH bpf-next 1/2] libbpf: Do not use btf_dump__new macro for c++ objects Yonghong Song
  1 sibling, 1 reply; 5+ messages in thread
From: Jiri Olsa @ 2021-12-23 13:17 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: netdev, bpf, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh

Adding btf_dump__new call to test_cpp, so we can
test C++ compilation with that.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/testing/selftests/bpf/test_cpp.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/test_cpp.cpp b/tools/testing/selftests/bpf/test_cpp.cpp
index a8d2e9a87fbf..e00201de2890 100644
--- a/tools/testing/selftests/bpf/test_cpp.cpp
+++ b/tools/testing/selftests/bpf/test_cpp.cpp
@@ -7,9 +7,15 @@
 
 /* do nothing, just make sure we can link successfully */
 
+static void dump_printf(void *ctx, const char *fmt, va_list args)
+{
+}
+
 int main(int argc, char *argv[])
 {
+	struct btf_dump_opts opts = { };
 	struct test_core_extern *skel;
+	struct btf *btf;
 
 	/* libbpf.h */
 	libbpf_set_print(NULL);
@@ -18,7 +24,8 @@ int main(int argc, char *argv[])
 	bpf_prog_get_fd_by_id(0);
 
 	/* btf.h */
-	btf__new(NULL, 0);
+	btf = btf__new(NULL, 0);
+	btf_dump__new(btf, dump_printf, nullptr, &opts);
 
 	/* BPF skeleton */
 	skel = test_core_extern__open_and_load();
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next 1/2] libbpf: Do not use btf_dump__new macro for c++ objects
  2021-12-23 13:17 [PATCH bpf-next 1/2] libbpf: Do not use btf_dump__new macro for c++ objects Jiri Olsa
  2021-12-23 13:17 ` [PATCH bpf-next 2/2] selftests/bpf: Add btf_dump__new to test_cpp Jiri Olsa
@ 2021-12-23 16:13 ` Yonghong Song
  2021-12-23 18:25   ` Andrii Nakryiko
  1 sibling, 1 reply; 5+ messages in thread
From: Yonghong Song @ 2021-12-23 16:13 UTC (permalink / raw)
  To: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: netdev, bpf, Martin KaFai Lau, Song Liu, John Fastabend, KP Singh



On 12/23/21 5:17 AM, Jiri Olsa wrote:
> As reported in here [0], C++ compilers don't support __builtin_types_compatible_p(),
> so at least don't screw up compilation for them and let C++ users
> pick btf_dump__new vs btf_dump__new_deprecated explicitly.
> 
> [0] https://github.com/libbpf/libbpf/issues/283#issuecomment-986100727
> Fixes: 6084f5dc928f ("libbpf: Ensure btf_dump__new() and btf_dump_opts are future-proof")
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Acked-by: Yonghong Song <yhs@fb.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next 2/2] selftests/bpf: Add btf_dump__new to test_cpp
  2021-12-23 13:17 ` [PATCH bpf-next 2/2] selftests/bpf: Add btf_dump__new to test_cpp Jiri Olsa
@ 2021-12-23 16:14   ` Yonghong Song
  0 siblings, 0 replies; 5+ messages in thread
From: Yonghong Song @ 2021-12-23 16:14 UTC (permalink / raw)
  To: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: netdev, bpf, Martin KaFai Lau, Song Liu, John Fastabend, KP Singh



On 12/23/21 5:17 AM, Jiri Olsa wrote:
> Adding btf_dump__new call to test_cpp, so we can
> test C++ compilation with that.
> 
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Acked-by: Yonghong Song <yhs@fb.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next 1/2] libbpf: Do not use btf_dump__new macro for c++ objects
  2021-12-23 16:13 ` [PATCH bpf-next 1/2] libbpf: Do not use btf_dump__new macro for c++ objects Yonghong Song
@ 2021-12-23 18:25   ` Andrii Nakryiko
  0 siblings, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2021-12-23 18:25 UTC (permalink / raw)
  To: Yonghong Song
  Cc: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Networking, bpf, Martin KaFai Lau, Song Liu, John Fastabend,
	KP Singh

On Thu, Dec 23, 2021 at 8:13 AM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 12/23/21 5:17 AM, Jiri Olsa wrote:
> > As reported in here [0], C++ compilers don't support __builtin_types_compatible_p(),
> > so at least don't screw up compilation for them and let C++ users
> > pick btf_dump__new vs btf_dump__new_deprecated explicitly.
> >
> > [0] https://github.com/libbpf/libbpf/issues/283#issuecomment-986100727
> > Fixes: 6084f5dc928f ("libbpf: Ensure btf_dump__new() and btf_dump_opts are future-proof")
> > Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
>
> Acked-by: Yonghong Song <yhs@fb.com>


Adjusted commit message a but and applied to bpf-next, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-23 18:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-23 13:17 [PATCH bpf-next 1/2] libbpf: Do not use btf_dump__new macro for c++ objects Jiri Olsa
2021-12-23 13:17 ` [PATCH bpf-next 2/2] selftests/bpf: Add btf_dump__new to test_cpp Jiri Olsa
2021-12-23 16:14   ` Yonghong Song
2021-12-23 16:13 ` [PATCH bpf-next 1/2] libbpf: Do not use btf_dump__new macro for c++ objects Yonghong Song
2021-12-23 18:25   ` Andrii Nakryiko

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).