* [PATCH] selftests/bpf: add -std=gnu11 to BPF_CFLAGS and CFLAGS
@ 2025-01-07 23:58 Ihor Solodrai
2025-01-08 17:40 ` patchwork-bot+netdevbpf
2025-01-10 23:34 ` Andrii Nakryiko
0 siblings, 2 replies; 5+ messages in thread
From: Ihor Solodrai @ 2025-01-07 23:58 UTC (permalink / raw)
To: bpf; +Cc: andrii, ast, daniel, eddyz87, mykolal, jose.marchesi
Latest versions of GCC BPF use C23 standard by default. This causes
compilation errors in vmlinux.h due to bool types declarations.
Add -std=gnu11 to BPF_CFLAGS and CFLAGS. This aligns with the version
of the standard used when building the kernel currently [1].
For more details see the discussions at [2] and [3].
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile#n465
[2] https://lore.kernel.org/bpf/EYcXjcKDCJY7Yb0GGtAAb7nLKPEvrgWdvWpuNzXm2qi6rYMZDixKv5KwfVVMBq17V55xyC-A1wIjrqG3aw-Imqudo9q9X7D7nLU2gWgbN0w=@pm.me/
[3] https://lore.kernel.org/bpf/20250106202715.1232864-1-ihor.solodrai@pm.me/
CC: Jose E. Marchesi <jose.marchesi@oracle.com>
Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
---
tools/testing/selftests/bpf/Makefile | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index d5be2f94deef..ea9cee5de0f8 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -41,7 +41,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
endif
-CFLAGS += -g $(OPT_FLAGS) -rdynamic \
+CFLAGS += -g $(OPT_FLAGS) -rdynamic -std=gnu11 \
-Wall -Werror -fno-omit-frame-pointer \
$(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \
-I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
@@ -447,6 +447,7 @@ CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
BPF_CFLAGS = -g -Wall -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
-I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
-I$(abspath $(OUTPUT)/../usr/include) \
+ -std=gnu11 \
-fno-strict-aliasing \
-Wno-compare-distinct-pointer-types
# TODO: enable me -Wsign-compare
@@ -787,9 +788,12 @@ $(OUTPUT)/xdp_features: xdp_features.c $(OUTPUT)/network_helpers.o $(OUTPUT)/xdp
$(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
# Make sure we are able to include and link libbpf against c++.
+CXXFLAGS += $(CFLAGS)
+CXXFLAGS := $(subst -D_GNU_SOURCE=,,$(CXXFLAGS))
+CXXFLAGS := $(subst -std=gnu11,-std=gnu++11,$(CXXFLAGS))
$(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
$(call msg,CXX,,$@)
- $(Q)$(CXX) $(subst -D_GNU_SOURCE=,,$(CFLAGS)) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@
+ $(Q)$(CXX) $(CXXFLAGS) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@
# Benchmark runner
$(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h $(BPFOBJ)
--
2.47.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/bpf: add -std=gnu11 to BPF_CFLAGS and CFLAGS
2025-01-07 23:58 [PATCH] selftests/bpf: add -std=gnu11 to BPF_CFLAGS and CFLAGS Ihor Solodrai
@ 2025-01-08 17:40 ` patchwork-bot+netdevbpf
2025-01-10 23:34 ` Andrii Nakryiko
1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-01-08 17:40 UTC (permalink / raw)
To: Ihor Solodrai; +Cc: bpf, andrii, ast, daniel, eddyz87, mykolal, jose.marchesi
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Tue, 07 Jan 2025 23:58:18 +0000 you wrote:
> Latest versions of GCC BPF use C23 standard by default. This causes
> compilation errors in vmlinux.h due to bool types declarations.
>
> Add -std=gnu11 to BPF_CFLAGS and CFLAGS. This aligns with the version
> of the standard used when building the kernel currently [1].
>
> For more details see the discussions at [2] and [3].
>
> [...]
Here is the summary with links:
- selftests/bpf: add -std=gnu11 to BPF_CFLAGS and CFLAGS
https://git.kernel.org/bpf/bpf-next/c/bab18c7db44d
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] 5+ messages in thread
* Re: [PATCH] selftests/bpf: add -std=gnu11 to BPF_CFLAGS and CFLAGS
2025-01-07 23:58 [PATCH] selftests/bpf: add -std=gnu11 to BPF_CFLAGS and CFLAGS Ihor Solodrai
2025-01-08 17:40 ` patchwork-bot+netdevbpf
@ 2025-01-10 23:34 ` Andrii Nakryiko
2025-01-10 23:44 ` Ihor Solodrai
1 sibling, 1 reply; 5+ messages in thread
From: Andrii Nakryiko @ 2025-01-10 23:34 UTC (permalink / raw)
To: Ihor Solodrai; +Cc: bpf, andrii, ast, daniel, eddyz87, mykolal, jose.marchesi
On Tue, Jan 7, 2025 at 3:58 PM Ihor Solodrai <ihor.solodrai@pm.me> wrote:
>
> Latest versions of GCC BPF use C23 standard by default. This causes
> compilation errors in vmlinux.h due to bool types declarations.
Do you have an example of an error? Why can't we fix that to work with C23?
>
> Add -std=gnu11 to BPF_CFLAGS and CFLAGS. This aligns with the version
> of the standard used when building the kernel currently [1].
>
> For more details see the discussions at [2] and [3].
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile#n465
> [2] https://lore.kernel.org/bpf/EYcXjcKDCJY7Yb0GGtAAb7nLKPEvrgWdvWpuNzXm2qi6rYMZDixKv5KwfVVMBq17V55xyC-A1wIjrqG3aw-Imqudo9q9X7D7nLU2gWgbN0w=@pm.me/
> [3] https://lore.kernel.org/bpf/20250106202715.1232864-1-ihor.solodrai@pm.me/
>
> CC: Jose E. Marchesi <jose.marchesi@oracle.com>
> Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
> ---
> tools/testing/selftests/bpf/Makefile | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index d5be2f94deef..ea9cee5de0f8 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -41,7 +41,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
> srctree := $(patsubst %/,%,$(dir $(srctree)))
> endif
>
> -CFLAGS += -g $(OPT_FLAGS) -rdynamic \
> +CFLAGS += -g $(OPT_FLAGS) -rdynamic -std=gnu11 \
> -Wall -Werror -fno-omit-frame-pointer \
> $(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \
> -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
> @@ -447,6 +447,7 @@ CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
> BPF_CFLAGS = -g -Wall -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
> -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
> -I$(abspath $(OUTPUT)/../usr/include) \
> + -std=gnu11 \
> -fno-strict-aliasing \
> -Wno-compare-distinct-pointer-types
> # TODO: enable me -Wsign-compare
> @@ -787,9 +788,12 @@ $(OUTPUT)/xdp_features: xdp_features.c $(OUTPUT)/network_helpers.o $(OUTPUT)/xdp
> $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
>
> # Make sure we are able to include and link libbpf against c++.
> +CXXFLAGS += $(CFLAGS)
> +CXXFLAGS := $(subst -D_GNU_SOURCE=,,$(CXXFLAGS))
> +CXXFLAGS := $(subst -std=gnu11,-std=gnu++11,$(CXXFLAGS))
> $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
> $(call msg,CXX,,$@)
> - $(Q)$(CXX) $(subst -D_GNU_SOURCE=,,$(CFLAGS)) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@
> + $(Q)$(CXX) $(CXXFLAGS) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@
>
> # Benchmark runner
> $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h $(BPFOBJ)
> --
> 2.47.1
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/bpf: add -std=gnu11 to BPF_CFLAGS and CFLAGS
2025-01-10 23:34 ` Andrii Nakryiko
@ 2025-01-10 23:44 ` Ihor Solodrai
2025-01-10 23:55 ` Andrii Nakryiko
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Solodrai @ 2025-01-10 23:44 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: bpf, andrii, ast, daniel, eddyz87, mykolal, jose.marchesi
On Friday, January 10th, 2025 at 3:34 PM, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
>
> On Tue, Jan 7, 2025 at 3:58 PM Ihor Solodrai ihor.solodrai@pm.me wrote:
>
> > Latest versions of GCC BPF use C23 standard by default. This causes
> > compilation errors in vmlinux.h due to bool types declarations.
>
>
> Do you have an example of an error? Why can't we fix that to work with C23?
See a thread here: https://lore.kernel.org/bpf/ZryncitpWOFICUSCu4HLsMIZ7zOuiH5f4jrgjAh0uiOgKvZzQES09eerwIXNonKEq0U6hdI9pHSCPahUKihTeS8NKlVfkcuiRLotteNbQ9I=@pm.me/
The one I ran into is about:
enum {
false = 0,
true = 1,
};
Which is illegal in C23, because true and false are reserved words.
>
> [...]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/bpf: add -std=gnu11 to BPF_CFLAGS and CFLAGS
2025-01-10 23:44 ` Ihor Solodrai
@ 2025-01-10 23:55 ` Andrii Nakryiko
0 siblings, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2025-01-10 23:55 UTC (permalink / raw)
To: Ihor Solodrai; +Cc: bpf, andrii, ast, daniel, eddyz87, mykolal, jose.marchesi
On Fri, Jan 10, 2025 at 3:44 PM Ihor Solodrai <ihor.solodrai@pm.me> wrote:
>
> On Friday, January 10th, 2025 at 3:34 PM, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
> >
> >
> > On Tue, Jan 7, 2025 at 3:58 PM Ihor Solodrai ihor.solodrai@pm.me wrote:
> >
> > > Latest versions of GCC BPF use C23 standard by default. This causes
> > > compilation errors in vmlinux.h due to bool types declarations.
> >
> >
> > Do you have an example of an error? Why can't we fix that to work with C23?
>
> See a thread here: https://lore.kernel.org/bpf/ZryncitpWOFICUSCu4HLsMIZ7zOuiH5f4jrgjAh0uiOgKvZzQES09eerwIXNonKEq0U6hdI9pHSCPahUKihTeS8NKlVfkcuiRLotteNbQ9I=@pm.me/
>
Yeah, thanks, still catching up, just got to that thread and saw the
discussion. What a mess, I'll pretend I don't know about this. :)
> The one I ran into is about:
>
> enum {
> false = 0,
> true = 1,
> };
>
> Which is illegal in C23, because true and false are reserved words.
>
> >
> > [...]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-01-10 23:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-07 23:58 [PATCH] selftests/bpf: add -std=gnu11 to BPF_CFLAGS and CFLAGS Ihor Solodrai
2025-01-08 17:40 ` patchwork-bot+netdevbpf
2025-01-10 23:34 ` Andrii Nakryiko
2025-01-10 23:44 ` Ihor Solodrai
2025-01-10 23:55 ` Andrii Nakryiko
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.