From patchwork Sat Mar 25 00:02:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 9644255 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 5057060327 for ; Sat, 25 Mar 2017 00:03:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AFD727165 for ; Sat, 25 Mar 2017 00:03:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FA6C27CF9; Sat, 25 Mar 2017 00:03:22 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 0BD4327317 for ; Sat, 25 Mar 2017 00:03:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936641AbdCYADI (ORCPT ); Fri, 24 Mar 2017 20:03:08 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:34008 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936628AbdCYADB (ORCPT ); Fri, 24 Mar 2017 20:03:01 -0400 Received: by mail-pg0-f41.google.com with SMTP id 21so2412542pgg.1 for ; Fri, 24 Mar 2017 17:02:55 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=FKz32dl7+xZGJKK/H173wPynxGt0LfuCV9JXH20l+8w=; b=niEdpFygo5iNcffTNJvHSiTqjBGKN0IpkS0i4geq334dFvfqlmkgrxM8X0dvRUaM65 +en0Q/nwXI47/uRr4lZKSYkK/MTs6GX4DNX1UFEY9QIO6e7kFRaYA/Lj1gveOCPLllkc 7HgsEIqpXgpKA5wSESisjgm5hUZSnOZhopd0Ldmuzj6ru4Sj2Y8F6xZvWu5rbjSefekK +nj789z8UdzrIlfc/4n+O9jtAFIr31FlKmXGUAITz5KlV8oXypF1fxBHUrss+Ro2K7Ot uW6t+LbXEZhKzrugxvQt1EHg3kJ35WdyC2GTY6uhEHEi1iC+SXEZwR8p4ylXKnxqUnVZ R4wQ== X-Gm-Message-State: AFeK/H38fuPvS+Zj+4Xbxbo8DIsf10BKvkZi3BCMPf1fnA2NZiSw/o+ptwyAi7yoRaJt9GWl X-Received: by 10.98.100.88 with SMTP id y85mr12132431pfb.112.1490400174471; Fri, 24 Mar 2017 17:02:54 -0700 (PDT) Received: from mka.mtv.corp.google.com ([172.22.64.162]) by smtp.gmail.com with ESMTPSA id x65sm6679491pfb.111.2017.03.24.17.02.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 17:02:53 -0700 (PDT) From: Matthias Kaehlcke To: Michal Marek Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Behan Webster , Grant Grundler , Greg Hackmann , Michael Davidson , Peter Foley , Matthias Kaehlcke Subject: [PATCH] kbuild: Add better clang cross build support Date: Fri, 24 Mar 2017 17:02:48 -0700 Message-Id: <20170325000248.101855-1-mka@chromium.org> X-Mailer: git-send-email 2.12.1.578.ge9c3154ca4-goog MIME-Version: 1.0 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 Add cross target to CC if using clang. Also add custom gcc toolchain path for fallback gcc tools. COMPILER is previously set to "clang" if CC=clang was set from the make command line. So -target and -gcc-toolchain can be added to CC, since we already know that it is set. Clang will fallback to using things like ld, as, and libgcc if (respectively) one of the llvm linkers isn't available, the integrated assembler is turned off, or an appropriately cross-compiled version of compiler-rt isn't available. To this end, you can specify the path to this fallback gcc toolchain with GCC_TOOLCHAIN. From: Behan Webster Signed-off-by: Behan Webster Reviewed-by: Jan-Simon Möller Reviewed-by: Mark Charlebois Signed-off-by: Greg Hackmann Signed-off-by: Matthias Kaehlcke --- Makefile | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b2faa9319372..b0f6ef67028d 100644 --- a/Makefile +++ b/Makefile @@ -375,6 +375,16 @@ LDFLAGS_vmlinux = CFLAGS_GCOV = -fprofile-arcs -ftest-coverage -fno-tree-loop-im -Wno-maybe-uninitialized CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,) +ifeq ($(cc-name),clang) +ifneq ($(CROSS_COMPILE),) +CLANG_TARGET := -target $(notdir $(CROSS_COMPILE:%-=%)) +GCC_TOOLCHAIN := $(dir $(CROSS_COMPILE)) +endif +ifneq ($(GCC_TOOLCHAIN),) +CLANG_GCC_TC := -gcc-toolchain $(GCC_TOOLCHAIN) +endif +CLANG_FLAGS := $(CLANG_TARGET) $(CLANG_GCC_TC) +endif # Use USERINCLUDE when you must reference the UAPI directories only. USERINCLUDE := \ @@ -395,18 +405,18 @@ LINUXINCLUDE := \ LINUXINCLUDE += $(filter-out $(LINUXINCLUDE),$(USERINCLUDE)) -KBUILD_CPPFLAGS := -D__KERNEL__ +KBUILD_CPPFLAGS := -D__KERNEL__ $(CLANG_FLAGS) KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -fno-common \ -Werror-implicit-function-declaration \ -Wno-format-security \ - -std=gnu89 $(call cc-option,-fno-PIE) - + -std=gnu89 $(call cc-option,-fno-PIE) \ + $(CLANG_FLAGS) KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := -KBUILD_AFLAGS := -D__ASSEMBLY__ $(call cc-option,-fno-PIE) +KBUILD_AFLAGS := -D__ASSEMBLY__ $(call cc-option,-fno-PIE) $(CLANG_FLAGS) KBUILD_AFLAGS_MODULE := -DMODULE KBUILD_CFLAGS_MODULE := -DMODULE KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds