我现在正在使用Linux Tracepoint进行练习。 基本上,我正在尝试制作一个内核模块,在其中定义了探测功能并将其连接到Linux内核中的tracepoint(内核源文件dev.c中的tracepoint(“ trace_netif_receive_skb”))。 当我在SLES11上编译并运行内核模块时,它运行良好。 但是,当我在SLES12上执行相同的操作时,它抱怨该符号未定义。 内核模块源代码为:
1 #include
2 #include
3 #include
4 #include
5 #include
6
7 static void probe(void *ignore, struct sk_buff *skb)
8 {
9 printk(KERN_INFO "probe, protocol[0X%04X]\n", ntohs(skb->protocol));
10 }
11
12 static int __init init_tracepoint(void)
13 {
14 if (0 != register_trace_netif_receive_skb(probe, NULL))
15 {
16 printk(KERN_INFO "tracepoint init fails\n");
17 }
18
19 printk(KERN_INFO "tracepoint init succeeds\n");
20 return 0;
21 }
22
23 static void __exit cleanup_tracepoint(void)
24 {
25 unregister_trace_netif_receive_skb(probe, NULL);
26 tracepoint_synchronize_unregister();
27
28 printk(KERN_INFO "tracepoint exit\n");
29 }
30
31 module_init(init_tracepoint);
32 module_exit(cleanup_tracepoint);
33
34 MODULE_LICENSE("GPL");
这是SLES11的输出,没有错误报告。
suse11-1:~/works/tracepoint # make
make -C /lib/modules/3.0.76-0.11-default/build M=/root/works/tracepoint modules
make[1]: Entering directory `/usr/src/linux-3.0.76-0.11-obj/x86_64/default'
make -C ../../../linux-3.0.76-0.11 O=/usr/src/linux-3.0.76-0.11-obj/x86_64/default/. modules
CC [M] /root/works/tracepoint/tracepoint.o
Building modules, stage 2.
MODPOST 1 modules
CC /root/works/tracepoint/tracepoint.mod.o
LD [M] /root/works/tracepoint/tracepoint.ko
make[1]: Leaving directory `/usr/src/linux-3.0.76-0.11-obj/x86_64/default'
suse11-1:~/works/tracepoint # insmod tracepoint.ko
这是SLES12上的输出,它说:警告:“ __tracepoint_netif_receive_skb” [/root/works/codes/tracepoint/tracepoint.ko]未定义! 而且我可以在/ var / log / messages中找到“未知符号__tracepoint_netif_receive_skb(err 0)”。
suse12-1:~/works/codes/tracepoint # make
make -C /lib/modules/4.4.21-69-default/build M=/root/works/codes/tracepoint modules
make[1]: Entering directory '/usr/src/linux-4.4.21-69-obj/x86_64/default'
CC [M] /root/works/codes/tracepoint/tracepoint.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "__tracepoint_netif_receive_skb" [/root/works/codes/tracepoint/tracepoint.ko] undefined!
CC /root/works/codes/tracepoint/tracepoint.mod.o
LD [M] /root/works/codes/tracepoint/tracepoint.ko
make[1]: Leaving directory '/usr/src/linux-4.4.21-69-obj/x86_64/default'
suse12-1:~/works/codes/tracepoint #
suse12-1:~/works/codes/tracepoint # insmod tracepoint.ko
insmod: ERROR: could not insert module tracepoint.ko: Unknown symbol in module
我检查了SLES11和SLES12的跟踪点框架的内核源代码,除非调用EXPORT_TRACEPOINT_SYMBOL()或EXPORT_TRACEPOINT_SYMBOL_GPL(),否则不会导出定义为“ include / linux / tracepoint.h”的“ __tracepoint _ ## name”,但是我没有这样做。在Linux内核代码中找不到在调用EXPORT_TRACEPOINT_SYMBOL(netif_receive_skb)或EXPORT_TRACEPOINT_SYMBOL_GPL(netif_receive_skb)导出符号__tracepoint_netif_receive_skb的任何位置。 那为什么我在SLES11上遇到问题呢? 我如何在SLES12上使用它?