All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH testsuite 1/2] tests/module_load: simplify the clean target
@ 2021-09-06 10:54 Ondrej Mosnacek
  2021-09-06 10:54 ` [PATCH testsuite 2/2] tests/module_load: use the right compiler to build kernel modules Ondrej Mosnacek
  2021-09-11 18:34 ` [PATCH testsuite 1/2] tests/module_load: simplify the clean target Ondrej Mosnacek
  0 siblings, 2 replies; 3+ messages in thread
From: Ondrej Mosnacek @ 2021-09-06 10:54 UTC (permalink / raw)
  To: selinux

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 <omosnace@redhat.com>
---
 tests/module_load/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/module_load/Makefile b/tests/module_load/Makefile
index b6eba25..ce34241 100644
--- a/tests/module_load/Makefile
+++ b/tests/module_load/Makefile
@@ -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
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH testsuite 2/2] tests/module_load: use the right compiler to build kernel modules
  2021-09-06 10:54 [PATCH testsuite 1/2] tests/module_load: simplify the clean target Ondrej Mosnacek
@ 2021-09-06 10:54 ` Ondrej Mosnacek
  2021-09-11 18:34 ` [PATCH testsuite 1/2] tests/module_load: simplify the clean target Ondrej Mosnacek
  1 sibling, 0 replies; 3+ messages in thread
From: Ondrej Mosnacek @ 2021-09-06 10:54 UTC (permalink / raw)
  To: selinux

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.

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
---
 tests/module_load/Makefile | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/tests/module_load/Makefile b/tests/module_load/Makefile
index ce34241..272872d 100644
--- a/tests/module_load/Makefile
+++ b/tests/module_load/Makefile
@@ -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
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH testsuite 1/2] tests/module_load: simplify the clean target
  2021-09-06 10:54 [PATCH testsuite 1/2] tests/module_load: simplify the clean target Ondrej Mosnacek
  2021-09-06 10:54 ` [PATCH testsuite 2/2] tests/module_load: use the right compiler to build kernel modules Ondrej Mosnacek
@ 2021-09-11 18:34 ` Ondrej Mosnacek
  1 sibling, 0 replies; 3+ messages in thread
From: Ondrej Mosnacek @ 2021-09-11 18:34 UTC (permalink / raw)
  To: SElinux list

On Mon, Sep 6, 2021 at 12:54 PM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> 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 <omosnace@redhat.com>
> ---
>  tests/module_load/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/module_load/Makefile b/tests/module_load/Makefile
> index b6eba25..ce34241 100644
> --- a/tests/module_load/Makefile
> +++ b/tests/module_load/Makefile
> @@ -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
> --
> 2.31.1
>

Both patches are now applied.

-- 
Ondrej Mosnacek
Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-11 18:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06 10:54 [PATCH testsuite 1/2] tests/module_load: simplify the clean target Ondrej Mosnacek
2021-09-06 10:54 ` [PATCH testsuite 2/2] tests/module_load: use the right compiler to build kernel modules Ondrej Mosnacek
2021-09-11 18:34 ` [PATCH testsuite 1/2] tests/module_load: simplify the clean target Ondrej Mosnacek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.