Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp419700ybh; Mon, 20 Jul 2020 21:21:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaj6eg9/c90kzkqEjZMth3DSf7XSjFwJ9DiZimeLzNQBSrgwBeE6wXYPguodp2KFiywt4J X-Received: by 2002:a05:6402:354:: with SMTP id r20mr25486659edw.32.1595305287105; Mon, 20 Jul 2020 21:21:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595305287; cv=none; d=google.com; s=arc-20160816; b=r+QEIfbIL/Rfi05NGhIL3btrox7zIlC+1JZKYqceQyATAnPHXO4V9STB4CRpugdbkg kLTUHSSmio2m3l94DCAeOOTfhxJI1GwbZKTApLMgsJyou9oF+d+6xBEsL85MrP4qu/Iq ocn29O9CtaO+QVLTGVE8Aa8wIpkfsaM2U3bCSUDlpycQEyTY2qsMI654bhfMZvK76hSl cGxMaaD3YeIzwyDmkh4/d1LO7lZYfr/BDdz1mFumH5JdkhSWykv9uVtFXVNJjwjqK9h6 izJ8LJyK2553gPfX6sFO1a3Wp2uj0Z/AU3KR3Kq/nVjxYjZlJwBKFW7C4Lodzb8nSYHc hFWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=BihrwH3YWr7bTCjry1NXThJajsBWv/A/wcqD0l396O4=; b=LkKuZCRnr6FE3GkvzCmvk2/mlaqkfBP2lbpfzBUcKTkA/JviabrfGyiwu8rfdNOfpk Kj7UvOGg6KxA2mG+IcYU1qJexvNbwklHWpOonTbEROL+k0zGBI+TYMlB9LVTFMTHUDgi eaAbSXT5AEJQmijgZEm/247jYzZG60+EvYmtKsiA7X6Kf3ADvGDpHPooNGtFyB3TGACl OE4gyBw41w6lthkvQwlrxtFEOKXVsizq3dNjdys/ozWeiwm9/su2xYwuGbtxlGXK1vNq ll6OPLsw5kdfNF95OQEAbHpc+11wdlcj3YfaYe97oZNEX+a5cwtPt62md9fuMlW6xdMh IHkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Gkxs/4L9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f25si11272819edy.565.2020.07.20.21.21.04; Mon, 20 Jul 2020 21:21:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Gkxs/4L9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725764AbgGUEUG (ORCPT + 99 others); Tue, 21 Jul 2020 00:20:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbgGUEUF (ORCPT ); Tue, 21 Jul 2020 00:20:05 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39BA8C0619D6 for ; Mon, 20 Jul 2020 21:20:05 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id v10so11573518qvm.17 for ; Mon, 20 Jul 2020 21:20:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=BihrwH3YWr7bTCjry1NXThJajsBWv/A/wcqD0l396O4=; b=Gkxs/4L9w2KYJeqo1YzrritKtKVPQXS0nv3cFc1jhGooz2i2RqPdhiqYoQnp1qX6Fy v0erMgNID5uKlh2JzkyqRUT3P2dNJPgGSUmyE/T5ReFLtmy2MGmujoy8D+zW9wi/mNkp rOVTsvULqQVx9jc4HxHbW8MaJS/1Tgjjza0iSFEIf3TswCxVOm4j8tuNunvWr+cxf1Ts hZYjAoCTG/p/3fEt/AbyH4JtklfW7Es9V6gVD8dewOgW2vhglnCtms5VhrnhEVBBrkbx HsHa51amlowN1sfv6HI5H1SbmFc//YgFuisS3nLFiSmSjpetTSEK0L5bn028gUR8C5rs T+uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=BihrwH3YWr7bTCjry1NXThJajsBWv/A/wcqD0l396O4=; b=XUiA6Nn9UF/7K4mSlSxYej3Vs/8Z3hODz0Y/ZpLFsKoLDb5x+1SsjkgmK4bMRLhNfB t0+eeVH4ycaeQBRfpB/zxZaKLgh6Y+AAG3Jb1O2Qb2o7zv7MlzJCbOS67Be8MkMKrhNN 1x83+54nae4o5yz9QwKNnaYnh6q25vYAvtKHg5IuEU14Pj8VOwsRHCEJ9OLxbO9NMEH2 WMsbVMdUFkZuPcyArTeSq7pzYs/g53Xly5CCRFVO7UhmdNHUBlKqjEbBjKFfAw1YVbZ3 3gI8brtfjtpevp7+5+iJIGUr6noYW5M9umT22GA7CYUdfMvQCJWdxrD2vTnFYu7Uc+jc dang== X-Gm-Message-State: AOAM531ZtPOcyknUH315vnvHxK8k7o2UfnmK/8XDaBMzHHhbWqriYRW6 Gb3KlP8f2pR3+M/XdcxdXkYoqxeIiwD3 X-Received: by 2002:a05:6214:927:: with SMTP id dk7mr24912062qvb.26.1595305204150; Mon, 20 Jul 2020 21:20:04 -0700 (PDT) Date: Mon, 20 Jul 2020 21:19:38 -0700 Message-Id: <20200721041940.4029552-1-maskray@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH v2] Makefile: Fix GCC_TOOLCHAIN_DIR prefix for Clang cross compilation From: Fangrui Song To: Masahiro Yamada , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Cc: stable@vger.kernel.org, Jian Cai , Bill Wendling , Manoj Gupta , Fangrui Song , Nathan Chancellor , Nick Desaulniers Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When CROSS_COMPILE is set (e.g. aarch64-linux-gnu-), if $(CROSS_COMPILE)elfedit is found at /usr/bin/aarch64-linux-gnu-elfedit, GCC_TOOLCHAIN_DIR will be set to /usr/bin/. --prefix= will be set to /usr/bin/ and Clang as of 11 will search for both $(prefix)aarch64-linux-gnu-$needle and $(prefix)$needle. GCC searchs for $(prefix)aarch64-linux-gnu/$version/$needle, $(prefix)aarch64-linux-gnu/$needle and $(prefix)$needle. In practice, $(prefix)aarch64-linux-gnu/$needle rarely contains executables. To better model how GCC's -B/--prefix takes in effect in practice, newer Clang (since https://github.com/llvm/llvm-project/commit/3452a0d8c17f7166f479706b293caf6ac76ffd90) only searches for $(prefix)$needle. Currently it will find /usr/bin/as instead of /usr/bin/aarch64-linux-gnu-as. Set --prefix= to $(GCC_TOOLCHAIN_DIR)$(CROSS_COMPILE) (/usr/bin/aarch64-linux-gnu-) so that newer Clang can find the appropriate cross compiling GNU as (when -no-integrated-as is in effect). Reported-by: Nathan Chancellor Signed-off-by: Fangrui Song Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor Tested-by: Nick Desaulniers Link: https://github.com/ClangBuiltLinux/linux/issues/1099 --- Changes in v2: * Updated description to add tags and the llvm-project commit link. * Fixed a typo. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0b5f8538bde5..3ac83e375b61 100644 --- a/Makefile +++ b/Makefile @@ -567,7 +567,7 @@ ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),) ifneq ($(CROSS_COMPILE),) CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) -CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR) +CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(CROSS_COMPILE) GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..) endif ifneq ($(GCC_TOOLCHAIN),) -- 2.28.0.rc0.105.gf9edc3c819-goog