BPF samples编译及错误解决

先阅读samples/bpf/README.rst。

非常关键:编译最新代码,llvm/llc和clang版本要高于10.0.0,使用llc-12和clang-12可以编译成功。

llc --version

  LLVM version 10.0.0

clang --version

clang version 10.0.0-4ubuntu1 

这两个版本,无法全部编译最新的bpf用例。

linux-next编译BPF:

make menuconfig

make bzImage

make headers_install

make M=samples/bpf/

或者指定LLC和CLANG版本:

make M=samples/bpf/ LLC=llc-12 CLANG=clang-12

如果要静态连接,可以加上选项:TPROGS_LDFLAGS=-static

例如:

make M=samples/bpf/ TPROGS_LDFLAGS=-static

注:使用make defconfig需要打开这两个宏

CONFIG_BPF=y

CONFIG_DEBUG_INFO_BTF=y

CONFIG_BPF_SYSCALL=y

alpha@mascot ~/Workspace/linux/linux-next $ grep BTF .config

CONFIG_VIDEO_SONY_BTF_MPX=m

CONFIG_DEBUG_INFO_BTF=y

CONFIG_PAHOLE_HAS_SPLIT_BTF=y

CONFIG_DEBUG_INFO_BTF_MODULES=y

# CONFIG_MODULE_ALLOW_BTF_MISMATCH is not set

alpha@mascot ~/Workspace/linux/linux-next $ grep BPF .config

CONFIG_BPF=y

CONFIG_HAVE_EBPF_JIT=y

CONFIG_ARCH_WANT_DEFAULT_BPF_JIT=y

# BPF subsystem

CONFIG_BPF_SYSCALL=y

CONFIG_BPF_JIT=y

CONFIG_BPF_JIT_ALWAYS_ON=y

CONFIG_BPF_JIT_DEFAULT_ON=y

CONFIG_BPF_UNPRIV_DEFAULT_OFF=y

# CONFIG_BPF_PRELOAD is not set

# CONFIG_BPF_LSM is not set

# end of BPF subsystem

CONFIG_CGROUP_BPF=y

CONFIG_IPV6_SEG6_BPF=y

CONFIG_NETFILTER_XT_MATCH_BPF=m

CONFIG_BPFILTER=y

CONFIG_BPFILTER_UMH=m

CONFIG_NET_CLS_BPF=m

CONFIG_NET_ACT_BPF=m

CONFIG_BPF_STREAM_PARSER=y

CONFIG_LWTUNNEL_BPF=y

CONFIG_BPF_EVENTS=y

CONFIG_BPF_KPROBE_OVERRIDE=y

CONFIG_TEST_BPF=m

===========================================

make[1]: *** No rule to make target 'debian/canonical-certs.pem', needed by 'certs/x509_certificate_list'.  Stop.

make[1]: *** No rule to make target 'debian/canonical-revoked-certs.pem', needed by 'certs/x509_revocation_list'.  Stop.

=================

alpha@mascot ~/Workspace/linux/linux-next $ grep 'debian/canonical-certs.pem' .config

CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"

alpha@mascot ~/Workspace/linux/linux-next $ ./scripts/config -d CONFIG_SYSTEM_TRUSTED_KEYS

alpha@mascot ~/Workspace/linux/linux-next $ grep 'debian/canonical-certs.pem' .config

alpha@mascot ~/Workspace/linux/linux-next $ grep 'debian/canonical-revoked-certs.pem' .config

CONFIG_SYSTEM_REVOCATION_KEYS="debian/canonical-revoked-certs.pem"

alpha@mascot ~/Workspace/linux/linux-next $ ./scripts/config -d CONFIG_SYSTEM_REVOCATION_KEYS

alpha@mascot ~/Workspace/linux/linux-next $ grep 'debian/canonical-revoked-certs.pem' .config

=====================================================

=====================================================

  CC  samples/bpf/xdp_rxq_info_user.o

