[RFC bpf-next 13/13] bpf: Supporting building verifier.ko out-of-tree

From: Daniel Xu
Date: Tue Apr 08 2025 - 23:40:43 EST


This supports out-of-tree builds against the in-tree verifier.ko. This
is intended to be used to build newer upstream verifiers against older
kernel sources.

You can also do an "in-tree out-of-tree" build as proof of concept:

$ make clean
$ make modules_prepare
$ cd kernel/bpf
$ make -C ../.. M=$PWD

Signed-off-by: Daniel Xu <dxu@xxxxxxxxx>
---
kernel/bpf/Kbuild | 8 ++++++++
1 file changed, 8 insertions(+)
create mode 100644 kernel/bpf/Kbuild

diff --git a/kernel/bpf/Kbuild b/kernel/bpf/Kbuild
new file mode 100644
index 000000000000..0b4a9ce14c6f
--- /dev/null
+++ b/kernel/bpf/Kbuild
@@ -0,0 +1,8 @@
+# Because Kbuild is preferred over Makefile for in-tree builds
+# but Kbuild is necessary for an out-of-tree module, we need an
+# explicit dispatch to Makefile if doing an in-tree build.
+ifneq ($(M),)
+ obj-m = verifier.o
+else
+ include $(src)/Makefile
+endif
--
2.47.1