LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v3] kbuild: use -fmacro-prefix-map to make __FILE__ a relative path
@ 2018-03-30 4:15 Masahiro Yamada
2018-04-05 14:50 ` Masahiro Yamada
0 siblings, 1 reply; 2+ messages in thread
From: Masahiro Yamada @ 2018-03-30 4:15 UTC (permalink / raw)
To: linux-kbuild
Cc: Greg KH, Michal Marek, Linus Torvalds, Tom Rini, Joe Perches,
Randy Dunlap, Sam Ravnborg, Geert Uytterhoeven, Masahiro Yamada,
linux-kernel
The __FILE__ macro is used everywhere in the kernel to locate the file
printing the log message, such as WARN_ON(), etc. If the kernel is
built out of tree, this can be a long absolute path, like this:
WARNING: CPU: 1 PID: 1 at /path/to/build/directory/arch/arm64/kernel/foo.c:...
This is because Kbuild runs in the objtree instead of the srctree,
then __FILE__ is expanded to a file path prefixed with $(srctree)/.
Commit 9da0763bdd82 ("kbuild: Use relative path when building in a
subdir of the source tree") improved this to some extent; $(srctree)
becomes ".." if the objtree is a child of the srctree.
For other cases of out-of-tree build, __FILE__ is still the absolute
path. It also means the kernel image depends on where it was built.
A brand-new option from GCC, -fmacro-prefix-map, solves this problem.
If your compiler supports it, __FILE__ is the relative path from the
srctree regardless of O= option. This provides more readable log and
more reproducible builds.
Please note __FILE__ is always an absolute path for external modules.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
I tested this on GCC 8.
(not released yet, but you can get the source code from the trunk.)
Changes in v3:
- It is harmless to always set this option.
Remove ifneq ifneq ($(KBUILD_SRC),)
Changes in v2:
- Comment-in the ifeq
Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Makefile b/Makefile
index 7ba478a..83d25c9 100644
--- a/Makefile
+++ b/Makefile
@@ -856,6 +856,9 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
# Require designated initializers for all marked structures
KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
+# change __FILE__ to the relative path from the srctree
+KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
+
# use the deterministic mode of AR if available
KBUILD_ARFLAGS := $(call ar-option,D)
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] kbuild: use -fmacro-prefix-map to make __FILE__ a relative path
2018-03-30 4:15 [PATCH v3] kbuild: use -fmacro-prefix-map to make __FILE__ a relative path Masahiro Yamada
@ 2018-04-05 14:50 ` Masahiro Yamada
0 siblings, 0 replies; 2+ messages in thread
From: Masahiro Yamada @ 2018-04-05 14:50 UTC (permalink / raw)
To: Linux Kbuild mailing list
Cc: Greg KH, Michal Marek, Linus Torvalds, Tom Rini, Joe Perches,
Randy Dunlap, Sam Ravnborg, Geert Uytterhoeven, Masahiro Yamada,
Linux Kernel Mailing List
2018-03-30 13:15 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> The __FILE__ macro is used everywhere in the kernel to locate the file
> printing the log message, such as WARN_ON(), etc. If the kernel is
> built out of tree, this can be a long absolute path, like this:
>
> WARNING: CPU: 1 PID: 1 at /path/to/build/directory/arch/arm64/kernel/foo.c:...
>
> This is because Kbuild runs in the objtree instead of the srctree,
> then __FILE__ is expanded to a file path prefixed with $(srctree)/.
>
> Commit 9da0763bdd82 ("kbuild: Use relative path when building in a
> subdir of the source tree") improved this to some extent; $(srctree)
> becomes ".." if the objtree is a child of the srctree.
>
> For other cases of out-of-tree build, __FILE__ is still the absolute
> path. It also means the kernel image depends on where it was built.
>
> A brand-new option from GCC, -fmacro-prefix-map, solves this problem.
> If your compiler supports it, __FILE__ is the relative path from the
> srctree regardless of O= option. This provides more readable log and
> more reproducible builds.
>
> Please note __FILE__ is always an absolute path for external modules.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
> I tested this on GCC 8.
> (not released yet, but you can get the source code from the trunk.)
Applied to linux-kbuild.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-04-05 14:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-30 4:15 [PATCH v3] kbuild: use -fmacro-prefix-map to make __FILE__ a relative path Masahiro Yamada
2018-04-05 14:50 ` Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).