From patchwork Fri Mar 30 04:15:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132587 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp2572169ljb; Thu, 29 Mar 2018 21:17:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx49iDDqzLm9WJwgWGNqNLdqGbruFoFgywmaO8dgXoaisEBo7+Mhlnkl0MvKpnmRIvmVSS7x/ X-Received: by 2002:a17:902:566:: with SMTP id 93-v6mr10968604plf.327.1522383459399; Thu, 29 Mar 2018 21:17:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522383459; cv=none; d=google.com; s=arc-20160816; b=U2qm4n2ibI+xxhBrQkU+5u/I3aUHEjGEkbZ1SF61+HbDvcAeQAQ7Tvp5Gzx/tJKW3D WRhKzmSJUHnbfuVaWdO0dWssdc2p6jIfnW91Me9jZgAUN11lA7L1G4bP2okEkuPClhn3 CHN6kFNWTbDG6eKAi3yi4Y3Bzsa36kZSlOVNy3oYkUg6N3GVxAsZwc6kl8RlLatB9dBy 2GiNWZPxbvLRuTW70YU4ucYpbGlD3UjQZ7fBd/2m+X2xivfj8tk5z5BZX9cTVwe5WwMQ UrJcJ/WHvUc+zl+KCg/S0IzaTNjob4nuaN1DSXeGfjYWCeEMGbJR1YYgXxEdQHS5THJK QxHQ== 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=O3LwoY7L+nMa/z0pl8tqBGnf4ydtnDcQUBBNN+QbOBg=; b=Y1g/zsFSeH9VTligkVCs7DnKG5VXUPhfhWU1B4XY2rvIcRoP8AVI2NeEYG/TyhtBVG j/ExlV6u1VgQGennu2VEsnbwaIMWBCc6pIfeJA4YZI8s9o2DXoWajamCapsxcdKtF6/i slvc7FcyhLH10e2YSHT7gNxgKpXZRuJ/LIXJ4EFxK07SwPbtL+7Uvbva5cTmXMY2+SNH GUT4CgbQdikuDHV5AOwB7cLEj+FTYXjUHSkxBkdVnFLUvSWDTleiTfk80bqv92hbHzjd KkFtsCMdpDkAVheMHEHaSx3LOXhPb+fr4FfA8xrrH5TMpahCyZHV2nmhziR3pT3m2AUU 3MyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=wKkwTII4; 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 68si1134316pfe.402.2018.03.29.21.17.39; Thu, 29 Mar 2018 21:17:39 -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=wKkwTII4; 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 S1751248AbeC3ERd (ORCPT + 29 others); Fri, 30 Mar 2018 00:17:33 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24910 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751129AbeC3ERb (ORCPT ); Fri, 30 Mar 2018 00:17:31 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w2U4FiLC008081; Fri, 30 Mar 2018 13:15:45 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w2U4FiLC008081 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522383345; bh=O3LwoY7L+nMa/z0pl8tqBGnf4ydtnDcQUBBNN+QbOBg=; h=From:To:Cc:Subject:Date:From; b=wKkwTII4jQmR6wYlB0AlLpYR3i+n5TUHs8I5nIr27G5bHJ6nnGIsqOU+S8nHTdFRs EOIirTYzRJAC0fMAABBHl14CNWJfR4nQIt4qxPAcGp44KTxdAyhz5kAJo3zCmwcsBq Vvdow+DiVGOnAOsfLwaeTPeaFYxuv9lHJajupVaQ81ynDrb7dMMZu4X2ymShftBKFC +v9kleYkADSyEsG4gE/LEZ2EiZ3O1JfhH8QnOQb36fvO8gIWxr8UBiIcyqma5B+tgr vI/0ZWG+P/qEw9c0x026NY7Rg6pJ3GkR2fgSxwGy1yHPoQcR/LwLyN5C/Lx1bRqhW2 dV0vQ8bF/bseg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Greg KH , Michal Marek , Linus Torvalds , Tom Rini , Joe Perches , Randy Dunlap , Sam Ravnborg , Geert Uytterhoeven , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v3] kbuild: use -fmacro-prefix-map to make __FILE__ a relative path Date: Fri, 30 Mar 2018 13:15:26 +0900 Message-Id: <1522383326-3880-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 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 --- 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(+) -- 2.7.4 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)