Hi,
I'm probably making some sort of basic error here, but how do I get gcc/ld to link a binary suitable for use as a kernel module?
I'm using ELF format and as far as I can tell, the binary needs to have both program headers in order for me to load it and relocation tables to allow me to load it at an arbitrary(ish) place in the kernel's address space. However, by default it seems that the linker outputs files without relocation tables (i.e. non-relocatable executables), but if I pass the "-r" (--relocatable) flag to the linker, the files are "partially linked" and have no program headers.
I've looked through the gcc and ld manual pages, but can't see anything obvious...
Linking kernel modules with gcc/ld
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Linking kernel modules with gcc/ld
There's two relocation flags right above each other - you're probably looking for --emit-relocs (-q) which actually performs linking unlike what -r does.
Re: Linking kernel modules with gcc/ld
Thanks, that looks like it's produced what I want (according to objdump at least). I'm not sure how I didn't spot that option before...