From patchwork Tue Nov 7 19:46:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 10047195 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 A8D556032D for ; Tue, 7 Nov 2017 19:46:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BC5F292EC for ; Tue, 7 Nov 2017 19:46:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9023928DF1; Tue, 7 Nov 2017 19:46:50 +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=unavailable 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 ECAF328DF1 for ; Tue, 7 Nov 2017 19:46:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753658AbdKGTqi (ORCPT ); Tue, 7 Nov 2017 14:46:38 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:44494 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753643AbdKGTqh (ORCPT ); Tue, 7 Nov 2017 14:46:37 -0500 Received: by mail-io0-f195.google.com with SMTP id m16so3415629iod.1 for ; Tue, 07 Nov 2017 11:46:36 -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=TmFcxzfqI4ioeZmtNzh2dZCPxt35Iw30GfHVRxcEoKk=; b=Y8qN1nlykRNHinRFxSudhxDUEJC+2uLi3bzX/FAf3VtHA7poXlaCL5K+e5CJOYaAGX D+CnVmCMOw/YKAAmxny3YShcG7GyfdA24zN34xHOUE4gtiKv4em0ZQHjA+t5j6SafT3y NwZUQvPay6OoGjMERR9O78f6svMm3Tnf862ZZkETFSY6OAjjM3AukIirl+YCVwuvTVcP +HMShx+wV6NW4C9cbmuFGUUHMWrfoCAkz7zz2CBis6K2cnz4L1DbP8QJiHPMKyAH9QpZ SEEzvYRA5PCc3S1kxOBKI1kynOi/w2j01LG+Swn2eMHAoTsIax4MqrNexE4w7xB4pOZv qBXQ== 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=TmFcxzfqI4ioeZmtNzh2dZCPxt35Iw30GfHVRxcEoKk=; b=BA3b9zHykn/1jBJMs38tG8TkGVFiazOzVJqRzLE6irjRVIquMiBvh9vkFPOnBkBMzf 5gGWrnpSqEkNNb0CPtl6qotmSOcK0HqA4LM90A0IQi+FzxSW7y/Rs0eYZlcKtyzI2qTo wazy96KAgyFl+MuL/UDCBDFNWUCQH0AZ82dLHTl3/z+Mpwd30gIo5ZVkYOhTUo0V8c7o 6cV5g0aSI4HUpM3CJ+SIPTZTDp6BRDC4L5fDW/07ka+yWTOqMzMsTn+7rUPa3MnvzXdq Kjn1VT+5NXjgurVsqo0rUyYTPnrMm7ZD+DsVXb25tok4CUUs2dRAJyGrf7o5aGP6vBI4 ia9A== X-Gm-Message-State: AJaThX5kBRc2qLbvZMcpvgvJKqwmL7cJu/5Bs8xSClGCfj6Jl3FVd2oW IucaQVQXSBxBHUZlrhXCm8fDOQ== X-Google-Smtp-Source: ABhQp+Tp12oIlTDhyOC72o5Zi8mQDxrOUgxIctm6hfamKQk91UaCKJ4AJ5trtRElN1aqqdH6cqxOlw== X-Received: by 10.107.10.82 with SMTP id u79mr25436332ioi.252.1510083995850; Tue, 07 Nov 2017 11:46:35 -0800 (PST) Received: from ndesaulniers0.mtv.corp.google.com ([100.123.74.54]) by smtp.gmail.com with ESMTPSA id 80sm932649ioz.54.2017.11.07.11.46.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Nov 2017 11:46:34 -0800 (PST) From: Nick Desaulniers Cc: Behan Webster , =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= , Mark Charlebois , Greg Hackmann , Matthias Kaehlcke , Chris Fries , Nick Desaulniers , Masahiro Yamada , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] kbuild: Set KBUILD_CFLAGS before incl. arch Makefile Date: Tue, 7 Nov 2017 11:46:13 -0800 Message-Id: <20171107194614.89371-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.15.0.403.gc27cc4dac6-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. 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 Reviewed-by: Matthias Kaehlcke Signed-off-by: Chris Fries Signed-off-by: Nick Desaulniers Tested-by: Matthias Kaehlcke --- Changes since v1: * Rebase on kbuild tree, as per Masahiro. * Add mka's RB/TB line to commit message. Makefile | 64 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index a7476e6934f1..d349734c7ef7 100644 --- a/Makefile +++ b/Makefile @@ -472,6 +472,38 @@ ifneq ($(KBUILD_SRC),) $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) 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 ($(config-targets),1) # =========================================================================== # *config targets only - make sure prerequisites are updated, and descend @@ -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