A python program which explains the helpers, which, by default, pulls info from linux-4.19.39/include/uapi/linux/bpf.h:
./linux-4.19.39/scripts/bpf_helpers_doc.py
A refined clang invocation to build an ebpf kernel load:
clang \ -I /usr/include/x86_64-linux-gnu \ -I linux-4.19.39 \ -I /usr/src/linux-headers-4.19.0-5-common/include \ -O2 -target bpf -c sock_kern.c -o sock_kern.o
A refined clang invocation of the userland loader, which should run the samples in linux-4.19.39/samples/bpf/:
SRC=linux-4.19.39 \ LIB=${SRC}/tools/lib/bpf/libbpf.a \ clang \ -I ${SRC}/tools/lib/bpf \ -I ${SRC}/tools/lib \ -I ${SRC}/tools/include \ -I ${SRC}/tools/perf \ -I ${SRC}/samples \ -I linux-5.2.7/tools/include \ -O2 -Wall -g \ -o sock_user \ ${LIB} -lelf \ sock_user.c ${SRC}/samples/bpf/bpf_load.c
On Debian, rather than loading the libbpf package it can be build from the kernel source to obtain libbpf.a:
# cd linux-4.19.39/tools/lib/bpf # make Auto-detecting system features: ... libelf: [ on ] ... bpf: [ on ] HOSTCC fixdep.o HOSTLD fixdep-in.o LINK fixdep CC libbpf.o CC bpf.o CC nlattr.o CC btf.o CC libbpf_errno.o CC str_error.o LD libbpf-in.o LINK libbpf.a LINK libbpf.so
It should be possible to do the same with linux-4.19.38/tools/bpf/bpftool, but fails on a missing bfd.h. But does work on linux-5.2.7/tools/bpf/bpftool.
'bpftool feature' will provide the features available in the current kernel. bpftool also has a bash completion file.
Some other bpftool invocations:
/bpftool feature ./bpftool map show sudo apt install jq ./bpftool prog show --json id 52 | jq -c '[.id, .type, .loaded_at]' # makes some things faster: echo 1 > /proc/sys/net/core/bpf_jit_enable