tests/module_load: simplify the clean target
PATCH 1/2 tests/module_load: simplify the clean target
No need to guess all the wildcards to remove the intermediate files from module build - we can just use the kernel module build system to clean them up for us.
--- tests/module_load/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/module_load/Makefile +1 -1
@@ -9,4 +9,4 @@ all: $(TARGETS) clean: rm -f $(TARGETS) - rm -f *.a *.o *.ko *.cmd *.mod *.mod.c .*.cmd Module.symvers modules.order + $(MAKE) -C $(KDIR) M=$(PWD) clean
Signature · 1 line
2.31.1
PATCH 2/2 tests/module_load: use the right compiler to build kernel modules
Kernel modules need to be built with the same compiler as the kernel was built with. Thus, try to explicitly pass the right compiler (detected from kernel config) to Make when compiling the modules, so that the testsuite can be successfully built also on systems with clang-built kernel, but with GCC as the default compiler.
Note that the rest of the testsuite doesn't currently build with clang, so just changing CC for the whole testuite is not enough as a workaround. And even after fixing testsuite to build with clang, it will be beneficial to be able to use a different compiler to build the testsuite than the one needed for the kernel modules - for example to find more bugs by building the test programs with multiple compilers in CI.
--- tests/module_load/Makefile | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
tests/module_load/Makefile +21 -2
@@ -4,9 +4,28 @@ TARGETS = finit_load init_load LDLIBS += -lselinux KDIR = /lib/modules/$(shell uname -r)/build +# Make sure to use the same compiler as the kernel was built with. +# If the compilers don't match, the build will fail on unsupported compiler +# flags and even if not, the resulting module would likely fail to load. +# If the kernel was compiled with neither GCC nor clang (currently the only +# supported compilers), fall back to the default compiler and hope for the best. +# In all cases allow the user to override the compiler via the KCC variable. +DETECTED_KCC = unknown +ifeq ($(shell grep -qFx CONFIG_CC_IS_GCC=y $(KDIR)/.config && echo true),true) + DETECTED_KCC = gcc +endif +ifeq ($(shell grep -qFx CONFIG_CC_IS_CLANG=y $(KDIR)/.config && echo true),true) + DETECTED_KCC = clang +endif +ifneq ($(DETECTED_KCC),unknown) + KCC ?= $(DETECTED_KCC) +else + KCC ?= $(CC) +endif + all: $(TARGETS) - $(MAKE) -C $(KDIR) M=$(PWD) + $(MAKE) -C $(KDIR) CC=$(KCC) M=$(PWD) clean: rm -f $(TARGETS) - $(MAKE) -C $(KDIR) M=$(PWD) clean + $(MAKE) -C $(KDIR) CC=$(KCC) M=$(PWD) clean
Signature · 1 line
2.31.1
Quoted 20 lines · Ondrej Mosnacek
No need to guess all the wildcards to remove the intermediate files from module build - we can just use the kernel module build system to clean them up for us.
Signed-off-by Ondrej Mosnacek <[email protected]>--- tests/module_load/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/module_load/Makefile +1
-2@@ -9,4 +9,4 @@ all: $(TARGETS) clean: rm -f $(TARGETS) - rm -f *.a *.o *.ko *.cmd *.mod *.mod.c .*.cmd Module.symvers modules.order + $(MAKE) -C $(KDIR) M=$(PWD) clean --
Quoted 2 lines
2.31.1
Both patches are now applied.
Signature · 3 lines
Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc.