I have written a sample hello.ko kernel module:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void)
{
printk(KERN_INFO "Hello world.\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
Here, I have used "printk" method which is a Kernel API exposed by Linux. I can see the Linux exported symbols in "/proc/kallsyms". I am curious to know how do gcc/ld links the called Kernel APIs? Does gcc/ld gets address of kernel method from "/proc/kallsyms" or some other file and perform linking? If yes, how do gcc/ld get to know that? I could not any option which tells that.