diff mbox series

kbuild: use -fmacro-prefix-map to make __FILE__ a relative path

Message ID 1523852311-15588-1-git-send-email-yamada.masahiro@socionext.com
State Accepted
Commit 1eb2e71edd55e16562e3912881c449db69623352
Headers show
Series kbuild: use -fmacro-prefix-map to make __FILE__ a relative path | expand

Commit Message

Masahiro Yamada April 16, 2018, 4:18 a.m. UTC
The __FILE__ macro is used everywhere in U-Boot to locate the file
printing the log message, such as WARN_ON(), etc.  If U-Boot is
built out of tree, this can be a long absolute path.

This is because Kbuild runs in the objtree instead of the srctree,
then __FILE__ is expanded to a file path prefixed with $(srctree)/.

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,
more reproducible builds, and smaller image size.

[ Linux commit: a73619a845d5625079cc1b3b820f44c899618388 ]

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

GCC 8 is required to use this new option.


 Makefile | 3 +++
 1 file changed, 3 insertions(+)

Comments

Simon Glass April 17, 2018, 3:10 p.m. UTC | #1
On 15 April 2018 at 22:18, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
>
> The __FILE__ macro is used everywhere in U-Boot to locate the file
> printing the log message, such as WARN_ON(), etc.  If U-Boot is
> built out of tree, this can be a long absolute path.
>
> This is because Kbuild runs in the objtree instead of the srctree,
> then __FILE__ is expanded to a file path prefixed with $(srctree)/.
>
> 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,
> more reproducible builds, and smaller image size.
>
> [ Linux commit: a73619a845d5625079cc1b3b820f44c899618388 ]
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
> GCC 8 is required to use this new option.
>
>
>  Makefile | 3 +++
>  1 file changed, 3 insertions(+)
>

Great!

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini April 28, 2018, 10:19 p.m. UTC | #2
On Mon, Apr 16, 2018 at 01:18:31PM +0900, Masahiro Yamada wrote:

> The __FILE__ macro is used everywhere in U-Boot to locate the file

> printing the log message, such as WARN_ON(), etc.  If U-Boot is

> built out of tree, this can be a long absolute path.

> 

> This is because Kbuild runs in the objtree instead of the srctree,

> then __FILE__ is expanded to a file path prefixed with $(srctree)/.

> 

> 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,

> more reproducible builds, and smaller image size.

> 

> [ Linux commit: a73619a845d5625079cc1b3b820f44c899618388 ]

> 

> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

> Reviewed-by: Simon Glass <sjg@chromium.org>


Applied to u-boot/master, thanks!

-- 
Tom
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 5cfe43f..243add1 100644
--- a/Makefile
+++ b/Makefile
@@ -595,6 +595,9 @@  endif
 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
 KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks)
 
+# change __FILE__ to the relative path from the srctree
+KBUILD_CFLAGS	+= $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
+
 KBUILD_CFLAGS	+= -g
 # $(KBUILD_AFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
 # option to the assembler.