libbpf: Do not use btf_dump__new macro for c++ objects
Subsystems (6)
PATCH 1/2 libbpf: Do not use btf_dump__new macro for c++ objects
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
--- tools/lib/bpf/btf.h | 6 ++++++ 1 file changed, 6 insertions(+)
tools/lib/bpf/btf.h +6 -0
@@ -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);
Signature · 1 line
2.33.1
PATCH 2/2 selftests/bpf: Add btf_dump__new to test_cpp
Adding btf_dump__new call to test_cpp, so we can
test C++ compilation with that.
--- tools/testing/selftests/bpf/test_cpp.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/test_cpp.cpp +8 -1
@@ -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();
Signature · 1 line
2.33.1
Re: [PATCH bpf-next 2/2] selftests/bpf: Add btf_dump__new to test_cpp
Quoted 4 lines · Jiri Olsa
Adding
btf_dump__newcall totest_cpp, so we can
test C++ compilation with that.Signed-off-by Jiri Olsa <[email protected]>
Quoted 8 lines · Jiri Olsa
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
pickbtf_dump__newvsbtf_dump__new_deprecatedexplicitly.[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 <[email protected]>Signed-off-by Jiri Olsa <[email protected]>
Quoted 8 lines · Yonghong Song
Quoted 4 lines · Jiri Olsa
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
pickbtf_dump__newvsbtf_dump__new_deprecatedexplicitly.
Quoted 6 lines
Quoted 4 lines
[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 <[email protected]>Signed-off-by Jiri Olsa <[email protected]>Acked-by Yonghong Song <[email protected]>
Adjusted commit message a but and applied to bpf-next, thanks.