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
This commit is contained in:
parent
5a2798ab32
commit
c9a0f3b85e
3
Makefile
3
Makefile
|
@ -448,6 +448,7 @@ OBJSIZE = $(CROSS_COMPILE)size
|
||||||
STRIP = $(CROSS_COMPILE)strip
|
STRIP = $(CROSS_COMPILE)strip
|
||||||
endif
|
endif
|
||||||
PAHOLE = pahole
|
PAHOLE = pahole
|
||||||
|
RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
|
||||||
LEX = flex
|
LEX = flex
|
||||||
YACC = bison
|
YACC = bison
|
||||||
AWK = awk
|
AWK = awk
|
||||||
|
@ -510,7 +511,7 @@ GCC_PLUGINS_CFLAGS :=
|
||||||
CLANG_FLAGS :=
|
CLANG_FLAGS :=
|
||||||
|
|
||||||
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
|
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
|
||||||
export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE LEX YACC AWK INSTALLKERNEL
|
export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
|
||||||
export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
|
export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
|
||||||
export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ
|
export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ
|
||||||
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
|
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <linux/elf.h>
|
#include <linux/elf.h>
|
||||||
#include <linux/pagemap.h>
|
#include <linux/pagemap.h>
|
||||||
#include <linux/irq_work.h>
|
#include <linux/irq_work.h>
|
||||||
|
#include <linux/btf_ids.h>
|
||||||
#include "percpu_freelist.h"
|
#include "percpu_freelist.h"
|
||||||
|
|
||||||
#define STACK_CREATE_FLAG_MASK \
|
#define STACK_CREATE_FLAG_MASK \
|
||||||
|
@ -576,7 +577,9 @@ BPF_CALL_4(bpf_get_task_stack, struct task_struct *, task, void *, buf,
|
||||||
return __bpf_get_stack(regs, task, buf, size, flags);
|
return __bpf_get_stack(regs, task, buf, size, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bpf_get_task_stack_btf_ids[5];
|
BTF_ID_LIST(bpf_get_task_stack_btf_ids)
|
||||||
|
BTF_ID(struct, task_struct)
|
||||||
|
|
||||||
const struct bpf_func_proto bpf_get_task_stack_proto = {
|
const struct bpf_func_proto bpf_get_task_stack_proto = {
|
||||||
.func = bpf_get_task_stack,
|
.func = bpf_get_task_stack,
|
||||||
.gpl_only = false,
|
.gpl_only = false,
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <linux/kprobes.h>
|
#include <linux/kprobes.h>
|
||||||
#include <linux/syscalls.h>
|
#include <linux/syscalls.h>
|
||||||
#include <linux/error-injection.h>
|
#include <linux/error-injection.h>
|
||||||
|
#include <linux/btf_ids.h>
|
||||||
|
|
||||||
#include <asm/tlb.h>
|
#include <asm/tlb.h>
|
||||||
|
|
||||||
|
@ -710,7 +711,9 @@ out:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bpf_seq_printf_btf_ids[5];
|
BTF_ID_LIST(bpf_seq_printf_btf_ids)
|
||||||
|
BTF_ID(struct, seq_file)
|
||||||
|
|
||||||
static const struct bpf_func_proto bpf_seq_printf_proto = {
|
static const struct bpf_func_proto bpf_seq_printf_proto = {
|
||||||
.func = bpf_seq_printf,
|
.func = bpf_seq_printf,
|
||||||
.gpl_only = true,
|
.gpl_only = true,
|
||||||
|
@ -728,7 +731,9 @@ BPF_CALL_3(bpf_seq_write, struct seq_file *, m, const void *, data, u32, len)
|
||||||
return seq_write(m, data, len) ? -EOVERFLOW : 0;
|
return seq_write(m, data, len) ? -EOVERFLOW : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bpf_seq_write_btf_ids[5];
|
BTF_ID_LIST(bpf_seq_write_btf_ids)
|
||||||
|
BTF_ID(struct, seq_file)
|
||||||
|
|
||||||
static const struct bpf_func_proto bpf_seq_write_proto = {
|
static const struct bpf_func_proto bpf_seq_write_proto = {
|
||||||
.func = bpf_seq_write,
|
.func = bpf_seq_write,
|
||||||
.gpl_only = true,
|
.gpl_only = true,
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
#include <net/ipv6_stubs.h>
|
#include <net/ipv6_stubs.h>
|
||||||
#include <net/bpf_sk_storage.h>
|
#include <net/bpf_sk_storage.h>
|
||||||
#include <net/transp_v6.h>
|
#include <net/transp_v6.h>
|
||||||
|
#include <linux/btf_ids.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sk_filter_trim_cap - run a packet through a socket filter
|
* 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 = {
|
||||||
.arg5_type = ARG_CONST_SIZE_OR_ZERO,
|
.arg5_type = ARG_CONST_SIZE_OR_ZERO,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int bpf_skb_output_btf_ids[5];
|
BTF_ID_LIST(bpf_skb_output_btf_ids)
|
||||||
|
BTF_ID(struct, sk_buff)
|
||||||
|
|
||||||
const struct bpf_func_proto bpf_skb_output_proto = {
|
const struct bpf_func_proto bpf_skb_output_proto = {
|
||||||
.func = bpf_skb_event_output,
|
.func = bpf_skb_event_output,
|
||||||
.gpl_only = true,
|
.gpl_only = true,
|
||||||
|
@ -4173,7 +4176,9 @@ static const struct bpf_func_proto bpf_xdp_event_output_proto = {
|
||||||
.arg5_type = ARG_CONST_SIZE_OR_ZERO,
|
.arg5_type = ARG_CONST_SIZE_OR_ZERO,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int bpf_xdp_output_btf_ids[5];
|
BTF_ID_LIST(bpf_xdp_output_btf_ids)
|
||||||
|
BTF_ID(struct, xdp_buff)
|
||||||
|
|
||||||
const struct bpf_func_proto bpf_xdp_output_proto = {
|
const struct bpf_func_proto bpf_xdp_output_proto = {
|
||||||
.func = bpf_xdp_event_output,
|
.func = bpf_xdp_event_output,
|
||||||
.gpl_only = true,
|
.gpl_only = true,
|
||||||
|
|
|
@ -336,6 +336,12 @@ fi
|
||||||
|
|
||||||
vmlinux_link vmlinux "${kallsymso}" ${btf_vmlinux_bin_o}
|
vmlinux_link vmlinux "${kallsymso}" ${btf_vmlinux_bin_o}
|
||||||
|
|
||||||
|
# fill in BTF IDs
|
||||||
|
if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then
|
||||||
|
info BTFIDS vmlinux
|
||||||
|
${RESOLVE_BTFIDS} vmlinux
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "${CONFIG_BUILDTIME_TABLE_SORT}" ]; then
|
if [ -n "${CONFIG_BUILDTIME_TABLE_SORT}" ]; then
|
||||||
info SORTTAB vmlinux
|
info SORTTAB vmlinux
|
||||||
if ! sorttable vmlinux; then
|
if ! sorttable vmlinux; then
|
||||||
|
|
Loading…
Reference in New Issue