From patchwork Thu Nov 2 21:26:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 10039327 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 B0E19603B5 for ; Thu, 2 Nov 2017 21:28:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94A44293C7 for ; Thu, 2 Nov 2017 21:28:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 867A6293C3; Thu, 2 Nov 2017 21:28:27 +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 C7514293C3 for ; Thu, 2 Nov 2017 21:28:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964953AbdKBV2Z (ORCPT ); Thu, 2 Nov 2017 17:28:25 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:47852 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964946AbdKBV2Y (ORCPT ); Thu, 2 Nov 2017 17:28:24 -0400 Received: by mail-io0-f193.google.com with SMTP id h70so2097555ioi.4 for ; Thu, 02 Nov 2017 14:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=+9pOE+wkG0XMUGMOKbBWC0tdN8Zg+6ZrcDuDjNZo34g=; b=gohEpbN5GmqXRDSuFqFo4DdWR7d1dR1wbiPclKxRnXqflJvaQbdx7JJQMh05fhnMT7 1drQCA8HZiDlgRN2qUqnznmPFqpXy3/R3Bnc3OXKOwXiWz9VKHsxSEoNIFo1z8Rad1k2 OfYiKAa4o4jKeKMFCK8B01kp3osxw4R10B6qEKVFGZSQPxd6mlswlmf3IJRi2mIliFlF aHVNUr7YJbZzU7tKMOpuuMrGkkp7gRKYSg/x/C+1E6tqtbU0oqB8m+8hXc0ca6igO+7F nBWm0anvKOdh92Yv2HXm7dmSThUc//ovdVj1vAUXr1giwo/OGpi2gQFwjibtJuc5Q7hy XxtA== 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; bh=+9pOE+wkG0XMUGMOKbBWC0tdN8Zg+6ZrcDuDjNZo34g=; b=WpdVXNwUHSxtwRbEpv5vq9t90eVg3F8ANV3bZBCDvo2DTwh5UO1S7nLWP6hCMWuPsg SryoMptqlO4K+tXCM70ENi0KdaLTu+u2gpEoabGDHpfEzcSZ4K6NWjZ/NJr6sreDy6EW LLqi4tQ2lvNYZYD58ycCyeORaEDKzZCQUUOBAONZ5O4GzGd/nAaTR1V1B7+ov4VXd6xJ RCleVcMXJ1JDubxpFzUm63yls+Ar88qx7AC9ToodNmoyIcOUJxGrxgaPvcNTc3LwLVZp f5+qDXhpQgp2xfN1G//7MQMkxCwcNmK4wlyjk9nheAA3CktTWCMLPOu6mTiYPQ+wQ3vO tUAA== X-Gm-Message-State: AMCzsaXlgicDzFqDFxe1foXD1IW6YjxS4BtbjHc7MpCRgTIHUsmW7iFQ OE3mMh8JSJtSvNKCHIF6tEdK1A== X-Google-Smtp-Source: ABhQp+SRZD7G3cSbcNozvOhyam6A4+tsLOE04KRPQd4I2U4lBw55jRMFSWs2lETp1jwH78z2Edrg2A== X-Received: by 10.36.85.211 with SMTP id e202mr4602063itb.32.1509658103436; Thu, 02 Nov 2017 14:28:23 -0700 (PDT) Received: from ndesaulniers0.mtv.corp.google.com ([100.123.74.54]) by smtp.gmail.com with ESMTPSA id c13sm287859itd.32.2017.11.02.14.28.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 14:28:22 -0700 (PDT) From: Nick Desaulniers To: Masahiro Yamada Cc: Behan Webster , =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= , Mark Charlebois , Greg Hackmann , Matthias Kaehlcke , Chris Fries , Nick Desaulniers , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] kbuild: Set KBUILD_CFLAGS before incl. arch Makefile Date: Thu, 2 Nov 2017 14:26:48 -0700 Message-Id: <20171102212649.108880-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.15.0.403.gc27cc4dac6-goog 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. We didn't notice this problem on Android, because we took the original LLVMLinux patch into our 4.4 kernels, which did not have this issue. We ran into this taking the proper upstream patch on newer kernel versions. The original LLVMLinux patch can be seen at: http://git.linuxfoundation.org/?p=llvmlinux/kernel.git;a=blobdiff;f=Makefile;h=389006c4ef494cda3a1ee52bf355618673ab4f31;hp=e41a3356abee83f08288362950bfceebd25ec3c2;hb=ef9126da11b18ff34eb1f01561f53c378860336c;hpb=f800c25b7a762d445ba1439a2428c8362157eba6 It seems that when the patch was re-upstreamed, a V2 was requested that moved the definition of Clang's target triple to be later in the top level Makefile than the inclusion of the arch specific Makefile, breaking macros like ld-option when cross compiling. V2 was requested at: https://lkml.org/lkml/2017/4/21/116 Signed-off-by: Chris Fries Signed-off-by: Nick Desaulniers Tested-by: Matthias Kaehlcke Reviewed-by: Matthias Kaehlcke --- Makefile | 64 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 5f91a28a3cea..72ea86157114 100644 --- a/Makefile +++ b/Makefile @@ -512,6 +512,38 @@ ifneq ($(filter install,$(MAKECMDGOALS)),) endif endif +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 + ifeq ($(mixed-targets),1) # =========================================================================== # We're called with mixed targets (*config and build targets). @@ -695,38 +727,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