From patchwork Thu Mar 29 15:36:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132569 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1910789ljb; Thu, 29 Mar 2018 08:38:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+uLJ1v6nHIacgfW7E8uMnr/qZHaud+lpvkFxURwXRbLy8fRz0xhsBTSGKsrTs+RTv7mLOV X-Received: by 2002:a17:902:8609:: with SMTP id f9-v6mr4040045plo.8.1522337918906; Thu, 29 Mar 2018 08:38:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522337918; cv=none; d=google.com; s=arc-20160816; b=uTSO7ZUOkX1jUw7GNVd3Vs7mcuQW88ODbAQY1welbmfT19MR70XHSJwGFCEEQa7Jr3 bPTkfbnuvHaUqERNMbngtZ2tFD3iIGHBBgxGki69MzMKLn2NO79qT98S4BSxYLD+cK8q AW+OiJVmIu0TYLxbhxmXp5gVuTPehg99RarElEGElb+8JpxtGIusA8GPayMqoPeMKTvh JGGy6XsqwPkxmimKiJIQ7yk9tKh+j/cEoP26fyCNDyPC6owBZPOSOAmnIN9E5SRRUlNm EwGmGCkx0C1DiVcM7FVzJIsbxDwaZoogKTFNwngfeNrV6d+/wrxauU85aiMzUeQi8aB3 GmYA== 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=ASsa6c/3FTooetj52xY3Ni62T7HMSHEXBvPm6pDXRdk=; b=n4Fzo2VmmRhRnZbmMIxjo/F9EorUZwGnYcqFLTw6LN/o6k9XEz1nfDuvHU1uE8kqHJ JNQOQX9iCVkyWU32YNZrfYOClorZIqpYk6k6RX+Anus9zjnm7HOd96vx9q+Dz2DdkOnk Cb2u0387jDSvfUZ+IuOVYX1mAfAgq0A/U56fKHtM3mcc4vp7ZS7WzbvLYiGH3qxiwVqb HDM6PWBfVkVrzoUSdnwQELEcWk+NvZaC873NGYvOY1vjtJN2svybFhw4zPAt+NpOqS1N b8WKPHMxd28nBx/eAJx9ctM1nsgWBDOd9KkE3KwhuR25FigdVEGVijNzuWFoNMBmBOUo gt4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=wwsobpKo; 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 b9-v6si2069526pls.485.2018.03.29.08.38.38; Thu, 29 Mar 2018 08:38:38 -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=wwsobpKo; 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 S1752199AbeC2Pif (ORCPT + 28 others); Thu, 29 Mar 2018 11:38:35 -0400 Received: from conuserg-12.nifty.com ([210.131.2.79]:56170 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751215AbeC2Pid (ORCPT ); Thu, 29 Mar 2018 11:38:33 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-12.nifty.com with ESMTP id w2TFac1c000897; Fri, 30 Mar 2018 00:36:38 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w2TFac1c000897 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522337799; bh=ASsa6c/3FTooetj52xY3Ni62T7HMSHEXBvPm6pDXRdk=; h=From:To:Cc:Subject:Date:From; b=wwsobpKoiRVnLSW0c7VPOcbhsL4QZBQAOwWlN5F9nvvn0o0jR6ifgWg7i5nxrdicV oTZdifLfu0YWvmEu816h7MRSkyoy4rU/fZaNaF/5ENFdXCPF5ad56Jvr87FPVw4HeW Fxt6YxpdD0+hSwgIKUdnH2g7jngF6iT3rNa5SHXU2H4tcGz9srsbmLkVem8cF+/d07 /ua//SNrHGidT0YF/xb5e5wVW/cfWIEu8IjUIucFg6LvcwemPpQa7iAarDvyfve2xl k2NnGsZPo50Z7ZrLauKoKKixTV/es9QQoSo7VqyGqzr8yFy5YDkiwBQncsu4yF5XvX F2gCVxXRjqVHg== 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] kbuild: use -fmacro-prefix-map to make __FILE__ a relative path Date: Fri, 30 Mar 2018 00:36:06 +0900 Message-Id: <1522337766-6476-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.) Makefile | 5 +++++ 1 file changed, 5 insertions(+) -- 2.7.4 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)