From c7fcf0091731e904aa26c1375348107b5ada984b Mon Sep 17 00:00:00 2001 From: Peter Levine Date: Wed, 2 Feb 2022 00:44:59 -0500 Subject: [PATCH] Add support for $KERNEL_{CC,LD,LLVM} variables Currently, $(CC), $(LD), and $(LLVM) variables aren't passed to kbuild while building modules. This causes modules to build with the default GNU GCC toolchain and prevents experimenting with other toolchains such as CLANG/LLVM. It can also lead to build failure if the CFLAGS/LDFLAGS passed are incompatible with gcc/ld. Pass $KERNEL_CC, $KERNEL_LD, and $KERNEL_LLVM as $(CC), $(LD), and $(LLVM), respectively, to kbuild for each that is defined in the environment. This should take care of the majority of alternative toolchain use cases. Reviewed-by: Damian Szuberski Reviewed-by: Brian Behlendorf Signed-off-by: Peter Levine Closes #13046 --- config/kernel.m4 | 8 +++++++- module/Makefile.in | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config/kernel.m4 b/config/kernel.m4 index 1adec975c0..b918f04534 100644 --- a/config/kernel.m4 +++ b/config/kernel.m4 @@ -601,9 +601,15 @@ dnl # dnl # Used internally by ZFS_LINUX_TEST_{COMPILE,MODPOST} dnl # AC_DEFUN([ZFS_LINUX_COMPILE], [ + AC_ARG_VAR([KERNEL_CC], [C compiler for + building kernel modules]) + AC_ARG_VAR([KERNEL_LD], [Linker for + building kernel modules]) + AC_ARG_VAR([KERNEL_LLVM], [Binary option to + build kernel modules with LLVM/CLANG toolchain]) AC_TRY_COMMAND([ KBUILD_MODPOST_NOFINAL="$5" KBUILD_MODPOST_WARN="$6" - make modules -k -j$TEST_JOBS -C $LINUX_OBJ $ARCH_UM + make modules -k -j$TEST_JOBS ${KERNEL_CC:+CC=$KERNEL_CC} ${KERNEL_LD:+LD=$KERNEL_LD} ${KERNEL_LLVM:+LLVM=$KERNEL_LLVM} -C $LINUX_OBJ $ARCH_UM M=$PWD/$1 >$1/build.log 2>&1]) AS_IF([AC_TRY_COMMAND([$2])], [$3], [$4]) ]) diff --git a/module/Makefile.in b/module/Makefile.in index 9cd075e685..b6338430e8 100644 --- a/module/Makefile.in +++ b/module/Makefile.in @@ -52,7 +52,9 @@ FMAKE = env -u MAKEFLAGS make $(FMAKEFLAGS) modules-Linux: list='$(SUBDIR_TARGETS)'; for td in $$list; do $(MAKE) -C $$td; done - $(MAKE) -C @LINUX_OBJ@ M="$$PWD" @KERNEL_MAKE@ CONFIG_ZFS=m modules + $(MAKE) -C @LINUX_OBJ@ $(if @KERNEL_CC@,CC=@KERNEL_CC@) \ + $(if @KERNEL_LD@,LD=@KERNEL_LD@) $(if @KERNEL_LLVM@,LLVM=@KERNEL_LLVM@) \ + M="$$PWD" @KERNEL_MAKE@ CONFIG_ZFS=m modules modules-FreeBSD: +$(FMAKE)