Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 2 down vote accepted

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.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.