From patchwork Wed Nov 15 20:42:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 10060237 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BADB26023A for ; Wed, 15 Nov 2017 20:42:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE0802A2E5 for ; Wed, 15 Nov 2017 20:42:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B23442A2EF; Wed, 15 Nov 2017 20:42:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F2CD2A2EE for ; Wed, 15 Nov 2017 20:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934354AbdKOUmx (ORCPT ); Wed, 15 Nov 2017 15:42:53 -0500 Received: from mail-it0-f68.google.com ([209.85.214.68]:41730 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934331AbdKOUmo (ORCPT ); Wed, 15 Nov 2017 15:42:44 -0500 Received: by mail-it0-f68.google.com with SMTP id x28so3291853ita.0 for ; Wed, 15 Nov 2017 12:42:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H98bEq5+tnXuV0FnTEKrnnqBFaczTId2r8yfYEvu7PY=; b=NNY/gO9O3RJ/bRYs/OoewZSRRLi9fJ7ZDjzHiFvIuJQMh+S93aFFFrUJTrBzkR64yc Sp1oIzOh8PwClIQZuFC7J1q3vXKAH8YdpFWdqpQrFFjQaYOrBEtso9yhq8ULywUL30m/ PH2NRs/rTaXUDrSU2v+yaGmrejenDLjxt9EJKiU2WRw4atXB58KiDYqnR8akb08lZ5R7 F+A6DFZydvrZzGr9ZUmqmr3Io69b/lEy/V9V5pNp97id0AdkiHgSRX1koGgtobkywG/o 9ipCK22Ot+WA5ub6MYEKJZ0OgmxNs0U+GyTjKwgWrsR4giL0ffZe612X44grxJlp69bU pYMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=H98bEq5+tnXuV0FnTEKrnnqBFaczTId2r8yfYEvu7PY=; b=YwGYk2zZ61GhW0+F4plCa8a2ciLztJ0CsMrVbC4c9LLLeE4MrG65BbtYAewgyhpDoK 9SvFtinwPHOu53HgmYHJXE07xDm+INWvGDX3dOBqhWmHPI+ZnpttrpNxYkJjMXU/k63h WoO6fd5GjQeZNghVkDI1NBtjzhYMZwNvnMx8WEO0ZYrBIxejZJaD/sP3fu5qMsB/0HX0 J9n4t7/rxHN4+5GYLO87cuoPVagDl0IT8MHXTmjTYg15gIp+qT5902eO4h1nHsPmLF41 cFuoxsZdh9oaLJTywwjk944CwATNW+wav4jCleRgi/U55s2Jos5gBtZNOgUmJMCcWUI4 qrlQ== X-Gm-Message-State: AJaThX5lzRbPSZwhPyzIbd27mY+eZjNx+Gap2jTJr/U/IQpjNkegVkM5 7LvfHywdQCQYghetgaUPCo8TwQ== X-Google-Smtp-Source: AGs4zMa4FwGbIyV0yRIOBd4QjNYSNnYCyS5NbmjBCpBZUbcKESlGVS6p3yCMOyR/oZLCZuNx//pY8A== X-Received: by 10.36.5.149 with SMTP id 143mr22472035itl.105.1510778562932; Wed, 15 Nov 2017 12:42:42 -0800 (PST) Received: from ndesaulniers0.mtv.corp.google.com ([100.123.74.54]) by smtp.gmail.com with ESMTPSA id v76sm7063015itb.1.2017.11.15.12.42.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Nov 2017 12:42:41 -0800 (PST) From: Nick Desaulniers Cc: Behan Webster , =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= , Mark Charlebois , Greg Hackmann , Matthias Kaehlcke , Douglas Anderson , Chris Fries , Nick Desaulniers , Masahiro Yamada , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] kbuild: Set KBUILD_CFLAGS before incl. arch Makefile Date: Wed, 15 Nov 2017 12:42:30 -0800 Message-Id: <20171115204231.34914-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.15.0.448.gf294e3d99a-goog In-Reply-To: References: To: unlisted-recipients:; (no To-header on input) Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Chris Fries Set the clang KBUILD_CFLAGS up before including arch/ Makefiles, so that ld-options (etc.) can work correctly. This fixes errors with clang such as ld-options trying to CC against your host architecture, but LD trying to link against your target architecture. Reviewed-by: Matthias Kaehlcke Signed-off-by: Chris Fries Signed-off-by: Nick Desaulniers Suggested-by: Masahiro Yamada Tested-by: Matthias Kaehlcke --- Changes since v2: * Move clang block lower in Makefile, so as not to run it when running configuration, per Masahiro. * Remove paragraphs from commit message, per Masahiro. * Add Masahiro to Suggested-by line in commit message. Makefile | 64 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index a7476e6934f1..b3352becc7df 100644 --- a/Makefile +++ b/Makefile @@ -608,6 +608,38 @@ CFLAGS_GCOV := -fprofile-arcs -ftest-coverage -fno-tree-loop-im $(call cc-disabl CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,) export CFLAGS_GCOV CFLAGS_KCOV +ifeq ($(cc-name),clang) +ifneq ($(CROSS_COMPILE),) +CLANG_TARGET := -target $(notdir $(CROSS_COMPILE:%-=%)) +GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..) +endif +ifneq ($(GCC_TOOLCHAIN),) +CLANG_GCC_TC := -gcc-toolchain $(GCC_TOOLCHAIN) +endif +KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) +KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) +KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) +KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) +KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) +KBUILD_CFLAGS += $(call cc-disable-warning, gnu) +KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) +# Quiet clang warning: comparison of unsigned expression < 0 is always false +KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare) +# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the +# source of a reference will be _MergedGlobals and not on of the whitelisted names. +# See modpost pattern 2 +KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,) +KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior) +KBUILD_CFLAGS += $(call cc-option, -no-integrated-as) +KBUILD_AFLAGS += $(call cc-option, -no-integrated-as) +else + +# These warnings generated too much noise in a regular build. +# Use make W=1 to enable them (see scripts/Makefile.extrawarn) +KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) +KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) +endif + # The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default # values of the respective KBUILD_* variables ARCH_CPPFLAGS := @@ -682,38 +714,6 @@ ifdef CONFIG_CC_STACKPROTECTOR endif KBUILD_CFLAGS += $(stackp-flag) -ifeq ($(cc-name),clang) -ifneq ($(CROSS_COMPILE),) -CLANG_TARGET := -target $(notdir $(CROSS_COMPILE:%-=%)) -GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..) -endif -ifneq ($(GCC_TOOLCHAIN),) -CLANG_GCC_TC := -gcc-toolchain $(GCC_TOOLCHAIN) -endif -KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) -KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) -KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) -KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) -KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) -KBUILD_CFLAGS += $(call cc-disable-warning, gnu) -KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) -# Quiet clang warning: comparison of unsigned expression < 0 is always false -KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare) -# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the -# source of a reference will be _MergedGlobals and not on of the whitelisted names. -# See modpost pattern 2 -KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,) -KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior) -KBUILD_CFLAGS += $(call cc-option, -no-integrated-as) -KBUILD_AFLAGS += $(call cc-option, -no-integrated-as) -else - -# These warnings generated too much noise in a regular build. -# Use make W=1 to enable them (see scripts/Makefile.extrawarn) -KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) -KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) -endif - ifdef CONFIG_FRAME_POINTER KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls else