lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1522337766-6476-1-git-send-email-yamada.masahiro@socionext.com>
Date:   Fri, 30 Mar 2018 00:36:06 +0900
From:   Masahiro Yamada <yamada.masahiro@...ionext.com>
To:     linux-kbuild@...r.kernel.org
Cc:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Arnd Bergmann <arnd@...db.de>,
        Randy Dunlap <rdunlap@...radead.org>,
        Geert Uytterhoeven <geert@...ux-m68k.org>,
        Joe Perches <joe@...ches.com>, Sam Ravnborg <sam@...nborg.org>,
        Michal Marek <michal.lkml@...kovi.net>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Tom Rini <trini@...sulko.com>,
        Masahiro Yamada <yamada.masahiro@...ionext.com>,
        linux-kernel@...r.kernel.org
Subject: [PATCH] kbuild: use -fmacro-prefix-map to make __FILE__ a relative path

The __FILE__ macro is used everywhere in the kernel to locate the file
path printing the log message.  The biggest users of this macro are
WARN_ON() and friends.  If the kernel is built out of tree, this could
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.

Commit 9da0763bdd82 ("kbuild: Use relative path when building in a
subdir of the source tree") mitigated the pain 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 solves this problem.

-fmacro-prefix-map=<old>=<new>
  When preprocessing files residing in directory <old>, expand the
  __FILE__ and __BASE_FILE__ macros as if the files resided in
  directory <new> instead.  This can be used to change an absolute
  path to a relative path by using . for <new> which can result in
  more reproducible builds that are location independent.  This
  option also affects __builtin_FILE() during compilation.

If your compiler supports this option, __FILE__ is the relative path
from the root of srctree regardless of O= option.

Please note __FILE__ is always an absolute path for external modules.

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

I tested this on GCC 8.
(not released yet, but you can get the source code from the trunk.)


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

diff --git a/Makefile b/Makefile
index 7ba478a..d2d44f9 100644
--- a/Makefile
+++ b/Makefile
@@ -813,6 +813,11 @@ KBUILD_CFLAGS	+= $(call cc-option,-ffunction-sections,)
 KBUILD_CFLAGS	+= $(call cc-option,-fdata-sections,)
 endif
 
+#ifneq ($(KBUILD_SRC),)
+# Change __FILE__ to a relative path from the srctree
+KBUILD_CFLAGS	+= $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
+#endif
+
 # arch Makefile may override CC so keep this after arch Makefile is included
 NOSTDINC_FLAGS += -nostdinc -isystem $(call shell-cached,$(CC) -print-file-name=include)
 CHECKFLAGS     += $(NOSTDINC_FLAGS)
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