Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp357126pxb; Wed, 14 Apr 2021 17:43:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDi8M5DVz9Av6v0m4QOYWMxZykzhBzlbpWRQ5QTuYxh+srxjT3hWSdZQtosY4TiwqpQyw6 X-Received: by 2002:a17:90a:fa0c:: with SMTP id cm12mr892170pjb.54.1618447386041; Wed, 14 Apr 2021 17:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618447386; cv=none; d=google.com; s=arc-20160816; b=nhUzbW6OEDDv4PnvGzXjmCchcHDpAzX9vv7HATlcxKK3zbrpYhcJasAoR10u1Lim/o r/lWZPMxBR1DQtx2MUXi4H0MGWYNY9OFmu9FmQxXeMFHtPrMr86S4CmydSh4ovg6+/hj 0Xf84+og4MDSh2aurX3av+wPgybIyUjC/1L0/BdBtujKqvLWiP/Rqs7f61JkJVj4dZcu aFFDM26VftUoJjch8qgo3f9hE9Es6BzsSDuea9xG7u5Bkt80p+UcRc8CbXh1jjKbUINr SXQb+uUWltqi9nr5t/+zLXcSbNKsxQpoerx6CNnv/neum94/662oGwZvV5ocvpn835hf ebpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SOwcXcva/ZnIOAakoMoVnIpEnuwRt7WVoDxac1C1eNU=; b=eIH7/nURICDj3vnq7qyNYSkpY47dgE/Tqru9knMafcuG50jKyUsicEcpoECJ+QjT+4 PWbXnD2DXm7PcuO64eTLohNEEM/6YaLgT3/qhB5QJ26p2LlD2xB1DXkvQrID3sqHdI8U X4RGy5hUjlEKLC5JclsmKrzdNQH0GcFLE8LnlypaQbyQVmANmwxts7iUeJdFq0+BWeoE FwR69qFuIl4ETgXi11VGXhOH3m36q7MHcxQ3swjks5c2Et7pkbGTWrWcIEbk/ae9dsDP Dsu/7bm07wXKsw0xjxtF3nEV/dEmMOyKsruaDWVvifjaMoJ6O+hMygPalpSRnHBcdIyR W/IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FY4OSukw; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h12si1226881pjk.54.2021.04.14.17.42.53; Wed, 14 Apr 2021 17:43:06 -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=@kernel.org header.s=k20201202 header.b=FY4OSukw; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353189AbhDNTAR (ORCPT + 99 others); Wed, 14 Apr 2021 15:00:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:55774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231152AbhDNTAQ (ORCPT ); Wed, 14 Apr 2021 15:00:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 47D9B61222; Wed, 14 Apr 2021 18:59:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618426794; bh=LYYO4HZeiyflbXu22XRjrSqjKF1aopb6IFR/toz6BrE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FY4OSukw42A9w7mugJGLbvz/lUKmexZF/yWDTt2BWAbYW83VLNwWl0kylYrgH2skv fzEq1f8xFrKkCmep36ljW9SZr7v/N8bcUw8FBFCmSQLoJO5e5o4Sq+qBwEkdHcTOIs izaI3KuImeeCevmPFysG6ltEyNIZSkaEvmqRUW2WYHXXoyUweNGV5jUz2uNBTbqLQ2 JMoTP/zW++fruQbMxXh2pOH5E2tnZYreKPVfwUDQPQjdoSw0r33bWOgA/RBM293BgP si6IhZObIvHGAMj1LCO3cIXqzWGWmWCvatDVrTlCeIp6yTMT6HY7f153kJ9uwh+ocd P0/+CF6HuvFgw== Date: Wed, 14 Apr 2021 11:59:48 -0700 From: Nathan Chancellor To: ojeda@kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alex Gaynor , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Wedson Almeida Filho , Michal Suchanek , Masahiro Yamada Subject: Re: [PATCH 03/13] Makefile: Generate CLANG_FLAGS even in GCC builds Message-ID: References: <20210414184604.23473-1-ojeda@kernel.org> <20210414184604.23473-4-ojeda@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210414184604.23473-4-ojeda@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Miguel, On Wed, Apr 14, 2021 at 08:45:54PM +0200, ojeda@kernel.org wrote: > From: Miguel Ojeda > > To support Rust under GCC-built kernels, we need to save the flags that > would have been passed if the kernel was being compiled with Clang. > > The reason is that bindgen -- the tool we use to generate Rust bindings > to the C side of the kernel -- relies on libclang to parse C. Ideally: > > - bindgen would support a GCC backend (requested at [1]), > > - or the Clang driver would be perfectly compatible with GCC, > including plugins. Unlikely, of course, but perhaps a big > subset of configs may be possible to guarantee to be kept > compatible nevertheless. > > This is also the reason why GCC builds are very experimental and some > configurations may not work (e.g. GCC_PLUGIN_RANDSTRUCT). However, > we keep GCC builds working (for some example configs) in the CI > to avoid diverging/regressing further, so that we are better prepared > for the future when a solution might become available. > > [1] https://github.com/rust-lang/rust-bindgen/issues/1949 > > Link: https://github.com/Rust-for-Linux/linux/issues/167 > > Co-developed-by: Alex Gaynor > Signed-off-by: Alex Gaynor > Co-developed-by: Geoffrey Thomas > Signed-off-by: Geoffrey Thomas > Co-developed-by: Finn Behrens > Signed-off-by: Finn Behrens > Co-developed-by: Adam Bratschi-Kaye > Signed-off-by: Adam Bratschi-Kaye > Co-developed-by: Wedson Almeida Filho > Signed-off-by: Wedson Almeida Filho > Signed-off-by: Miguel Ojeda > --- > Makefile | 27 ++++++++++++++++----------- > 1 file changed, 16 insertions(+), 11 deletions(-) > > diff --git a/Makefile b/Makefile > index d4784d181123..9c75354324ed 100644 > --- a/Makefile > +++ b/Makefile > @@ -559,26 +559,31 @@ ifdef building_out_of_srctree > { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore > endif > > -# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included. > -# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile. > -# CC_VERSION_TEXT is referenced from Kconfig (so it needs export), > -# and from include/config/auto.conf.cmd to detect the compiler upgrade. > -CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1 | sed 's/\#//g') > +TENTATIVE_CLANG_FLAGS := -Werror=unknown-warning-option > > -ifneq ($(findstring clang,$(CC_VERSION_TEXT)),) > ifneq ($(CROSS_COMPILE),) > -CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) > +TENTATIVE_CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) > GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) Shuffling this around will cause this issue (I never saw you CC'd on the thread). https://lore.kernel.org/r/f6218ac526a04fa4d4406f935bcc4eb4a7df65c4.1617917438.git.msuchanek@suse.de/ Perhaps that patch should be added to this series? > -CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) > +TENTATIVE_CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) > GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..) > endif > ifneq ($(GCC_TOOLCHAIN),) > -CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN) > +TENTATIVE_CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN) > endif > ifneq ($(LLVM_IAS),1) > -CLANG_FLAGS += -no-integrated-as > +TENTATIVE_CLANG_FLAGS += -no-integrated-as > endif > -CLANG_FLAGS += -Werror=unknown-warning-option > + > +export TENTATIVE_CLANG_FLAGS > + > +# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included. > +# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile. > +# CC_VERSION_TEXT is referenced from Kconfig (so it needs export), > +# and from include/config/auto.conf.cmd to detect the compiler upgrade. > +CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1 | sed 's/\#//g') > + > +ifneq ($(findstring clang,$(CC_VERSION_TEXT)),) > +CLANG_FLAGS += $(TENTATIVE_CLANG_FLAGS) > KBUILD_CFLAGS += $(CLANG_FLAGS) > KBUILD_AFLAGS += $(CLANG_FLAGS) > export CLANG_FLAGS > -- > 2.17.1 >