diff --git a/bpf/Makefile.bpf b/bpf/Makefile.bpf index 14f25bb1113c..d88a3ec23228 100644 --- a/bpf/Makefile.bpf +++ b/bpf/Makefile.bpf @@ -3,11 +3,14 @@ FLAGS := -I$(ROOT_DIR)/bpf/include -I$(ROOT_DIR)/bpf -D__NR_CPUS__=$(shell nproc) -O2 -g -CLANG_FLAGS := ${FLAGS} -target bpf -emit-llvm +CLANG_FLAGS := ${FLAGS} -target bpf -std=gnu89 -nostdinc -emit-llvm # eBPF verifier enforces unaligned access checks where necessary, so don't # let clang complain too early. -CLANG_FLAGS += -Wall -Wextra -Werror -CLANG_FLAGS += -Wno-address-of-packed-member -Wno-unknown-warning-option -Wno-gnu-variable-sized-type-not-at-end +CLANG_FLAGS += -Wall -Wextra -Werror -Wshadow +CLANG_FLAGS += -Wno-address-of-packed-member +CLANG_FLAGS += -Wno-unknown-warning-option +CLANG_FLAGS += -Wno-gnu-variable-sized-type-not-at-end +CLANG_FLAGS += -Wdeclaration-after-statement LLC_FLAGS := -march=bpf -mcpu=probe -mattr=dwarfris # BUILD_PERMUTATIONS_DEP is a dummy file dependency that ensures all targets diff --git a/bpf/init.sh b/bpf/init.sh index 7926679299e3..4c69190d885c 100755 --- a/bpf/init.sh +++ b/bpf/init.sh @@ -268,11 +268,12 @@ function bpf_compile() TYPE=$3 EXTRA_OPTS=$4 - clang -O2 -target bpf -emit-llvm \ - -Wall -Wextra -Werror \ + clang -O2 -target bpf -std=gnu89 -nostdinc -emit-llvm \ + -Wall -Wextra -Werror -Wshadow \ -Wno-address-of-packed-member \ -Wno-unknown-warning-option \ -Wno-gnu-variable-sized-type-not-at-end \ + -Wdeclaration-after-statement \ -I. -I$DIR -I$LIB -I$LIB/include \ -D__NR_CPUS__=$(nproc) \ -DENABLE_ARP_RESPONDER=1 \ diff --git a/pkg/datapath/loader/compile.go b/pkg/datapath/loader/compile.go index 56faea952056..5d1d298cc549 100644 --- a/pkg/datapath/loader/compile.go +++ b/pkg/datapath/loader/compile.go @@ -82,12 +82,13 @@ type directoryInfo struct { } var ( - standardCFlags = []string{"-O2", "-target", "bpf", - fmt.Sprintf("-D__NR_CPUS__=%d", runtime.NumCPU()), - "-Wall", "-Wextra", "-Werror", + standardCFlags = []string{"-O2", "-target", "bpf", "-std=gnu89", + "-nostdinc", fmt.Sprintf("-D__NR_CPUS__=%d", runtime.NumCPU()), + "-Wall", "-Wextra", "-Werror", "-Wshadow", "-Wno-address-of-packed-member", "-Wno-unknown-warning-option", - "-Wno-gnu-variable-sized-type-not-at-end"} + "-Wno-gnu-variable-sized-type-not-at-end", + "-Wdeclaration-after-statement"} standardLDFlags = []string{"-march=bpf"} // testIncludes allows the unit tests to inject additional include diff --git a/test/bpf/Makefile b/test/bpf/Makefile index 64cae73537d7..d291ac635118 100644 --- a/test/bpf/Makefile +++ b/test/bpf/Makefile @@ -4,9 +4,13 @@ include ../../Makefile.defs FLAGS := -I../../bpf/ -I../../bpf/include -I. -D__NR_CPUS__=$(shell nproc) -O2 -FLAGS_CLANG := -Wno-gnu-variable-sized-type-not-at-end +FLAGS_CLANG := -Wall -Wextra -Werror -Wshadow -Wno-unused-parameter +FLAGS_CLANG += -Wno-address-of-packed-member +FLAGS_CLANG += -Wno-unknown-warning-option +FLAGS_CLANG += -Wno-gnu-variable-sized-type-not-at-end +FLAGS_CLANG += -Wdeclaration-after-statement -BPF_CC_FLAGS := ${FLAGS} -target bpf -emit-llvm +BPF_CC_FLAGS := ${FLAGS} -target bpf -std=gnu89 -nostdinc -emit-llvm BPF_LLC_FLAGS := -march=bpf -mcpu=probe -filetype=obj LIB := $(shell find ../../bpf/ -name '*.h')