Skip to content

Commit bab18c7

Browse files
theihorAlexei Starovoitov
authored andcommitted
selftests/bpf: add -std=gnu11 to BPF_CFLAGS and CFLAGS
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/[email protected]/ CC: Jose E. Marchesi <[email protected]> Signed-off-by: Ihor Solodrai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 46c61cb commit bab18c7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
4141
srctree := $(patsubst %/,%,$(dir $(srctree)))
4242
endif
4343

44-
CFLAGS += -g $(OPT_FLAGS) -rdynamic \
44+
CFLAGS += -g $(OPT_FLAGS) -rdynamic -std=gnu11 \
4545
-Wall -Werror -fno-omit-frame-pointer \
4646
$(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \
4747
-I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
@@ -447,6 +447,7 @@ CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
447447
BPF_CFLAGS = -g -Wall -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
448448
-I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
449449
-I$(abspath $(OUTPUT)/../usr/include) \
450+
-std=gnu11 \
450451
-fno-strict-aliasing \
451452
-Wno-compare-distinct-pointer-types
452453
# TODO: enable me -Wsign-compare
@@ -787,9 +788,12 @@ $(OUTPUT)/xdp_features: xdp_features.c $(OUTPUT)/network_helpers.o $(OUTPUT)/xdp
787788
$(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
788789

789790
# Make sure we are able to include and link libbpf against c++.
791+
CXXFLAGS += $(CFLAGS)
792+
CXXFLAGS := $(subst -D_GNU_SOURCE=,,$(CXXFLAGS))
793+
CXXFLAGS := $(subst -std=gnu11,-std=gnu++11,$(CXXFLAGS))
790794
$(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
791795
$(call msg,CXX,,$@)
792-
$(Q)$(CXX) $(subst -D_GNU_SOURCE=,,$(CFLAGS)) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@
796+
$(Q)$(CXX) $(CXXFLAGS) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@
793797

794798
# Benchmark runner
795799
$(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h $(BPFOBJ)

0 commit comments

Comments
 (0)