1

вот код.

#include <linux/bpf.h>

#define SEC(NAME) __attribute__((section(NAME), used))

SEC("tracepoint/syscalls/sys_enter_execve")
int bpf_prog(void *ctx) {
        char msg[] = "Hello, BPF World!";
        bpf_trace_printk(msg, sizeof(msg));
        return 0;
}

char _license[] SEC("license") = "GPL";

вот makefile

C=/usr/include/x86_64-linux-gnu
S=/usr/src/linux-hwe-5.8-headers-5.8.0-48/include/linux
M=/usr/src/linux-hwe-5.8-headers-5.8.0-48/include/
MO=/usr/src/linux-hwe-5.8-headers-5.8.0-48/usr/include/
all:
        clang -O2 -target bpf -c bpf.c -I${S} -I${C} -I${M} -I${MO} -o bpf.o

вот ошибка

clang -O2 -target bpf -c bpf.c -I/usr/src/linux-hwe-5.8-headers-5.8.0-48/include/linux -I/usr/include/x86_64-linux-gnu -I/usr/src/linux-hwe-5.8-headers-5.8.0-48/include/ -I/usr/src/linux-hwe-5.8-headers-5.8.0-48/usr/include/ -o bpf.o
In file included from bpf.c:1:
In file included from /usr/src/linux-hwe-5.8-headers-5.8.0-48/include/linux/bpf.h:9:
In file included from /usr/src/linux-hwe-5.8-headers-5.8.0-48/include/linux/workqueue.h:9:
In file included from /usr/src/linux-hwe-5.8-headers-5.8.0-48/include/linux/timer.h:5:
In file included from /usr/src/linux-hwe-5.8-headers-5.8.0-48/include/linux/list.h:9:
In file included from /usr/src/linux-hwe-5.8-headers-5.8.0-48/include/linux/kernel.h:8:
/usr/src/linux-hwe-5.8-headers-5.8.0-48/include/linux/linkage.h:8:10: fatal error: 'asm/linkage.h' file not found
#include <asm/linkage.h>
         ^~~~~~~~~~~~~~~
1 error generated.
make: *** [makefile:6: all] Error 1
12
  • @aleksandrbarakin так ничего не выводит же.
    – xverizex
    3 апр 2021 в 17:44
  • есть asm-generic, но не помогает.
    – xverizex
    3 апр 2021 в 17:44
  • Насколько я вижу в выводе find этот файл находится в ряде каталогов. Попробуйте тот, что соответствует вашей архитектуре
    – avp
    3 апр 2021 в 17:49
  • @avp у меня find не выдал ничего. архитектура x86_64, помогите.
    – xverizex
    3 апр 2021 в 17:51
  • 1
    Я немного почитал про BPF и, мне кажется, вы делаете что-то не то. Насколько я понимаю, вам нужно сначала написать eBPF программу, затем скомпилировать ее с помощью Clang или GCC в eBPF байткод, затем написать программу на любом языке программирования (который может делать системные вызовы к ядру), и с помощью системного вызова ядра bpf() передать этот скомпилированный байткод в ядро, которое его уже будет исполнять.
    – eanmos
    3 апр 2021 в 18:39

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.