From patchwork Fri Oct 27 20:13:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 10030581 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 EE9D26022E for ; Fri, 27 Oct 2017 20:13:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D159228FD7 for ; Fri, 27 Oct 2017 20:13:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C48C828FDA; Fri, 27 Oct 2017 20:13:54 +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 2E0DA28FD7 for ; Fri, 27 Oct 2017 20:13:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751786AbdJ0UNx (ORCPT ); Fri, 27 Oct 2017 16:13:53 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:55219 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751516AbdJ0UNw (ORCPT ); Fri, 27 Oct 2017 16:13:52 -0400 Received: by mail-io0-f194.google.com with SMTP id e89so15130215ioi.11 for ; Fri, 27 Oct 2017 13:13:52 -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:in-reply-to:references; bh=ZPswCdhBHst//Sp8b/A1dDBIS+pOWISnhFl2D2mnluE=; b=Lkku+6GjwGR+9lU7wrNejCccsx3c4NNfuw86MC1Yc3cvvsdxS6yYa1EYJUHu/GEh0Q 3fPvgdaec938yqYxo9rdtGVQZ0rHKih8lrHCzqwiTZNWdQTih20jUfiwb0A6gJ9oTofO CX3iFrR+QdyBBGM4ov0UU2T0XlsvLF4G5rd8+mWZJrc6Ek+8RmI+pTover5GpkqYfkRn VVwp5Ey7AtsOqguiIED1fLp4B21HZonbDEm/SmUJsOZQVs37WTH6Km+4rQ26HQ3sM/8J a+Gf9oEC77t0RMmCcXd69+jojwQOL+ua/CQpCQ2GZEER8/DS9raqHOAhek+S2B12PT3X R3sA== 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=ZPswCdhBHst//Sp8b/A1dDBIS+pOWISnhFl2D2mnluE=; b=nJlZvwNWbYaIVesqraq0q35VDATdJQADVK17P6/FOs9YM3pdc3AYXsGqIDiBy5VnUx NQTOaPjwWWFgbV46oyD3K81KUfGC6NH00SbyHIqkFvCP2Vgs6jUQYrq+6Qnabl3zkkEa 8siMP+GPtUwdfSIxtHsEJ8bU65nYMQP1QcQ9w8jOUFLXITrok8XgNK1N+Yjdsmii3993 APyMadVnUjR4ayX2szJ04apF0O38Oc7yDdGHeg/GiWo5hJq/Bu7oE50vKo+joGf7tIn+ 9ZDq8ZUjY/kuRxFlNABw1CsneMnQhG1AlBY92sfZYxD3kN0DKfvkKot+6wjfMdkVqDmU cjdA== X-Gm-Message-State: AMCzsaXBbg6bPJ5lNfXCQNjj2UwOWnDZSmnuBjuqlyZw44TBXE5aL1o9 1tKbg4DJLZmAX9qQN6wt66fM/bi0yiCLPQ== X-Google-Smtp-Source: ABhQp+TCzANnZGYb/0UoJXZrmzItGewxI8K4ceyU9pKC0JF+JPJIFYqA2rXTO1lfGoq/S5rsHli7HQ== X-Received: by 10.36.242.132 with SMTP id j126mr2162600ith.141.1509135231231; Fri, 27 Oct 2017 13:13:51 -0700 (PDT) Received: from ndesaulniers0.mtv.corp.google.com ([100.98.120.97]) by smtp.gmail.com with ESMTPSA id 79sm1258436itu.7.2017.10.27.13.13.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Oct 2017 13:13:49 -0700 (PDT) From: Nick Desaulniers To: linux-kbuild@vger.kernel.org, Masahiro Yamada Cc: md@google.com, ghackmann@google.com, pirama@google.com, Nick Desaulniers , Douglas Anderson , Ingo Molnar , Matthias Kaehlcke , Arnd Bergmann , Marcin Nowakowski , Mark Charlebois , Josh Poimboeuf , Cao jin , linux-kernel@vger.kernel.org Subject: [PATCH v2] kbuild: fix linker feature test macros when cross compiling with Clang Date: Fri, 27 Oct 2017 13:13:43 -0700 Message-Id: <20171027201345.87383-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.15.0.rc2.357.g7e34df9404-goog In-Reply-To: References: 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 I was not seeing my linker flags getting added when using ld-option when cross compiling with Clang. Upon investigation, this seems to be due to a difference in how GCC vs Clang handle cross compilation. GCC is configured at build time to support one backend, that is implicit when compiling. Clang is explicit via the use of `-target ` and ships with all supported backends by default. GNU Make feature test macros that compile then link will always fail when cross compiling with Clang unless Clang's triple is passed along to the compiler. For example: $ clang -x c /dev/null -c -o temp.o $ aarch64-linux-android/bin/ld -E temp.o aarch64-linux-android/bin/ld: unknown architecture of input file `temp.o' is incompatible with aarch64 output aarch64-linux-android/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400078 $ echo $? 1 $ clang -target aarch64-linux-android- -x c /dev/null -c -o temp.o $ aarch64-linux-android/bin/ld -E temp.o aarch64-linux-android/bin/ld: warning: cannot find entry symbol _start; defaulting to 00000000004002e4 $ echo $? 0 This causes conditional checks that invoke $(CC) without the target triple, then $(LD) on the result, to always fail. Suggested-by: Masahiro Yamada Signed-off-by: Nick Desaulniers Reviewed-by: Matthias Kaehlcke --- Changes since v1: * base patch off of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git kbuild branch, per Masahiro. * Use $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) rather than $(CLANG_TRIPLE), per Masahiro. scripts/Kbuild.include | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 064f477dfdca..0f09e4508554 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -228,12 +228,13 @@ cc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo # cc-ldoption # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both) cc-ldoption = $(call try-run-cached,\ - $(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) + $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) # ld-option # Usage: LDFLAGS += $(call ld-option, -X) ld-option = $(call try-run-cached,\ - $(CC) -x c /dev/null -c -o "$$TMPO" ; $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) + $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -x c /dev/null -c -o "$$TMPO"; \ + $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) # ar-option # Usage: KBUILD_ARFLAGS := $(call ar-option,D)