All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2] bpftool: Remove usage of reallocarray()
@ 2022-02-21 12:56 Mauricio Vásquez
  2022-02-21 15:48 ` Quentin Monnet
  2022-02-23 22:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Mauricio Vásquez @ 2022-02-21 12:56 UTC (permalink / raw)
  To: netdev, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Quentin Monnet

This commit fixes a compilation error on systems with glibc < 2.26 [0]:

```
In file included from main.h:14:0,
                 from gen.c:24:
linux/tools/include/tools/libc_compat.h:11:21: error: attempt to use poisoned "reallocarray"
 static inline void *reallocarray(void *ptr, size_t nmemb, size_t size)
```

This happens because gen.c pulls <bpf/libbpf_internal.h>, and then
<tools/libc_compat.h> (through main.h). When
COMPAT_NEED_REALLOCARRAY is set, libc_compat.h defines reallocarray()
which libbpf_internal.h poisons with a GCC pragma.

This commit reuses libbpf_reallocarray() implemented in commit
029258d7b228 ("libbpf: Remove any use of reallocarray() in libbpf").

v1 -> v2:
- reuse libbpf_reallocarray() instead of reimplementing it

Reported-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>

[0]: https://lore.kernel.org/bpf/3bf2bd49-9f2d-a2df-5536-bc0dde70a83b@isovalent.com/
---
 tools/bpf/bpftool/Makefile        | 6 +-----
 tools/bpf/bpftool/main.h          | 2 +-
 tools/bpf/bpftool/prog.c          | 7 ++++---
 tools/bpf/bpftool/xlated_dumper.c | 5 +++--
 4 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index a137db96bd56..ba647aede0d6 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -93,7 +93,7 @@ INSTALL ?= install
 RM ?= rm -f
 
 FEATURE_USER = .bpftool
-FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib libcap \
+FEATURE_TESTS = libbfd disassembler-four-args zlib libcap \
 	clang-bpf-co-re
 FEATURE_DISPLAY = libbfd disassembler-four-args zlib libcap \
 	clang-bpf-co-re
@@ -118,10 +118,6 @@ ifeq ($(feature-disassembler-four-args), 1)
 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
 endif
 
-ifeq ($(feature-reallocarray), 0)
-CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
-endif
-
 LIBS = $(LIBBPF) -lelf -lz
 LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz
 ifeq ($(feature-libcap), 1)
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index 0c3840596b5a..0468e5b24bd4 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -8,10 +8,10 @@
 #undef GCC_VERSION
 #include <stdbool.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <linux/bpf.h>
 #include <linux/compiler.h>
 #include <linux/kernel.h>
-#include <tools/libc_compat.h>
 
 #include <bpf/hashmap.h>
 #include <bpf/libbpf.h>
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 92a6f679ef7d..8a52eed19fa2 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -26,6 +26,7 @@
 #include <bpf/btf.h>
 #include <bpf/hashmap.h>
 #include <bpf/libbpf.h>
+#include <bpf/libbpf_internal.h>
 #include <bpf/skel_internal.h>
 
 #include "cfg.h"
@@ -1558,9 +1559,9 @@ static int load_with_options(int argc, char **argv, bool first_prog_only)
 			if (fd < 0)
 				goto err_free_reuse_maps;
 
-			new_map_replace = reallocarray(map_replace,
-						       old_map_fds + 1,
-						       sizeof(*map_replace));
+			new_map_replace = libbpf_reallocarray(map_replace,
+							      old_map_fds + 1,
+							      sizeof(*map_replace));
 			if (!new_map_replace) {
 				p_err("mem alloc failed");
 				goto err_free_reuse_maps;
diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c
index f1f32e21d5cd..2d9cd6a7b3c8 100644
--- a/tools/bpf/bpftool/xlated_dumper.c
+++ b/tools/bpf/bpftool/xlated_dumper.c
@@ -8,6 +8,7 @@
 #include <string.h>
 #include <sys/types.h>
 #include <bpf/libbpf.h>
+#include <bpf/libbpf_internal.h>
 
 #include "disasm.h"
 #include "json_writer.h"
@@ -32,8 +33,8 @@ void kernel_syms_load(struct dump_data *dd)
 		return;
 
 	while (fgets(buff, sizeof(buff), fp)) {
-		tmp = reallocarray(dd->sym_mapping, dd->sym_count + 1,
-				   sizeof(*dd->sym_mapping));
+		tmp = libbpf_reallocarray(dd->sym_mapping, dd->sym_count + 1,
+					  sizeof(*dd->sym_mapping));
 		if (!tmp) {
 out:
 			free(dd->sym_mapping);
-- 
2.25.1


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

* Re: [PATCH bpf-next v2] bpftool: Remove usage of reallocarray()
  2022-02-21 12:56 [PATCH bpf-next v2] bpftool: Remove usage of reallocarray() Mauricio Vásquez
@ 2022-02-21 15:48 ` Quentin Monnet
  2022-02-22  1:48   ` Song Liu
  2022-02-23 22:00 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Quentin Monnet @ 2022-02-21 15:48 UTC (permalink / raw)
  To: Mauricio Vásquez, netdev, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko

2022-02-21 07:56 UTC-0500 ~ Mauricio Vásquez <mauricio@kinvolk.io>
> This commit fixes a compilation error on systems with glibc < 2.26 [0]:
> 
> ```
> In file included from main.h:14:0,
>                  from gen.c:24:
> linux/tools/include/tools/libc_compat.h:11:21: error: attempt to use poisoned "reallocarray"
>  static inline void *reallocarray(void *ptr, size_t nmemb, size_t size)
> ```
> 
> This happens because gen.c pulls <bpf/libbpf_internal.h>, and then
> <tools/libc_compat.h> (through main.h). When
> COMPAT_NEED_REALLOCARRAY is set, libc_compat.h defines reallocarray()
> which libbpf_internal.h poisons with a GCC pragma.
> 
> This commit reuses libbpf_reallocarray() implemented in commit
> 029258d7b228 ("libbpf: Remove any use of reallocarray() in libbpf").
> 
> v1 -> v2:
> - reuse libbpf_reallocarray() instead of reimplementing it
> 
> Reported-by: Quentin Monnet <quentin@isovalent.com>
> Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
> 
> [0]: https://lore.kernel.org/bpf/3bf2bd49-9f2d-a2df-5536-bc0dde70a83b@isovalent.com/

Fixes: a9caaba399f9 ("bpftool: Implement "gen min_core_btf" logic")
Reviewed-by: Quentin Monnet <quentin@isovalent.com>

Thanks!

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

* Re: [PATCH bpf-next v2] bpftool: Remove usage of reallocarray()
  2022-02-21 15:48 ` Quentin Monnet
@ 2022-02-22  1:48   ` Song Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Song Liu @ 2022-02-22  1:48 UTC (permalink / raw)
  To: Quentin Monnet
  Cc: Mauricio Vásquez, Networking, bpf, Alexei Starovoitov,
	Daniel Borkmann, Andrii Nakryiko

On Mon, Feb 21, 2022 at 7:48 AM Quentin Monnet <quentin@isovalent.com> wrote:
>
> 2022-02-21 07:56 UTC-0500 ~ Mauricio Vásquez <mauricio@kinvolk.io>
> > This commit fixes a compilation error on systems with glibc < 2.26 [0]:
> >
> > ```
> > In file included from main.h:14:0,
> >                  from gen.c:24:
> > linux/tools/include/tools/libc_compat.h:11:21: error: attempt to use poisoned "reallocarray"
> >  static inline void *reallocarray(void *ptr, size_t nmemb, size_t size)
> > ```
> >
> > This happens because gen.c pulls <bpf/libbpf_internal.h>, and then
> > <tools/libc_compat.h> (through main.h). When
> > COMPAT_NEED_REALLOCARRAY is set, libc_compat.h defines reallocarray()
> > which libbpf_internal.h poisons with a GCC pragma.
> >
> > This commit reuses libbpf_reallocarray() implemented in commit
> > 029258d7b228 ("libbpf: Remove any use of reallocarray() in libbpf").
> >
> > v1 -> v2:
> > - reuse libbpf_reallocarray() instead of reimplementing it
> >
> > Reported-by: Quentin Monnet <quentin@isovalent.com>
> > Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
> >
> > [0]: https://lore.kernel.org/bpf/3bf2bd49-9f2d-a2df-5536-bc0dde70a83b@isovalent.com/
>
> Fixes: a9caaba399f9 ("bpftool: Implement "gen min_core_btf" logic")
> Reviewed-by: Quentin Monnet <quentin@isovalent.com>

Acked-by: Song Liu <songliubraving@fb.com>

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

* Re: [PATCH bpf-next v2] bpftool: Remove usage of reallocarray()
  2022-02-21 12:56 [PATCH bpf-next v2] bpftool: Remove usage of reallocarray() Mauricio Vásquez
  2022-02-21 15:48 ` Quentin Monnet
@ 2022-02-23 22:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-23 22:00 UTC (permalink / raw)
  To: =?utf-8?q?Mauricio_V=C3=A1squez_=3Cmauricio=40kinvolk=2Eio=3E?=
  Cc: netdev, bpf, ast, daniel, andrii, quentin

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Mon, 21 Feb 2022 07:56:17 -0500 you wrote:
> This commit fixes a compilation error on systems with glibc < 2.26 [0]:
> 
> ```
> In file included from main.h:14:0,
>                  from gen.c:24:
> linux/tools/include/tools/libc_compat.h:11:21: error: attempt to use poisoned "reallocarray"
>  static inline void *reallocarray(void *ptr, size_t nmemb, size_t size)
> ```
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2] bpftool: Remove usage of reallocarray()
    https://git.kernel.org/bpf/bpf-next/c/a19df7139440

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-02-23 22:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21 12:56 [PATCH bpf-next v2] bpftool: Remove usage of reallocarray() Mauricio Vásquez
2022-02-21 15:48 ` Quentin Monnet
2022-02-22  1:48   ` Song Liu
2022-02-23 22:00 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.