问题
I'm trying to cross-compile the LiME Kernel Module for the android-goldfish-3.10-n-dev ( commit: 3a3b199582a68ba0688a099147738d6c99f3282d ) Linux Kernel version with the following Makefile:
obj-m := lime.o
lime-objs := tcp.o disk.o main.o
KDIR_GOLD := /path/to/goldfish
PWD := $(shell pwd)
CCPATH :=/path/to/x86_64-linux-android-4.9/bin
default:
# cross-compile for Android emulator
$(MAKE) ARCH=x86_64 CROSS_COMPILE=$(CCPATH)/x86_64-linux-android- -C $(KDIR_GOLD) M="$(PWD)" modules
$(CCPATH)/x86_64-linux-android-strip --strip-unneeded lime.ko
mv lime.ko lime-goldfish.ko
$(MAKE) tidy
tidy:
rm -f *.o *.mod.c Module.symvers Module.markers modules.order \.*.o.cmd \.*.ko.cmd \.*.o.d
rm -rf \.tmp_versions
clean:
$(MAKE) tidy
rm -f *.ko
But I'm getting the following errors/warnings and the compilation fails.
make ARCH=x86_64 CROSS_COMPILE=/path/to/x86_64-linux-android-4.9/bin/x86_64-linux-android- -C /path/to/goldfish M="/path/to/LiME/src" modules
make[1]: Entering directory '/path/to/goldfish'
CC [M] /path/to/LiME/src/tcp.o
CC [M] /path/to/LiME/src/disk.o
CC [M] /path/to/LiME/src/main.o
LD [M] /path/to/LiME/src/lime.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "param_ops_int" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "param_ops_charp" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "param_ops_long" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "ldigest_final" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "ns_to_timeval" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "kfree" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "ktime_get_real" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "iomem_resource" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "ldigest_init" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "sscanf" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "strcmp" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "kmem_cache_alloc_trace" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "kmalloc_caches" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "ldigest_update" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "vfs_write" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "filp_close" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "filp_open" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "kernel_sendmsg" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "sock_setsockopt" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "kernel_stack" [/path/to/LiME/src/lime.ko] undefined!
WARNING: "sock_create_kern" [/path/to/LiME/src/lime.ko] undefined!
CC /path/to/LiME/src/lime.mod.o
/path/to/LiME/src/lime.mod.c:8:1: error: variable '__this_module' has initializer but incomplete type
__attribute__((section(".gnu.linkonce.this_module"))) = {
^
/path/to/LiME/src/lime.mod.c:9:2: error: unknown field 'name' specified in initializer
.name = KBUILD_MODNAME,
^
/path/to/LiME/src/lime.mod.c:9:2: warning: excess elements in struct initializer
/path/to/LiME/src/lime.mod.c:9:2: warning: (near initialization for '__this_module')
/path/to/LiME/src/lime.mod.c:10:2: error: unknown field 'init' specified in initializer
.init = init_module,
^
/path/to/LiME/src/lime.mod.c:10:2: warning: excess elements in struct initializer
/path/to/LiME/src/lime.mod.c:10:2: warning: (near initialization for '__this_module')
/path/to/LiME/src/lime.mod.c:14:2: error: unknown field 'arch' specified in initializer
.arch = MODULE_ARCH_INIT,
^
/path/to/LiME/src/lime.mod.c:14:10: error: 'MODULE_ARCH_INIT' undeclared here (not in a function)
.arch = MODULE_ARCH_INIT,
^
/path/to/LiME/src/lime.mod.c:14:2: warning: excess elements in struct initializer
.arch = MODULE_ARCH_INIT,
^
/path/to/LiME/src/lime.mod.c:14:2: warning: (near initialization for '__this_module')
make[2]: *** [/path/to/goldfish/scripts/Makefile.modpost:111: /path/to/LiME/src/lime.mod.o] Error 1
make[1]: *** [Makefile:1228: modules] Error 2
make[1]: Leaving directory '/path/to/goldfish'
make: *** [Makefile:35: default] Error 2
If I search for the 'undefined' symbols inside the System.map file of the built kernel I can find all of them. Any hint on how to solve this issue? Thank you
回答1:
I've solved this issued setting CONFIG_MODULES=y
in my .config file for the goldfish kernel. I also needed to replace a line in the .config file otherwise KBuild system would not notify the change in file and CONFIG_MODULES=y
would be overritten and not applied.
来源:https://stackoverflow.com/questions/57002979/lime-kernel-module-cross-compilation-fails