Issue
Let we've written the following simplest module source file:
#include <linux/init.h>
#include <linux/module.h>
static int __init md_init(void){
printk("Hello kernel");
return 0;
}
static void __exit md_exit(void){
printk("Goodbye kernel");
}
module_init(md_init);
module_exit(md_exit);
How can I see this source after preprocessing? I want to know how are __init
and __exit
macros deployed and what's the module_init(md_init)
and module_exit(md_exit)
? How it works?
Solution
If you only plan to get the preprocessed output of kernel module, don't use Makefile, cause Makefiles (sub-make) will try to produce an object file with ability to insert into the kernel. Which contradicts with gcc -E
, which just stops after preprocessing. So, just do the followings by using gcc
:
gcc -E new.c -I$TREE/include -I$TREE/arch/x86/include -I$TREE/include/uapi
-E
is to get the preprocessed output, $TREE is the location of your kernel tree and if you use other arch then change x86. And we know that, gcc
takes include dir parameter with -I
, so pass all the kernel include dir through -I
. Hope this helps!
Answered By - rakib_ Answer Checked By - Marie Seifert (WPSolving Admin)