Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp96608ybh; Mon, 20 Jul 2020 11:13:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrWIKCV365hMOEq3v+TYfzj97QOE4VIWdng+STIZ3av2xMt/m4hOk9uPEaQTiyJ2GgYznk X-Received: by 2002:aa7:da56:: with SMTP id w22mr23415053eds.124.1595268802036; Mon, 20 Jul 2020 11:13:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595268802; cv=none; d=google.com; s=arc-20160816; b=XEfbmVkP6PUmo1AtUVB8ZwflTxn3vU4bCLNV8RQcRynB9+5SI1Nc3S7pQYfcBHBnR8 ZopoOmDOV3Aig4BFP/1RxlPpilPBPMiQgi8kDhd9KarrJ0gMSC+UUhKiEc84ubBojUKq g4jtZ0w0Vfvi5W0WMOBul7vFa6tMnJ1vwjwDw1LBCmzs/PjlGqyfQfZDsz3buRV5yVB+ X8xlp19W7MmvWRHbZU+E71vQPQu/UhFlFA773NF+n+KAN4hooX9VERVpIKQZI1R12EFP fdTdpVm0til9VgW7Zpz0FptntE0Ni8G25iZV4oaEV2KDlkmGjIJGKElJoyM3tPbTZZ53 Osvw== 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=foQP01o+jLLxWyYMddt7wMxz9LiizEHjChmq39E8dvQ=; b=IgeXZ1ilfp0ApDss0qoJKnbajARfH5bAagIlQMU3lg7mEiA6+0FpEY3WdslOQL58EQ 4hmuedxDFHWV2nRKfJyysMYtbl1WDyEnnLvyEtC7OyjXrFpIj4dRE4FpCmxYMoNmfAi/ 7dQLKQHrwrkybWvUr0ueXEqpeImkiu3bmn19YPfXhdNV9atjC6xKD6idHmK6q7ilRsG8 eBkhixHqjzzJB4BhpQAxO+6UpJ+tXEuNdxiX9W/VMpQx5evZAFuFUQjtcr8oj01woi8t ZKrf5mxfxyz58cm4EkgKcg7X9/mtLwRQH0mI1KgeVOydaBtt9QkiEVCBKISix+szQGEb jSvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ks6dk1mR; 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 a9si10772985edt.401.2020.07.20.11.12.52; Mon, 20 Jul 2020 11:13:22 -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=ks6dk1mR; 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 S1729385AbgGTSMr (ORCPT + 99 others); Mon, 20 Jul 2020 14:12:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726030AbgGTSMq (ORCPT ); Mon, 20 Jul 2020 14:12:46 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FB56C061794 for ; Mon, 20 Jul 2020 11:12:46 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 124so22894839ybb.5 for ; Mon, 20 Jul 2020 11:12:46 -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=foQP01o+jLLxWyYMddt7wMxz9LiizEHjChmq39E8dvQ=; b=ks6dk1mRoPvv5K/RguqHzZXRvpQzZ8Sma0KZPaH2f9dcYupIWG8cBMxwDl+AR4xhaV CH1dhBt+6QvtqFvJImE7/TQy6QanJ3RuMki6d2XjchxX6NLmodxKd/KU4im88YsqeISB 0PdFNGrai/DE1DxfYYhfhT+51rxO3HwD7yttKR78i/mA3LXJAncVIiTIkjq0TKeK7F2b sHfctGLF7Zvzut+ZSeq6cb4vKRBUUEW2YtnYgEgH5jCsx4+dhdKZHZk4cn03GDcAWKAt Wmc6voUlwuxFz/qni4DIekfBhxrgjZWS+g8WjfJWc6pKMq891yKv8oGa2AbFZd79eTpv o/EQ== 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=foQP01o+jLLxWyYMddt7wMxz9LiizEHjChmq39E8dvQ=; b=lvyDltCuvsrtQgMHeNsTR6p72z2ZxLNI9Jatr6bWejo19D6nAdDegQQRpM7BUwqEM+ gcnsSUWCEXaDpouPEcCvOL7LPRSCOOFqeepOaCaFc2UYLlWO0VYGCIc5VuAracW81QII XM12q7MiQHv3oYanxQD1U3H1Jk2jFAh4DzWLoSayQCTG3sWm8xwVC6p2qfuWtlzKAk7T U9P3XWh3/0p9tSTkqAaUhDHVIhjZsYgy2FlWWAzYZg71am1mOHHtlCLxbgEXcbIcPacB kVfG/Zm1lkLhPG44RRvG/UWdjFt2kxLuPS6kx8xlWfvyXACD4EGIySBjNoP+z+uf3PNY 3nmw== X-Gm-Message-State: AOAM531ufQbnMV+zonYA1m8BYrGcakzv/AtKTbbA6zMOpaH7XbyDCuqz YTJn9Rk/byS9BJUD6pngv3ZV/T+7TjaO X-Received: by 2002:a25:fc04:: with SMTP id v4mr37291336ybd.164.1595268765617; Mon, 20 Jul 2020 11:12:45 -0700 (PDT) Date: Mon, 20 Jul 2020 11:12:22 -0700 Message-Id: <20200720181237.3015826-1-maskray@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH] 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: Fangrui Song , Nathan Chancellor 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-, 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 only searches for $(prefix)$needle and for example 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). Signed-off-by: Nathan Chancellor Signed-off-by: Fangrui Song Link: https://github.com/ClangBuiltLinux/linux/issues/1099 --- 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