skeleton/pid_iter.bpf.c:35:10: error: incomplete definition of type 'struct bpf_link'

                return BPF_CORE_READ((struct bpf_link *)ent, id);

                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:403:2: note: expanded from macro 'BPF_CORE_READ'

        ___type((src), a, ##__VA_ARGS__) __r;                               \

        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:274:29: note: expanded from macro '___type'

#define ___type(...) typeof(___arrow(__VA_ARGS__))

                            ^~~~~~~~~~~~~~~~~~~~~

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:272:23: note: expanded from macro '___arrow'

#define ___arrow(...) ___apply(___arrow, ___narg(__VA_ARGS__))(__VA_ARGS__)

                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:223:25: note: expanded from macro '___concat'

#define ___concat(a, b) a ## b

                        ^

<scratch space>:16:1: note: expanded from here

___arrow2

^

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:263:26: note: expanded from macro '___arrow2'

#define ___arrow2(a, b) a->b

                        ~^

skeleton/pid_iter.bpf.c:35:32: note: forward declaration of 'struct bpf_link'

                return BPF_CORE_READ((struct bpf_link *)ent, id);

                                             ^

skeleton/pid_iter.bpf.c:35:10: error: incomplete definition of type 'struct bpf_link'

                return BPF_CORE_READ((struct bpf_link *)ent, id);

                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:404:2: note: expanded from macro 'BPF_CORE_READ'

        BPF_CORE_READ_INTO(&__r, (src), a, ##__VA_ARGS__);                  \

        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:311:2: note: expanded from macro 'BPF_CORE_READ_INTO'

        ___core_read(bpf_core_read, bpf_core_read,                          \

        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:302:2: note: expanded from macro '___core_read'

        ___apply(___core_read, ___empty(__VA_ARGS__))(fn, fn_ptr, dst,      \

        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

note: (skipping 3 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:296:2: note: expanded from macro '___core_read0'

        ___read(fn, dst, ___type(src), src, a);

        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:277:59: note: expanded from macro '___read'

        read_fn((void *)(dst), sizeof(*(dst)), &((src_type)(src))->accessor)

        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:206:79: note: expanded from macro 'bpf_core_read'

        bpf_probe_read_kernel(dst, sz, (const void *)__builtin_preserve_access_index(src))

                                                                                     ^~~

skeleton/pid_iter.bpf.c:35:32: note: forward declaration of 'struct bpf_link'

                return BPF_CORE_READ((struct bpf_link *)ent, id);

                                             ^

skeleton/pid_iter.bpf.c:35:10: error: returning 'void' from a function with incompatible result type '__u32' (aka 'unsigned int')

                return BPF_CORE_READ((struct bpf_link *)ent, id);

                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/home/alpha/Workspace/linux/linux-next/samples/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:402:36: note: expanded from macro 'BPF_CORE_READ'

#define BPF_CORE_READ(src, a, ...) ({                                       \

                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

skeleton/pid_iter.bpf.c:42:17: warning: declaration of 'struct bpf_iter__task_file' will not be visible outside of this function [-Wvisibility]

int iter(struct bpf_iter__task_file *ctx)

                ^

skeleton/pid_iter.bpf.c:44:25: error: incomplete definition of type 'struct bpf_iter__task_file'

        struct file *file = ctx->file;

                            ~~~^

skeleton/pid_iter.bpf.c:42:17: note: forward declaration of 'struct bpf_iter__task_file'

int iter(struct bpf_iter__task_file *ctx)

                ^

skeleton/pid_iter.bpf.c:45:32: error: incomplete definition of type 'struct bpf_iter__task_file'

        struct task_struct *task = ctx->task;

                                   ~~~^

skeleton/pid_iter.bpf.c:42:17: note: forward declaration of 'struct bpf_iter__task_file'

int iter(struct bpf_iter__task_file *ctx)

                ^

skeleton/pid_iter.bpf.c:76:19: error: incomplete definition of type 'struct bpf_iter__task_file'

        bpf_seq_write(ctx->meta->seq, &e, sizeof(e));

                      ~~~^

skeleton/pid_iter.bpf.c:42:17: note: forward declaration of 'struct bpf_iter__task_file'

int iter(struct bpf_iter__task_file *ctx)

========================

这种错误,尝试执行命令:

make -C samples/bpf/ clean

make -C tools/ clean

make bzImage

make headers_install

make M=samples/bpf/ LLC=llc-12 CLANG=clang-12

============================================================

============================================================

Error: failed to load BTF from /home/alpha/Workspace/linux/mainline/linux/vmlinux: Unknown error -2

# CONFIG_DEBUG_INFO_BTF is not set

=================

要打开CONFIG_DEBUG_INFO_BTF:

/scripts/config -e CONFIG_DEBUG_INFO_BTF

============================================================

=======================================

libbpf: failed to find BTF info for global/extern symbol 'tx_mac_addr'

Error: failed to link 'samples/bpf/xdp_redirect_cpu.bpf.o': Unknown error -2 (-2)

make[1]: *** [samples/bpf/Makefile:429: samples/bpf/xdp_redirect_cpu.skel.h] Error 254

=================

这种错误是llc和clang版本不对,要高于10.x.x版本: 

make M=samples/bpf/ LLC=llc-12 CLANG=clang-12

===============================================

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
BPF and related observability tools give software professionals unprecedented visibility into software, helping them analyze operating system and application performance, troubleshoot code, and strengthen security. BPF Performance Tools: Linux System and Application Observability is the industry’s most comprehensive guide to using these tools for observability. Brendan Gregg, author of the industry’s definitive guide to system performance, introduces powerful new methods and tools for doing analysis that leads to more robust, reliable, and safer code. This authoritative guide: Explores a wide spectrum of software and hardware targets Thoroughly covers open source BPF tools from the Linux Foundation iovisor project’s bcc and bpftrace repositories Summarizes performance engineering and kernel internals you need to understand Provides and discusses 150+ bpftrace tools, including 80 written specifically for this book: tools you can run as-is, without programming — or customize and develop further, using diverse interfaces and the bpftrace front-end You’ll learn how to use BPF (eBPF) tracing tools to analyze CPUs, memory, disks, file systems, networking, languages, applications, containers, hypervisors, security, and the Linux kernel. You’ll move from basic to advanced tools and techniques, producing new metrics, stack traces, custom latency histograms, and more. It’s like having a superpower: with Gregg’s guidance and tools, you can analyze virtually everything that impacts system performance, so you can improve virtually any Linux operating system or application.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值