[PATCH 20/23] kbuild: support -fmacro-prefix-map for external modules

Masahiro Yamada posted 23 patches 2 months, 1 week ago
There is a newer version of this series
[PATCH 20/23] kbuild: support -fmacro-prefix-map for external modules
Posted by Masahiro Yamada 2 months, 1 week ago
This commit makes -fmacro-prefix-map work for external modules built in
a separate output directory. It improves the reproducibility of external
modules and provides the benefits described in commit a73619a845d5
("kbuild: use -fmacro-prefix-map to make __FILE__ a relative path").

When VPATH is not defined (e.g., when the kernel or external module is
built in the source directory), this option is unnecessary.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index b654baa0763a..ce646a6994a6 100644
--- a/Makefile
+++ b/Makefile
@@ -1027,8 +1027,10 @@ ifdef CONFIG_CC_IS_GCC
 KBUILD_CFLAGS   += -fconserve-stack
 endif
 
-# change __FILE__ to the relative path from the srctree
-KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
+# change __FILE__ to the relative path to the source directory
+ifdef VPATH
+KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(VPATH)/=)
+endif
 
 # include additional Makefiles when needed
 include-y			:= scripts/Makefile.extrawarn
-- 
2.43.0
Re: [PATCH 20/23] kbuild: support -fmacro-prefix-map for external modules
Posted by Nicolas Schier 1 month, 3 weeks ago
On Tue, Sep 17, 2024 at 11:16:48PM +0900, Masahiro Yamada wrote:
> This commit makes -fmacro-prefix-map work for external modules built in
> a separate output directory. It improves the reproducibility of external
> modules and provides the benefits described in commit a73619a845d5
> ("kbuild: use -fmacro-prefix-map to make __FILE__ a relative path").
> 
> When VPATH is not defined (e.g., when the kernel or external module is
> built in the source directory), this option is unnecessary.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
>  Makefile | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>