Linking kernel modules with gcc/ld
Posted: Wed May 14, 2014 4:04 am
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...
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...