Skip to content

Commit 50aea48

Browse files
ojedaRichardhongyu
authored andcommitted
Makefile: generate CLANG_FLAGS even in GCC builds
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] rust-lang/rust-bindgen#1949 Link: Rust-for-Linux/linux#167 Co-developed-by: Alex Gaynor <[email protected]> Signed-off-by: Alex Gaynor <[email protected]> Co-developed-by: Geoffrey Thomas <[email protected]> Signed-off-by: Geoffrey Thomas <[email protected]> Co-developed-by: Finn Behrens <[email protected]> Signed-off-by: Finn Behrens <[email protected]> Co-developed-by: Adam Bratschi-Kaye <[email protected]> Signed-off-by: Adam Bratschi-Kaye <[email protected]> Co-developed-by: Wedson Almeida Filho <[email protected]> Signed-off-by: Wedson Almeida Filho <[email protected]> Signed-off-by: Miguel Ojeda <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]>
1 parent 4c8d480 commit 50aea48

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Makefile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,18 +583,23 @@ endif
583583
# and from include/config/auto.conf.cmd to detect the compiler upgrade.
584584
CC_VERSION_TEXT = $(subst $(pound),,$(shell $(CC) --version 2>/dev/null | head -n 1))
585585

586-
ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
586+
TENTATIVE_CLANG_FLAGS := -Werror=unknown-warning-option
587+
587588
ifneq ($(CROSS_COMPILE),)
588-
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
589+
TENTATIVE_CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
589590
endif
590591
ifeq ($(LLVM_IAS),1)
591-
CLANG_FLAGS += -integrated-as
592+
TENTATIVE_CLANG_FLAGS += -integrated-as
592593
else
593-
CLANG_FLAGS += -no-integrated-as
594+
TENTATIVE_CLANG_FLAGS += -no-integrated-as
594595
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
595-
CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
596+
TENTATIVE_CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
596597
endif
597-
CLANG_FLAGS += -Werror=unknown-warning-option
598+
599+
export TENTATIVE_CLANG_FLAGS
600+
601+
ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
602+
CLANG_FLAGS += $(TENTATIVE_CLANG_FLAGS)
598603
KBUILD_CFLAGS += $(CLANG_FLAGS)
599604
KBUILD_AFLAGS += $(CLANG_FLAGS)
600605
export CLANG_FLAGS

0 commit comments

Comments
 (0)