Skip to content

Commit c9a0f3b

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
bpf: Resolve BTF IDs in vmlinux image
Using BTF_ID_LIST macro to define lists for several helpers using BTF arguments. And running resolve_btfids on vmlinux elf object during linking, so the .BTF_ids section gets the IDs resolved. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Tested-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/20200711215329.41165-5-jolsa@kernel.org
1 parent 5a2798a commit c9a0f3b

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ OBJSIZE = $(CROSS_COMPILE)size
448448
STRIP = $(CROSS_COMPILE)strip
449449
endif
450450
PAHOLE = pahole
451+
RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
451452
LEX = flex
452453
YACC = bison
453454
AWK = awk
@@ -510,7 +511,7 @@ GCC_PLUGINS_CFLAGS :=
510511
CLANG_FLAGS :=
511512

512513
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
513-
export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE LEX YACC AWK INSTALLKERNEL
514+
export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
514515
export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
515516
export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ
516517
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE

kernel/bpf/stackmap.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/elf.h>
1010
#include <linux/pagemap.h>
1111
#include <linux/irq_work.h>
12+
#include <linux/btf_ids.h>
1213
#include "percpu_freelist.h"
1314

1415
#define STACK_CREATE_FLAG_MASK \
@@ -576,7 +577,9 @@ BPF_CALL_4(bpf_get_task_stack, struct task_struct *, task, void *, buf,
576577
return __bpf_get_stack(regs, task, buf, size, flags);
577578
}
578579

579-
static int bpf_get_task_stack_btf_ids[5];
580+
BTF_ID_LIST(bpf_get_task_stack_btf_ids)
581+
BTF_ID(struct, task_struct)
582+
580583
const struct bpf_func_proto bpf_get_task_stack_proto = {
581584
.func = bpf_get_task_stack,
582585
.gpl_only = false,

kernel/trace/bpf_trace.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/kprobes.h>
1414
#include <linux/syscalls.h>
1515
#include <linux/error-injection.h>
16+
#include <linux/btf_ids.h>
1617

1718
#include <asm/tlb.h>
1819

@@ -710,7 +711,9 @@ BPF_CALL_5(bpf_seq_printf, struct seq_file *, m, char *, fmt, u32, fmt_size,
710711
return err;
711712
}
712713

713-
static int bpf_seq_printf_btf_ids[5];
714+
BTF_ID_LIST(bpf_seq_printf_btf_ids)
715+
BTF_ID(struct, seq_file)
716+
714717
static const struct bpf_func_proto bpf_seq_printf_proto = {
715718
.func = bpf_seq_printf,
716719
.gpl_only = true,
@@ -728,7 +731,9 @@ BPF_CALL_3(bpf_seq_write, struct seq_file *, m, const void *, data, u32, len)
728731
return seq_write(m, data, len) ? -EOVERFLOW : 0;
729732
}
730733

731-
static int bpf_seq_write_btf_ids[5];
734+
BTF_ID_LIST(bpf_seq_write_btf_ids)
735+
BTF_ID(struct, seq_file)
736+
732737
static const struct bpf_func_proto bpf_seq_write_proto = {
733738
.func = bpf_seq_write,
734739
.gpl_only = true,

net/core/filter.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include <net/ipv6_stubs.h>
7676
#include <net/bpf_sk_storage.h>
7777
#include <net/transp_v6.h>
78+
#include <linux/btf_ids.h>
7879

7980
/**
8081
* sk_filter_trim_cap - run a packet through a socket filter
@@ -3779,7 +3780,9 @@ static const struct bpf_func_proto bpf_skb_event_output_proto = {
37793780
.arg5_type = ARG_CONST_SIZE_OR_ZERO,
37803781
};
37813782

3782-
static int bpf_skb_output_btf_ids[5];
3783+
BTF_ID_LIST(bpf_skb_output_btf_ids)
3784+
BTF_ID(struct, sk_buff)
3785+
37833786
const struct bpf_func_proto bpf_skb_output_proto = {
37843787
.func = bpf_skb_event_output,
37853788
.gpl_only = true,
@@ -4173,7 +4176,9 @@ static const struct bpf_func_proto bpf_xdp_event_output_proto = {
41734176
.arg5_type = ARG_CONST_SIZE_OR_ZERO,
41744177
};
41754178

4176-
static int bpf_xdp_output_btf_ids[5];
4179+
BTF_ID_LIST(bpf_xdp_output_btf_ids)
4180+
BTF_ID(struct, xdp_buff)
4181+
41774182
const struct bpf_func_proto bpf_xdp_output_proto = {
41784183
.func = bpf_xdp_event_output,
41794184
.gpl_only = true,

scripts/link-vmlinux.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ fi
336336

337337
vmlinux_link vmlinux "${kallsymso}" ${btf_vmlinux_bin_o}
338338

339+
# fill in BTF IDs
340+
if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then
341+
info BTFIDS vmlinux
342+
${RESOLVE_BTFIDS} vmlinux
343+
fi
344+
339345
if [ -n "${CONFIG_BUILDTIME_TABLE_SORT}" ]; then
340346
info SORTTAB vmlinux
341347
if ! sorttable vmlinux; then

0 commit comments

Comments
 (0)