Skip to content

Commit 099548f

Browse files
ojedaintel-lab-lkp
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#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]>
1 parent 34dd656 commit 099548f

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Makefile

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -559,26 +559,31 @@ ifdef building_out_of_srctree
559559
{ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
560560
endif
561561

562-
# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
563-
# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
564-
# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
565-
# and from include/config/auto.conf.cmd to detect the compiler upgrade.
566-
CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1 | sed 's/\#//g')
562+
TENTATIVE_CLANG_FLAGS := -Werror=unknown-warning-option
567563

568-
ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
569564
ifneq ($(CROSS_COMPILE),)
570-
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
565+
TENTATIVE_CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
571566
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
572-
CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
567+
TENTATIVE_CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
573568
GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
574569
endif
575570
ifneq ($(GCC_TOOLCHAIN),)
576-
CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
571+
TENTATIVE_CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
577572
endif
578573
ifneq ($(LLVM_IAS),1)
579-
CLANG_FLAGS += -no-integrated-as
574+
TENTATIVE_CLANG_FLAGS += -no-integrated-as
580575
endif
581-
CLANG_FLAGS += -Werror=unknown-warning-option
576+
577+
export TENTATIVE_CLANG_FLAGS
578+
579+
# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
580+
# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
581+
# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
582+
# and from include/config/auto.conf.cmd to detect the compiler upgrade.
583+
CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1 | sed 's/\#//g')
584+
585+
ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
586+
CLANG_FLAGS += $(TENTATIVE_CLANG_FLAGS)
582587
KBUILD_CFLAGS += $(CLANG_FLAGS)
583588
KBUILD_AFLAGS += $(CLANG_FLAGS)
584589
export CLANG_FLAGS

0 commit comments

Comments
 (0)