linux-stable/tools
Andrii Nakryiko 4a3b33f857 libbpf: Add BTF writing APIs
Add APIs for appending new BTF types at the end of BTF object.

Each BTF kind has either one API of the form btf__add_<kind>(). For types
that have variable amount of additional items (struct/union, enum, func_proto,
datasec), additional API is provided to emit each such item. E.g., for
emitting a struct, one would use the following sequence of API calls:

btf__add_struct(...);
btf__add_field(...);
...
btf__add_field(...);

Each btf__add_field() will ensure that the last BTF type is of STRUCT or
UNION kind and will automatically increment that type's vlen field.

All the strings are provided as C strings (const char *), not a string offset.
This significantly improves usability of BTF writer APIs. All such strings
will be automatically appended to string section or existing string will be
re-used, if such string was already added previously.

Each API attempts to do all the reasonable validations, like enforcing
non-empty names for entities with required names, proper value bounds, various
bit offset restrictions, etc.

Type ID validation is minimal because it's possible to emit a type that refers
to type that will be emitted later, so libbpf has no way to enforce such
cases. User must be careful to properly emit all the necessary types and
specify type IDs that will be valid in the finally generated BTF.

Each of btf__add_<kind>() APIs return new type ID on success or negative
value on error. APIs like btf__add_field() that emit additional items
return zero on success and negative value on error.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200929020533.711288-2-andriin@fb.com
2020-09-28 19:17:13 -07:00
..
accounting
arch tools headers kvm s390: Sync headers with the kernel sources 2020-08-12 08:52:32 -03:00
bootconfig tools/bootconfig: Add testcases for value override operator 2020-08-03 16:22:29 -04:00
bpf Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2020-09-23 13:11:11 -07:00
build tools, bpf/build: Cleanup feature files on make clean 2020-08-28 14:04:27 +02:00
cgroup tools/cgroup: add memcg_slabinfo.py tool 2020-08-07 11:33:25 -07:00
debugging
edid
firewire
firmware
gpio tools: gpio: fix spurious close warning in gpio-event-mon 2020-07-12 10:22:01 +02:00
hv tools: hv: change http to https in hv_kvp_daemon.c 2020-07-06 10:46:23 +00:00
iio
include bpf: Add bpf_seq_printf_btf helper 2020-09-28 18:26:58 -07:00
io_uring tools/io_uring: fix compile breakage 2020-09-21 07:50:58 -06:00
kvm/kvm_stat
laptop
leds
lib libbpf: Add BTF writing APIs 2020-09-28 19:17:13 -07:00
memory-model These were the main changes in this cycle: 2020-08-03 14:39:35 -07:00
nfsd
objtool objtool: Fix noreturn detection for ignored functions 2020-09-18 19:37:51 +02:00
pci
pcmcia
perf Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2020-09-23 13:11:11 -07:00
power ACPI updates for 5.9-rc1 2020-08-03 20:37:22 -07:00
scripts
spi
testing selftests/bpf: Add test for bpf_seq_printf_btf helper 2020-09-28 18:26:58 -07:00
thermal/tmon
time
usb tools: usb: move to tools buildsystem 2020-08-19 14:11:44 +02:00
virtio virtio: fixes, features 2020-08-11 14:34:17 -07:00
vm
wmi
Makefile bpf: Compile resolve_btfids tool at kernel compilation start 2020-07-13 10:42:02 -07:00