mirror of
https://github.com/torvalds/linux.git
synced 2024-11-29 23:51:37 +00:00
d4fffba4d0
Currently old compile rule (CLANG-bpf) doesn't contains VMLINUX_H define
flag which is essential for the bpf program that includes "vmlinux.h".
Also old compile rule doesn't directly specify the compile target as bpf,
instead it uses bunch of extra options with clang followed by long chain
of commands. (e.g. clang | opt | llvm-dis | llc)
In Makefile, there is already new compile rule which is more simple and
neat. And it also has -D__VMLINUX_H__ option. By just changing the _kern
suffix to .bpf will inherit the benefit of the new CLANG-BPF compile
target.
Also, this commit adds dummy gnu/stub.h to the samples/bpf directory.
As commit 1c2dd16add
("selftests/bpf: get rid of -D__x86_64__") noted,
compiling with 'clang -target bpf' will raise an error with stubs.h
unless workaround (-D__x86_64) is used. This commit solves this problem
by adding dummy stub.h to make /usr/include/features.h to follow the
expected path as the same way selftests/bpf dealt with.
Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20221224071527.2292-4-danieltimlee@gmail.com
30 lines
589 B
C
30 lines
589 B
C
#include "vmlinux.h"
|
|
#include <linux/version.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
struct {
|
|
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
|
|
__uint(key_size, sizeof(int));
|
|
__uint(value_size, sizeof(u32));
|
|
__uint(max_entries, 2);
|
|
} my_map SEC(".maps");
|
|
|
|
SEC("ksyscall/write")
|
|
int bpf_prog1(struct pt_regs *ctx)
|
|
{
|
|
struct S {
|
|
u64 pid;
|
|
u64 cookie;
|
|
} data;
|
|
|
|
data.pid = bpf_get_current_pid_tgid();
|
|
data.cookie = 0x12345678;
|
|
|
|
bpf_perf_event_output(ctx, &my_map, 0, &data, sizeof(data));
|
|
|
|
return 0;
|
|
}
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
u32 _version SEC("version") = LINUX_VERSION_CODE;
|