Skip to content

eBPF-based security platform

build: fail on compiler warnings

Daniel Borkmannaacf8d152199
diff --git a/AGENTS.md b/AGENTS.md
index 9b632a53..f1592f19 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -296,6 +296,10 @@ one usually still compiles and passes tests.
- `make` builds the operator binary; `make shirudo-build` the helper;
`make target` the static-OpenSSL target profile (`make target-deps`
builds OpenSSL, libcurl and tpm2-tss from source first).
+- A compiler warning fails every build the Makefiles drive, the BPF
+ objects, vendored libbpf, test helpers and fuzz targets included;
+ fix the warning rather than silence it. `WERROR=0` is for a compiler
+ newer than the tree, while its new warnings get fixed.
- `make -C testing test-op` runs the host-side suite (`testing/t0*`), no root needed;
`make -C testing SANITIZE=address,undefined test-op` runs it under ASan and
UBSan (CI does too); `make -C testing test-tgt` runs the target suite in the
diff --git a/Documentation/requirements.rst b/Documentation/requirements.rst
index 5d737f4d..441ddbbf 100644
--- a/Documentation/requirements.rst
+++ b/Documentation/requirements.rst
@@ -262,7 +262,9 @@ since the libguestfs appliance resolves names through DNS alone.
4) Operator host
----------------
-* A C toolchain (``cc``, ``make``, ``pkg-config``).
+* A C toolchain (``cc``, ``make``, ``pkg-config``). A compiler warning
+ fails the build; ``make WERROR=0`` lets a compiler newer than the tree
+ finish it.
* Current upstream ``clang`` and ``llvm`` with the BPF target, for
``shirudo build`` and the embedded enforcement programs.
* OpenSSL 3.5 or newer: ``libcrypto`` and ``libssl`` development files
diff --git a/Makefile.shirudo b/Makefile.shirudo
index cd5046d6..3010516c 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -69,9 +69,15 @@ SHIRUDO_BPF_INCDIR ?= $(sharedir)/shirudo/bpf/include
# Installed kernel BTF types used as the default vmlinux.h fallback.
SHIRUDO_VMLINUX_PATH ?= $(sharedir)/shirudo/vmlinux.h
+# A warning fails the build, ours and that of the vendored libbpf and
+# the BPF objects alike; WERROR=0 lets a compiler newer than the tree
+# finish the build while its new warnings get fixed.
+WERROR ?= 1
+WERROR_CFLAGS := $(if $(filter 1,$(WERROR)),-Werror)
WARNINGS := -Wall -Wextra -Wno-unused-parameter -Wstrict-prototypes \
-Wmissing-prototypes -Wpointer-arith -Wshadow \
- -Wdeclaration-after-statement -Wformat-security
+ -Wdeclaration-after-statement -Wformat-security \
+ $(WERROR_CFLAGS)
SHIRUDO_DEBUG ?= 1
DEBUG_CFLAGS := $(if $(filter 1 yes y true,$(SHIRUDO_DEBUG)),-g,)
@@ -149,7 +155,7 @@ endif
# fixable upstream of us, so silence both for BPF compilation.
CLANG_BPF := $(CLANG) -target bpf -O2 -g -Wall -Wextra \
-Wno-missing-declarations -Wno-unused-parameter \
- -Wdeclaration-after-statement
+ -Wdeclaration-after-statement $(WERROR_CFLAGS)
# ----- source manifests -------------------------------------------
@@ -289,7 +295,8 @@ libbpf: $(LIBBPF_A)
$(LIBBPF_A): $(LIBBPF_SRCS)
@printf ' LIBBPF\n'
- $(Q)$(MAKE) -C $(LIBBPF_VENDOR) CC="$(CC)" Q="$(Q)"
+ $(Q)$(MAKE) -C $(LIBBPF_VENDOR) CC="$(CC)" Q="$(Q)" \
+ EXTRA_CFLAGS="$(WERROR_CFLAGS)"
# Build-time only; links the vendored libbpf and dumps BTF as C.
$(VMLINUX_GEN): tools/gen-vmlinux-h/gen-vmlinux-h.c $(LIBBPF_A)