diff --git a/hello-world/Makefile b/hello-world/Makefile index fccc18c3..21e4fbde 100644 --- a/hello-world/Makefile +++ b/hello-world/Makefile @@ -1,6 +1,11 @@ +ifneq ($(KERNELRELEASE),) obj-m := helloworld.o -helloworld-objs := target/x86_64-linux-kernel-module/debug/libhello_world.a +helloworld-objs := libhello_world.o EXTRA_LDFLAGS += --entry=init_module + +$(M)/libhello_world.o: target/x86_64-linux-kernel-module/debug/libhello_world.a + $(LD) -r -o $@ --whole-archive $^ +else KDIR ?= /lib/modules/$(shell uname -r)/build all: @@ -8,3 +13,4 @@ all: clean: $(MAKE) -C $(KDIR) M=$(CURDIR) clean +endif diff --git a/tests/Makefile b/tests/Makefile index acfd9592..8a2f876b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,6 +1,11 @@ +ifneq ($(KERNELRELEASE),) obj-m := testmodule.o -testmodule-objs := $(TEST_LIBRARY) +testmodule-objs := $(TEST_LIBRARY_OBJECT) EXTRA_LDFLAGS += --entry=init_module + +$(M)/$(TEST_LIBRARY_OBJECT): target/x86_64-linux-kernel-module/debug/$(TEST_LIBRARY_ARCHIVE) + $(LD) -r -o $@ --whole-archive $^ +else KDIR ?= /lib/modules/$(shell uname -r)/build all: @@ -8,3 +13,4 @@ all: clean: $(MAKE) -C $(KDIR) M=$(CURDIR) clean +endif diff --git a/tests/run_tests.py b/tests/run_tests.py index f8fae900..681f6388 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -46,14 +46,13 @@ def main(): path ) ) + library_path, _ = os.path.splitext(os.path.basename(module)) + library_object = library_path + ".o" + library_archive = library_path + ".a" run( "make", "-C", BASE_DIR, - "TEST_LIBRARY={}".format( - os.path.join( - "target/x86_64-linux-kernel-module/debug/", - os.path.basename(module) - ) - ), + "TEST_LIBRARY_OBJECT={}".format(library_object), + "TEST_LIBRARY_ARCHIVE={}".format(library_archive), ) run( "rustc",