在 ubuntu clang 和 llvm 中编译扩展的 berkley 数据包过滤器程序,安装了 libbpf 也安装了 bt helper func not found& formar error
compiling extended berkley packet filters program in ubuntu clang and llvm installed with libbpf also installed bt helper func not found& formar error
所以我有 llvm、内核头文件 (5.14.1)、clang 和 libbpf,以及我从 linux 源代码复制到 ebpf 程序目录中的 bpf_helpers.h。这是一个简单的程序,我喜欢加载它,并且 运行 当 execve
系统从任何程序
被调用时
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "bpf_helpers.h" // some helpers not found, why is that?
#define SEC(NAME) __attribute__((section(NAME), used))
SEC("kprobe/execve")
int bpf_prog1(struct pt_regs *ctx)
{
char m[]="hello world";
bpf_trace_printk(m,sizeof(m));
return 0;
}
char _license[] SEC("license") = "GPL";
真的是一个简单的程序,
我用 clang 编译了程序,但是当我这样做时 llvm-objdump -S ./one.o
但它给出了无法识别格式的消息,
所以如果我的 llvm 不理解我的 .o 文件,我想知道那是什么意思。我可以忽略 llvm-objdum 的这个警告并继续使用 ebpf 加载程序加载 .o 文件吗,或者我创建 .o 文件并用 clang 编译的方式是错误的所以在这种情况下有人可以告诉如何创建 ebpf来自 ebpf .c 文件的程序并使用加载程序加载它。
如果您在 Ubuntu 上 运行 并且安装了 libbpf-dev
,您应该能够像这样包含 libbpf headers:
#include <bpf/bpf_helpers.h>
和(在加载程序中):
#include <bpf/libbpf.h>
至于llvm-objdump
抱怨,这可能取决于您使用的编译命令。您是否超过了 -t bpf
目标?您具体使用什么命令?
所以我有 llvm、内核头文件 (5.14.1)、clang 和 libbpf,以及我从 linux 源代码复制到 ebpf 程序目录中的 bpf_helpers.h。这是一个简单的程序,我喜欢加载它,并且 运行 当 execve
系统从任何程序
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "bpf_helpers.h" // some helpers not found, why is that?
#define SEC(NAME) __attribute__((section(NAME), used))
SEC("kprobe/execve")
int bpf_prog1(struct pt_regs *ctx)
{
char m[]="hello world";
bpf_trace_printk(m,sizeof(m));
return 0;
}
char _license[] SEC("license") = "GPL";
真的是一个简单的程序,
我用 clang 编译了程序,但是当我这样做时 llvm-objdump -S ./one.o
但它给出了无法识别格式的消息,
所以如果我的 llvm 不理解我的 .o 文件,我想知道那是什么意思。我可以忽略 llvm-objdum 的这个警告并继续使用 ebpf 加载程序加载 .o 文件吗,或者我创建 .o 文件并用 clang 编译的方式是错误的所以在这种情况下有人可以告诉如何创建 ebpf来自 ebpf .c 文件的程序并使用加载程序加载它。
如果您在 Ubuntu 上 运行 并且安装了 libbpf-dev
,您应该能够像这样包含 libbpf headers:
#include <bpf/bpf_helpers.h>
和(在加载程序中):
#include <bpf/libbpf.h>
至于llvm-objdump
抱怨,这可能取决于您使用的编译命令。您是否超过了 -t bpf
目标?您具体使用什么命令?