kbuild: use -fmacro-prefix-map to make __FILE__ a relative path
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Fri, 30 Mar 2018 04:15:26 +0000 (13:15 +0900)
committerBastian Blank <waldi@debian.org>
Fri, 22 Jun 2018 09:50:22 +0000 (10:50 +0100)
commitf9d2c6c1385e76267b8af0e97cb46ce6f38c5425
treeea6e37261766e2609861b98ef44951176f42d5ec
parent28f7883b996ff4f5a9a3d46e7d8540dd7ccb3e18
kbuild: use -fmacro-prefix-map to make __FILE__ a relative path

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>
Gbp-Pq: Topic features/all
Gbp-Pq: Name kbuild-use-fmacro-prefix-map-to-make-__file__-a-rela.patch
Makefile