From patchwork Thu Mar 29 15:40:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132571 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1915046ljb; Thu, 29 Mar 2018 08:42:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/KvPtjFnfjIPdw+m3QMAFRoCs2dEzdQkKQHJyfX7ofN0VS/95AGdmhiwwZvIsK7CXqciPM X-Received: by 10.99.37.196 with SMTP id l187mr5944084pgl.221.1522338161976; Thu, 29 Mar 2018 08:42:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522338161; cv=none; d=google.com; s=arc-20160816; b=BH0KGGAyE4IRS2o7M+FvrSOO827rZusYsZVkWEL9NgXC67vsIAO6+dj3p5fwQmaGC+ ZHU1KBsu6IhJqeXSE4Oqs8oljfrUoxyumKkKTgnBwq0iT5q0KqzWEBR7brkBCxWP7Oei piW71mW5cKifHEpUKV7iWDLEIErHdgVa36D5PU0Ql/9uLI/pljY9ZUe9aJ64A/1MyRtC O5l8McAqzmQYBY/mLMyC3iIDuS6ZBCNE/SSsqoaIaineIbUiBChEJDX68u7BHSjsyWD/ PMqVFU03aLe3MlGhT7cIry87Ah1ldLEt4FU2GW1Ivp8spUDLcmSPOHlr0HN72UDwJjgA 3l6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=sHEgxRJnbdWjM7XLzV0WFDDMn1Cv4T0bXNiR5hHMPew=; b=NZkxVDtSDsXg1z/pmUFQnAqSYWVh8KS7HZCW9ASjtfU7ywrkru6KQ9jNBADDY6xnY2 wegpzex/Mw+av/2FGKuk8akQY/MX3Wd7nqQCqeoDurj584t7TAIy/68mIew0evkH762c HXe/Cn0J6Qqlp79ZdHiYEkb/93LCwjRMjJ5IDbF4Lz7C7tfahPrK5jVOq7umGJ/+3xVB tsoI8rV1e5sNs25Ix/nKo7yfapm3J2NSW4Sj7tbtgPvqEEbenDk7qfXFoaPlydPJ/8Pf 7HH0vEErHXATGTS4ylZdGLQ68hi1jZiK5pKLJ4fcdXBPSiEugsOLyqreZo89Ntu1TtFy fhpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=QTYDZ334; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s16-v6si5972496plp.113.2018.03.29.08.42.41; Thu, 29 Mar 2018 08:42:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=QTYDZ334; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752282AbeC2Pmi (ORCPT + 28 others); Thu, 29 Mar 2018 11:42:38 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:33079 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751182AbeC2Pmh (ORCPT ); Thu, 29 Mar 2018 11:42:37 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2TFerLv018522; Fri, 30 Mar 2018 00:40:53 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2TFerLv018522 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522338054; bh=sHEgxRJnbdWjM7XLzV0WFDDMn1Cv4T0bXNiR5hHMPew=; h=From:To:Cc:Subject:Date:From; b=QTYDZ3342vMuL7b4+NtOKM9Az0CSBQknUaCa0NyjCWNAgEN7cihF1mEQb8/OKucf5 LJ7QcHoO7C2asfhlCNCCB+SRe39KE8oMHv41ihtEnZ1kbr8L07TuM5qwOec6/NZlSH BcFR056i1Rv50MYezPhWYmjjs+bOFW2iY7Zol9aol1wULAhilwbY/99OM7tKmYikEj f2zjb5unVCgKs44+3G/A9DSMehc3G2GVcKxJYDVkEOqYIHiqu4XcxFztBSv+qHsbKx msYhvzZWW5dtJHoAKmHl7E9xBU9quWidnXMQgAMnIticL1RbdU7Hyh440S8OKKdi2K 1KbI/qsQI7AJw== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Greg Kroah-Hartman , Arnd Bergmann , Randy Dunlap , Geert Uytterhoeven , Joe Perches , Sam Ravnborg , Michal Marek , Linus Torvalds , Tom Rini , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2] kbuild: use -fmacro-prefix-map to make __FILE__ a relative path Date: Fri, 30 Mar 2018 00:40:47 +0900 Message-Id: <1522338047-7128-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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== When preprocessing files residing in directory , expand the __FILE__ and __BASE_FILE__ macros as if the files resided in directory instead. This can be used to change an absolute path to a relative path by using . for 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 --- I tested this on GCC 8. (not released yet, but you can get the source code from the trunk.) Changes in v2: - Comment-in the ifeq Makefile | 5 +++++ 1 file changed, 5 insertions(+) -- 2.7.4 diff --git a/Makefile b/Makefile index 7ba478a..5acee54 100644 --- a/Makefile +++ b/Makefile @@ -813,6 +813,11 @@ KBUILD_CFLAGS += $(call cc-option,-ffunction-sections,) KBUILD_CFLAGS += $(call cc-option,-fdata-sections,) endif +# Change __FILE__ to a relative path from the srctree +ifneq ($(KBUILD_SRC),) +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)