Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples/bpf: fix symbol mismatch by compiler optimization

Currently, multiple kprobe programs are suffering from symbol mismatch
due to compiler optimization. These optimizations might induce
additional suffix to the symbol name such as '.isra' or '.constprop'.

# egrep ' finish_task_switch| __netif_receive_skb_core' /proc/kallsyms
ffffffff81135e50 t finish_task_switch.isra.0
ffffffff81dd36d0 t __netif_receive_skb_core.constprop.0
ffffffff8205cc0e t finish_task_switch.isra.0.cold
ffffffff820b1aba t __netif_receive_skb_core.constprop.0.cold

To avoid this, this commit replaces the original kprobe section to
kprobe.multi in order to match symbol with wildcard characters. Here,
asterisk is used for avoiding symbol mismatch.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Link: https://lore.kernel.org/r/20230818090119.477441-5-danieltimlee@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Daniel T. Lee and committed by
Alexei Starovoitov
02dabc24 4a0ee788

+3 -2
+1 -1
samples/bpf/offwaketime.bpf.c
··· 118 118 /* record previous thread sleep time */ 119 119 u32 pid = ctx->prev_pid; 120 120 #else 121 - SEC("kprobe/finish_task_switch") 121 + SEC("kprobe.multi/finish_task_switch*") 122 122 int oncpu(struct pt_regs *ctx) 123 123 { 124 124 struct task_struct *p = (void *) PT_REGS_PARM1(ctx);
+2 -1
samples/bpf/tracex1.bpf.c
··· 22 22 * Number of arguments and their positions can change, etc. 23 23 * In such case this bpf+kprobe example will no longer be meaningful 24 24 */ 25 - SEC("kprobe/__netif_receive_skb_core") 25 + SEC("kprobe.multi/__netif_receive_skb_core*") 26 26 int bpf_prog1(struct pt_regs *ctx) 27 27 { 28 28 /* attaches to kprobe __netif_receive_skb_core, 29 29 * looks for packets on loobpack device and prints them 30 + * (wildcard is used for avoiding symbol mismatch due to optimization) 30 31 */ 31 32 char devname[IFNAMSIZ]; 32 33 struct net_device *dev;