Who knows how to solve "unknown symbol" error when `insmod probe.ko`?
I enconter this problem when writing a simple module with a function named "kallsyms_lookup_name" inside.
The error when `insmod probe.ko` is as bleow:
===========insmod ERROR==========BEG
probe: Unknown symbol kallsyms_lookup_name
probe: Unknown symbol register_kprobe
insmod: error inserting `porbe.ko`: -1 Unknown symbol in module
===========insmod ERROR==========END
my module source code is separated to kernel source; where kernel source is locateed at $HOME/kernel/linux-`uname -r` and module source at $HOME/program/kernel/module/sample.
the compile command is : make -C $HOME/kernel/linux-`uname -r` SUBDIRS=$PWD modules
there's no error message except one warning "*** Warning: "kallsyms_lookup_name" [/root/program/kernel/module/sample/probe.ko] undefined!"
and I can find symbol in System.map as well as /proc/kallsyms.
some one told me to enable the option "CONFIG_KALLSYMS", set to 'y'.
and I found out that the option was enabled[set to y] in my .config, located in the $HOME/kernel/linux-`uname -r`(which is my kernel source).
I don't know what to do now. I know this may be a newbie question, but I have no idea how to solve it for few weeks, even though I read the makefile.txt and modules.txt located in the $KERNEL_SOURCE/Documentation/kbuild.
I appreciate any suggestion, sincerely.
==========Makefile==========BEG
obj-m += probe.o
==========Makefile==========END
===========System.map==========BEG
c0135190 t add_kallsyms
c0136100 T module_kallsyms_lookup_name
c0136610 T kallsyms_lookup_name
c01366f0 T kallsyms_lookup
c0136c40 t kallsyms_open
c0136cb0 t kallsyms_release
c0429b00 D kallsyms_op
c0429b20 d kallsyms_operations
c0486344 D kallsyms_addresses
c04947c0 D kallsyms_num_syms
c04947c4 D kallsyms_names
c04dd030 T kallsyms_init
c04f4cc0 t __initcall_kallsyms_init
===========System.map==========END
============/proc/kallsyms==========BEG
c0135190 t add_kallsyms
c0136100 t module_kallsyms_lookup_name
c0136610 t kallsyms_lookup_name
c01366f0 t kallsyms_lookup
c0136c40 t kallsyms_open
c0136cb0 t kallsyms_release
c04dd030 t kallsyms_init
============/proc/kallsyms==========END
============probe.c===============BEG
#include <linux/kallsyms.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
/* kprobes */
#include <linux/kprobes.h>
int
handler_pre(struct kprobe *p, struct pt_regs *regs)
{
printk("pre_hanlder: p->addr=0x%p, eflags=0x%lx\n",
p->addr, regs->eflags);
return 0;
}
void
handler_post(struct kprobe *p, struct pt_regs *regs, unsigned long eflags)
{
printk("post_handler: p->addr=0x%p, eflags=0x%lx \n",
p->addr, regs->eflags);
}
int
handler_fault(struct kprobe *p, struct pt_regs *regs, int trapnr)
{
printk("fault_handler
->addr=0x%p, eflags=0x%lx\n",
p->addr, regs->eflags);
return 0;
}
int
init_module(void)
{
struct kprobe kp;
printk(KERN_ALERT"init module!\n");
kp.pre_handler=handler_pre;
kp.post_handler=handler_post;
kp.fault_handler=handler_fault;
kp.addr=(kprobe_opcode_t *)kallsyms_lookup_name("do_fork");
if(kp.addr==NULL){
printk("kallsyms_lookup_name could not find address for the specified sumbol name!\n");
return 1;
}
register_kprobe(&kp);
return 0;
}
void
cleanup_module()
{
printk(KERN_ALERT"cleanup module!\n");
}
============probe.c===============END