summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Spooren2026-09-23 12:52:24 +0000
committerPaul Spooren2026-09-25 16:03:23 +0000
commit50ec6f218ab9d2b507c0c74ed0e14535257dc799 (patch)
tree7caee4e0bf95e6224e59d93e6cb8a10791548f84
parentbbe5cbb665ec1db69e9171e35d4aaa6d3ac0f146 (diff)
kernel: map the kernel tree out of __FILE__ for external modules
Kernel modules from the packages feed differ between builds on 6.18, e.g. kmod-v4l2loopback, kmod-jool-netfilter, kmod-pf-ring and kmod-usb-serial-dmx_usb_module: -/builder/shared-workdir/build/build_dir/.../linux-6.18.52/include/linux/ucopysize.h +/tmp/rebuilderd-openwrt.Xebb8P/src/build_dir/.../linux-6.18.52/include/linux/ucopysize.h These packages call make -C $(LINUX_DIR) M=... without KERNEL_MAKE_FLAGS, so they get none of the OpenWrt prefix maps. With 6.12 that did not matter, since srctree stayed "." and the kernel headers were included by a relative path. Since 6.13 srctree holds the absolute path of the kernel tree for external modules, while kbuild only maps srcroot, the module directory. Add a pending patch that maps the kernel tree for external modules too. It is added before the map of srcroot and before KCFLAGS, and GCC uses the last matching map, so modules built through KERNEL_MAKE_FLAGS keep their current output. Link: https://github.com/openwrt/openwrt/pull/25356 Signed-off-by: Paul Spooren <mail@aparcar.org>
-rw-r--r--target/linux/generic/pending-6.18/206-kbuild-map-the-kernel-tree-for-external-modules.patch42
1 files changed, 42 insertions, 0 deletions
diff --git a/target/linux/generic/pending-6.18/206-kbuild-map-the-kernel-tree-for-external-modules.patch b/target/linux/generic/pending-6.18/206-kbuild-map-the-kernel-tree-for-external-modules.patch
new file mode 100644
index 0000000000..bea8f05d17
--- /dev/null
+++ b/target/linux/generic/pending-6.18/206-kbuild-map-the-kernel-tree-for-external-modules.patch
@@ -0,0 +1,42 @@
+From 7fbe3426fe286332745cbb7464147af6199268a8 Mon Sep 17 00:00:00 2001
+From: Paul Spooren <mail@aparcar.org>
+Date: Fri, 25 Sep 2026 09:53:18 +0200
+Subject: [PATCH] kbuild: map the kernel tree out of __FILE__ for external
+ modules
+
+Since external modules are built in their own directory, srctree holds
+the absolute path of the kernel tree and srcroot the one of the module.
+Only srcroot is mapped with -fmacro-prefix-map, so every __FILE__ taken
+from a kernel header, e.g. by WARN_ON() in an inline function, keeps the
+absolute path of the kernel tree:
+
+ -/builder/shared-workdir/build/build_dir/.../linux-6.18.52/include/linux/ucopysize.h
+ +/tmp/rebuilderd-openwrt.Xebb8P/src/build_dir/.../linux-6.18.52/include/linux/ucopysize.h
+
+Before, make -C $(KERNEL_DIR) M=... left srctree at ".", so the kernel
+headers were included by a relative path.
+
+Map the kernel tree as well when building external modules. Add the map
+before the one of srcroot, since GCC uses the last matching map, so a
+module directory inside the kernel tree is still mapped relative to the
+module.
+
+Signed-off-by: Paul Spooren <mail@aparcar.org>
+---
+ Makefile | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+--- a/Makefile
++++ b/Makefile
+@@ -1106,6 +1106,11 @@ endif
+ export CFLAGS_GCOV
+
+ # change __FILE__ to the relative path to the source directory
++ifdef KBUILD_EXTMOD
++# External modules include the kernel headers by their absolute path. Map
++# them first, so that the map of the module directory below takes precedence.
++KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(abs_srctree)/=)
++endif
+ ifdef building_out_of_srctree
+ KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srcroot)/=)
+ endif