I'm trying to build kexec as a module, but I'm running into a weird problem. My obj-m is:

obj-m += kexec.o machine_kexec.o relocate_kernel.o

When I run the makefile, it complains that there's "no rule to make target relocate_kernel.c, needed by relocate_kernel.o"

How should I be telling it to include the assembly file? I've looked in the kernel Makefile, and while I'm not very good with them, it DOES appear that there's a rule for .S > .o. Am I wrong about this?

1 Answer 1


As always, RTFM. Answering this and leaving it up to help others that may come across this. Per the Linux documentation project, I was using obj-m wrong:

Sometimes it makes sense to divide a kernel module between several source files. Here's an example of such a kernel module.

[ Source files ... ]

And finally, the makefile:

Example 2-10. Makefile

obj-m += hello-1.o obj-m += hello-2.o obj-m += hello-3.o obj-m += hello-4.o obj-m += hello-5.o obj-m += startstop.o startstop-objs := start.o stop.o

all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Linux Kernel Module Programming Guide: 2.7. Modules Spanning Multiple Files

So, my Makefile should have read:

obj-m += kexecmod.o
kexecmod-objs := kexec.o machine_kexec.o relocate_kernel.o

Which compiled relocate_kernel.S into relocate_kernel.o

(To anyone stumbling across this trying to compile kexec as a module, I still haven't found all the dependencies, but this is a start.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .