Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp1112593pxb; Fri, 18 Feb 2022 00:36:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7U3qWF2gWeGMuRmSFEcSMwgzxvEgxPDKkkk0LNqs8CJU/ff7jBvOai3MWyuuKWWtCMmvb X-Received: by 2002:a17:90a:5794:b0:1b9:8932:d475 with SMTP id g20-20020a17090a579400b001b98932d475mr7223854pji.24.1645173390594; Fri, 18 Feb 2022 00:36:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645173390; cv=none; d=google.com; s=arc-20160816; b=N5WWAcKx9RHPCAtz/9cdxMN2KCTDi3THaiKKSPzDDC51LUvcE+bnqAv9DUalugazGN hqjB2LU9xDoAwkEVK/33RXqpHoZBrJA8kvr7s04qbkwl9G/psyAKPkmFe+d/9RXLV9c0 Z+b2lo0TkN8278/rnDMdyzd/9Dez2mSho+lUXmdko6Sckr6r1Qb5PoiG0HLToCFoNcOz naywoQf0FemAOSNyVRrUPb82skj6oK11XdVnsVqpbMah9m2AeDdYrGmd5L6I0s+38WI2 jw0y4VKxa5ay9q0fVPoT6QWpu7KsL9LeeFNpIN1dl6DK17VHaYENureXfHFIqo/bubpz zWgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=c2Cbubek2IMOpYs+Y/vvzVJP4fB6kWNFxqZ34EZAc+4=; b=LElePF0K4JPWBn5kjep0PV5UcQuK8hqzpr4tZd2NnnJVt2/YUHslFT5AKpqUjCT3jE 1qbr3dK4EVwSorAblIzs8QmLzBvzlwxVwIcAF2AD9hxfm2iwnxtzDlDtP+w9ceXmRfQ8 FtQy98+HWpBE9Qeo7k8wTghuUcnRpMxz6ojdX13UKFlg66t8AjsnKTMReL/gZKxJXxBU 75xlkrGgFivXiAq6DkbP4ItvZGhTD77J6GKhRNiVw5LUcHjckBXKm+vzdJFr9kHM4TLN SDqO0Q/zIJw3heEWCZ2Q68WZW+gnfPZmFLtCk0aTKQ3Ioo78oooQgFrPXVFBcPhQWFJZ bJZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=U6IzTeuS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4si2744185pjr.24.2022.02.18.00.36.16; Fri, 18 Feb 2022 00:36:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=U6IzTeuS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231365AbiBRH2U (ORCPT + 99 others); Fri, 18 Feb 2022 02:28:20 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230397AbiBRH2T (ORCPT ); Fri, 18 Feb 2022 02:28:19 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 185E5130830 for ; Thu, 17 Feb 2022 23:28:01 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: aratiu) with ESMTPSA id F3BC81F464F4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1645169280; bh=KYLq7eNzr+XRZuirnWBJLVeUqZ6BEc4ttbFcZk8iUGk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=U6IzTeuS1C+9np66UfM0lKpZF0ZKxDj3xYfdA5C4d9HrIROIyV/RyA2jMUd2BNOz3 sGl2U7h0GuVIpNXqneRPSmoSK+E0lHgdD+mi3foUCPxf73o9EVHvFIn1QiUxe8MgPT L8SU7BZy9V5lD9EmjJd9qtP1dTFOskQgGX07ipGgvN3DW9W5F/NOGO8CPlMk+ibsaR NlXwtCJQRxpBtzNatU97rvLq8HfGcKA36bCUc/jxLWpPZJqUPNKXgmrzcR05o3JuJR ujv7dXmfGgx/ly3f+Oh7FZwWA9dZoBv5tAkxQcctMyqjtBwPB/+MZuJsNvk7eliUNV 33O8pUAIYIqaA== From: Adrian Ratiu To: Nathan Chancellor Cc: llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Nick Desaulniers , Manoj Gupta Subject: Re: [PATCH] tools: fix unavoidable GCC call in Clang builds In-Reply-To: References: <20220217033648.1453303-1-adrian.ratiu@collabora.com> Date: Fri, 18 Feb 2022 09:27:57 +0200 Message-ID: <87czjk4osi.fsf@ryzen9.i-did-not-set--mail-host-address--so-tickle-me> MIME-Version: 1.0 Content-Type: text/plain; format=flowed X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 17 Feb 2022, Nathan Chancellor wrote: > Hi Adrian > > On Thu, Feb 17, 2022 at 05:36:48AM +0200, Adrian Ratiu wrote: >> In ChromeOS and Gentoo we catch any unwanted mixed Clang/LLVM >> and GCC/binutils usage via toolchain wrappers which fail >> builds. > > Neat for hermetic builds. > Thanks! We're doing this for the entire build and found quite some bugs in upstream userspace projects as well, like configure/m4 hardcoding things like binutils ar instead of our toolchain configured llvm-ar. >> This has revealed that GCC is called unconditionally in Clang >> configured builds to populate GCC_TOOLCHAIN_DIR. Allow >> overriding the variable to avoid the GCC call - in our case we >> can set GCC_TOOLCHAIN_DIR directly in the ebuild recipe. > > Would you just set GCC_TOOLCHAIN_DIR to nothing to avoid > triggering the 'gcc -print-sysroot' call? Yes, the intention was to set GCC_TOOLCHAIN_DIR="" in the ebuild, but now we have a better approach suggested by you below :) What we do right now is add an exception for the entire kernel, to allow it to make mixed toolchain calls (wrappers don't fail the build). AFAICT this is the last bug before we can start enforcing "pure" LLVM builds, at least on more recent kernels. Older kernels have been known to work as well (eg 5.4) after fixing some bugs which were not strictly in the kernel codebase, like: https://archives.gentoo.org/gentoo-dev/message/a4aefebf8969b2ddbbf7298c67659996 > > An alternative might be allowing CLANG_CROSS_FLAGS to be > supplied by the user, so that you can stil benefit from cross > compiling tools, but with the flags and sysroot that you expect. > That seems like a better approach, thanks. It makes sense to allow distributions to specify locations of their userspace libraries since the kernel has no control over how various distros are configured. According to the original commit message adding this change, in some cases Clang might be able to autodetect these paths, but autodetection does not work for all possible configurations. If a reliable generic Clang autodetection mechanism is possible, then setting these vars/flags becomes a no-op and can be dropped, until then CLANG_CROSS_FLAGS solves our problem. >> Suggested-by: Manoj Gupta >> Signed-off-by: Adrian Ratiu > > Regardless, as long as it works for your use case: > > Acked-by: Nathan Chancellor > > The change that this patch fixes [1] went via bpf-next [2] last > cycle, you could either target that tree to have it fixed for > 5.18 or make a case for having it merged in the 5.17 cycle via > bpf [3]. I would resend this change to the kernel/bpf > maintainers, as Nick and I do not currently pick up patches. If Nick is also ok with the CLANG_CROSS_FLAGS approach, I'll send that to bpf-next. Thanks again! > > [1]: https://lore.kernel.org/r/20211216163842.829836-2-jean-philippe@linaro.org/ > [2]: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/ > [3]: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/ > >> --- >> tools/scripts/Makefile.include | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include >> index 79d102304470..98c098c064dd 100644 >> --- a/tools/scripts/Makefile.include >> +++ b/tools/scripts/Makefile.include >> @@ -90,7 +90,7 @@ EXTRA_WARNINGS += -Wstrict-aliasing=3 >> >> else ifneq ($(CROSS_COMPILE),) >> CLANG_CROSS_FLAGS := --target=$(notdir $(CROSS_COMPILE:%-=%)) >> -GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)gcc 2>/dev/null)) >> +GCC_TOOLCHAIN_DIR ?= $(dir $(shell which $(CROSS_COMPILE)gcc 2>/dev/null)) >> ifneq ($(GCC_TOOLCHAIN_DIR),) >> CLANG_CROSS_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) >> CLANG_CROSS_FLAGS += --sysroot=$(shell $(CROSS_COMPILE)gcc -print-sysroot) >> -- >> 2.35.0 >>