[PATCH] kbuild: use prefix-map for host and user progs

From: Thomas Weißschuh

Date: Wed Aug 19 2026 - 03:54:01 EST


Host and user progs may also use __FILE__.

Make sure it shows up canonicalized, as in regular kernel code.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
---
Makefile | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 130926fa592e..322b5ce9f218 100644
--- a/Makefile
+++ b/Makefile
@@ -1188,7 +1188,10 @@ export CFLAGS_GCOV

# change __FILE__ to the relative path to the source directory
ifdef building_out_of_srctree
-KBUILD_CPPFLAGS += -fmacro-prefix-map=$(srcroot)/=
+CFLAGS_PREFIX_MAP := -fmacro-prefix-map=$(srcroot)/=
+KBUILD_CPPFLAGS += $(CFLAGS_PREFIX_MAP)
+KBUILD_USERCFLAGS += $(CFLAGS_PREFIX_MAP)
+KBUILD_HOSTCFLAGS += $(CFLAGS_PREFIX_MAP)
ifeq ($(call rustc-option-yn, --remap-path-scope=macro),y)
KBUILD_RUSTFLAGS += --remap-path-prefix=$(srcroot)/= --remap-path-scope=macro
endif

---
base-commit: bd5f485f3f026225b86573e559af0b7254ef4184
change-id: 20260819-kbuild-prefix-map-5a056c1baa98

Best regards,
--
Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>