Yes, this should be possible, provided your library archive doesn’t depend on any external symbols (e.g., no C-library dependence). There are two things meant by your question, and both are possible. The first is: can you have multiple source files linked to form one single loadable kernel module, much as they can form an archive or executable in userspace? The second is: suppose you have a precompiled (for the target arch) library archive making use of no external symbols. Can you use that object code in a kernel module without the source code? The answer to both is yes, as I will show in this example.
Suppose I want to make a module which will eventually be called
foo.ko. The logic is complicated enough to be separated into two separate source files:
bar.c and
baz.c (this addresses the first question). Additionally, there is a precompiled library filled with symbols referenced by
bar.c or
baz.c. This is named
qux.a (this addresses the second question). Then there is a Makefile to tie it all together (this is the file I will show you). All four of these files live in the same directory (for simplicity), which happens to be somewhere outside the kernel source tree (also for simplicity).
The Makefile might go something like this:
Code:
ifndef KERNELDIR
KERNELDIR := /lib/modules/$(shell uname -r)/build
endif
obj-m := foo.o
foo-objs := bar.o baz.o qux.a
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD)
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
/sbin/depmod -ae
This way you can execute
make from the directory containing the sources. A module with prefix
foo (full name
foo.ko) will be built. The objects from which it is built are
bar.o,
baz.o and
qux.a. Since
bar.c and
baz.c are newer than
bar.o and
baz.o (which don’t yet exist), they will be compiled into their respective objects. Since
qux.a exists (and since there is no requisite), it will be incorporated as-is.
HTH.
P.S., you can read more about using Makefiles with the kbuild system
here.