From patchwork Mon Nov 6 18:47:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 10044247 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 93E956032D for ; Mon, 6 Nov 2017 18:48:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8320A29F68 for ; Mon, 6 Nov 2017 18:48:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 755CE29F82; Mon, 6 Nov 2017 18:48:23 +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 2358F29F68 for ; Mon, 6 Nov 2017 18:48:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932939AbdKFSsP (ORCPT ); Mon, 6 Nov 2017 13:48:15 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:46304 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932374AbdKFSsO (ORCPT ); Mon, 6 Nov 2017 13:48:14 -0500 Received: by mail-pf0-f194.google.com with SMTP id p87so8383386pfj.3 for ; Mon, 06 Nov 2017 10:48:14 -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=3aCLHa5FGOB5v5h4ELmChwuzB79J0OI+EXnK3XYb/80=; b=FPoqn6ZgTnA4J6RIfDynL+vGCJPcNEByu+Y1yaf9m3Kbt52G3jJGwHdrzUDcspt/S0 wgl5JokcXJairFT1S/uiOMz4iPOz3BKVH2RFOls3L63yOtgYo9qix0Wul4jRwqOvjUYw lTl+9g3isYmWzpkhHNbMF01DtK6y0cWpXlZqaYIK6edqsDw85S9Y6MLfIGF2ssxwp/N0 SIwW1KvFlq8HWZ7hPH7dvjzj2VQ5DBj8yhgklkFL2pmGe6bNtREqfAV8ylfxf023YLF8 6+X46MTfAxaSEo73s/z/2iR53dXoBT27dVvjq4F0RkOEuaWHwhfw03mIknugqdDawQgL Cltw== 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=3aCLHa5FGOB5v5h4ELmChwuzB79J0OI+EXnK3XYb/80=; b=OvOqLNx6Zd62GrgYIvhf8lbpSIG0LavR9wmNuBuwTuq7diTvtz3b3zlx1YA1Hhovzu 446gbUkR1KVdZIGOjpHcpmXoMKBKpIVql1Fh8SlRcOu/TNouj4Fr+POIfz5SvAa9a4/A /n/W+q61qJKnVv1W+e8qJ1hyf/JtTLJ6pZj2kBEOZcxsd060TliTC95zyCnLi8yeagUZ 3vhWSEjz4LteHX7TrA36tFNLR3iJuZyMQuOop7egrjY8aCexQlyhX2IFBrTeQuMYEXy5 0hmSiQdtD2v5yafLEw4KrY6bodsO8yuSer4NitqpYEVuzYEmdGBPt7tfcL0FIMKpICzF TRYg== X-Gm-Message-State: AMCzsaWVtLC417kBT5tbFEJOhbGq/z0hJjwizo2D5B3FJcIy8770SNXG 9Y5aYej9FZMVfTK0UvqsFdCAEGJoQJA= X-Google-Smtp-Source: ABhQp+Sffeuz1QzJFcUuk494om5XvPI38KgItOJKX/uif64HdYF7acrit8IwphtGg/TItBO6KVG4vA== X-Received: by 10.159.214.152 with SMTP id n24mr15757910plp.48.1509994092979; Mon, 06 Nov 2017 10:48:12 -0800 (PST) Received: from ndesaulniers0.mtv.corp.google.com ([100.123.74.54]) by smtp.gmail.com with ESMTPSA id f15sm20338745pgv.45.2017.11.06.10.48.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Nov 2017 10:48:11 -0800 (PST) From: Nick Desaulniers To: linux-kbuild@vger.kernel.org, Masahiro Yamada Cc: md@google.com, ghackmann@google.com, pirama@google.com, Nick Desaulniers , Matthias Kaehlcke , Arnd Bergmann , Ingo Molnar , Douglas Anderson , Cao jin , Josh Poimboeuf , Mark Charlebois , linux-kernel@vger.kernel.org Subject: [PATCH v3] kbuild: fix linker feature test macros when cross compiling with Clang Date: Mon, 6 Nov 2017 10:47:54 -0800 Message-Id: <20171106184756.24404-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.15.0.403.gc27cc4dac6-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 v2: * Add LDFLAGS to ld-option, as per Masahiro, and spotted by 0-day bot: https://lists.01.org/pipermail/lkp/2017-October/007427.html scripts/Kbuild.include | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 064f477dfdca..be1c9d65eaf4 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) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) # ar-option # Usage: KBUILD_ARFLAGS := $(call ar-option,D)