Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp356311pxb; Wed, 14 Apr 2021 17:41:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTaZV8wlUOU2alAx3e5GHNvg9ho4Jw64KyFEZSUN3erjePFNfnwEkPwxJVXRcbj+KH6GRq X-Received: by 2002:a05:6402:1d3a:: with SMTP id dh26mr961531edb.359.1618447286279; Wed, 14 Apr 2021 17:41:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618447286; cv=none; d=google.com; s=arc-20160816; b=NgMeHyxnpQ+dxuxAN9rbSpuRh4EqfNiLbUn+DultEyXx0Z3zd4Wxj59NVwDG/dQK7g o0w2WjYhNwr+AAxvVjl8aFtyy1CrrSPfxqCdjgLgkuPSDeIrlT4b2WdQGwnG7qY6P1en H4138id+9NHAoaH2fCN2mGYCX+HDezWwe8WEzJAond7UFnVXT5VC46b1MfsZADmhWgv4 3Of91jlVbnn3YOoYaNvSAtoZktXTp7C6iEzpFfJ3CLiroA9tsGn1JxLSB9piyBvcjxbu 5BS2UrFNS7XAyo3m6TXXCfsbRV0g/siuIkxfCwQgoGs1EMcLdjAnXA4+kEeT3S/eaoIp NsIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=im5K6q9qlFYTRaczDv5oHN9cthw2zVuAjLZ+IaWIYpY=; b=wMFKzHlS2Xm8vkIjNUnBk6+ZXgTFzbZPAcyMGDLaRnPAnarXYV/w6A+zyUAHEdo1A2 dtal2ZMyPH73rJJ8bn14TLrRN6Rhk6ue2pyVLkfcqavIiDYb9DaGe38NTqKM+PvVqqf6 r5836j+YOPdEiwiSBpKTA7amerk+6drIyUHWby/hm8ueWusX1vfC9Gn8/FKX8AoRe9xw elsJF7CC/jFJmQ9zlxyK0TYCIfYLVzMGRIZcIRfvVZD1dwFV0Nf2lno3yD7Kkxa7j98w HUZ/DMWr6kfyZYWf573/bgzqc+ml63v3SMiMsSfYSp9Ts9LA7HTAd/CO9lX1xwhi1HJt x1IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=amBUYURL; 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 bh18si718287ejb.405.2021.04.14.17.41.03; Wed, 14 Apr 2021 17:41:26 -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=amBUYURL; 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 S1353072AbhDNSrJ (ORCPT + 99 others); Wed, 14 Apr 2021 14:47:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:49152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353052AbhDNSq6 (ORCPT ); Wed, 14 Apr 2021 14:46:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9D37961153; Wed, 14 Apr 2021 18:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618425997; bh=J2a8PS8uFRlQIf9jLGd/pmNX4lflqEQpT2s3wHMzz+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=amBUYURLbySxZCz62sQUdb+yDhXgd5hj4LgkTM+8IsqjDoQgzUY9eKL8pbD5KQUbw bQC5yZ2gYNfSOE8Zg4vRq3vK6wqQFhEAfWY+Yl96/ib+y+dj33+ORu/EtTAKg82PDr UvHZcOd0fFgtcGX/onLKk+0ZcOs5UZucOZhToLafiM1PNoWfKOOqdocbwZpAom4TZJ qXDUidPYwuuXRjMndISFrs7EyMYgsYDhlZhkEIjQGRrW//DdzGCM9L6oHT4jRlM3HT DXprJTN1u/nKosoLiuuji74fnrhvwzibN8hM8YRj9BdSkadUvAKu6kKKNFqVscPCYz 7nVQH/+5uo2CQ== From: ojeda@kernel.org To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Wedson Almeida Filho Subject: [PATCH 03/13] Makefile: Generate CLANG_FLAGS even in GCC builds Date: Wed, 14 Apr 2021 20:45:54 +0200 Message-Id: <20210414184604.23473-4-ojeda@kernel.org> In-Reply-To: <20210414184604.23473-1-ojeda@kernel.org> References: <20210414184604.23473-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)) -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