From 12e63277f414aa0fbe2dfa662d5dd4ff85d6ff68 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 15:54:32 -0800 Subject: [PATCH 1/4] Link libhello_world.a into an object file before linking it into the module (required by newer kernel build systems, it seems) --- hello-world/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hello-world/Makefile b/hello-world/Makefile index fccc18c3..88247ba7 100644 --- a/hello-world/Makefile +++ b/hello-world/Makefile @@ -1,6 +1,9 @@ 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 $^ KDIR ?= /lib/modules/$(shell uname -r)/build all: From 5626b364b2f8678e7a555ae3db209a369ba17852 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 16:00:41 -0800 Subject: [PATCH 2/4] Updated hello-world makefile to check if inside the kernel build system or not --- hello-world/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hello-world/Makefile b/hello-world/Makefile index 88247ba7..21e4fbde 100644 --- a/hello-world/Makefile +++ b/hello-world/Makefile @@ -1,9 +1,11 @@ +ifneq ($(KERNELRELEASE),) obj-m := helloworld.o 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: @@ -11,3 +13,4 @@ all: clean: $(MAKE) -C $(KDIR) M=$(CURDIR) clean +endif From 55e4015ad91bed32753c3a33bf4ac295876da349 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Wed, 27 Mar 2019 12:52:55 -0400 Subject: [PATCH 3/4] Attempt to fix tests --- tests/Makefile | 6 ++++++ tests/run_tests.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/tests/Makefile b/tests/Makefile index acfd9592..e85a9c40 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,6 +1,11 @@ +ifneq ($(KERNELRELEASE),) obj-m := testmodule.o testmodule-objs := $(TEST_LIBRARY) EXTRA_LDFLAGS += --entry=init_module + +$(M)/$(TEST_LIBRARY): $(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..b49ec25f 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -46,6 +46,8 @@ def main(): path ) ) + library_archive, _ = os.path.splitext(os.path.basename(module)) + library_archive = library_archive + ".a" run( "make", "-C", BASE_DIR, "TEST_LIBRARY={}".format( @@ -54,6 +56,7 @@ def main(): os.path.basename(module) ) ), + "TEST_LIBRARY_ARCHIVE={}".format(library_archive), ) run( "rustc", From 58380b7693c80a3630c79bcde4cb69de5a6479ce Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Wed, 27 Mar 2019 16:04:52 -0400 Subject: [PATCH 4/4] Fixed tests Makefile. Removed no_copy. Fixed run_test script --- tests/Makefile | 4 ++-- tests/run_tests.py | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index e85a9c40..8a2f876b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,9 +1,9 @@ ifneq ($(KERNELRELEASE),) obj-m := testmodule.o -testmodule-objs := $(TEST_LIBRARY) +testmodule-objs := $(TEST_LIBRARY_OBJECT) EXTRA_LDFLAGS += --entry=init_module -$(M)/$(TEST_LIBRARY): $(TEST_LIBRARY_ARCHIVE) +$(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 diff --git a/tests/run_tests.py b/tests/run_tests.py index b49ec25f..681f6388 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -46,16 +46,12 @@ def main(): path ) ) - library_archive, _ = os.path.splitext(os.path.basename(module)) - library_archive = library_archive + ".a" + 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(