diff options
author | Alexei Starovoitov <ast@kernel.org> | 2021-03-19 02:14:23 +0300 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2021-03-19 02:14:23 +0300 |
commit | 6d8b271682e2e0ff6a793c76803a5506b5535a5a (patch) | |
tree | 72d416410a0f4f26e673324551acb8a97e342969 /tools/lib/bpf/btf.h | |
parent | fdc13979f91e664717f47eb8c49094e4b7f202e3 (diff) | |
parent | a0964f526df6facd4e12a4c416185013026eecf9 (diff) | |
download | linux-6d8b271682e2e0ff6a793c76803a5506b5535a5a.tar.xz |
Merge branch 'BPF static linking'
Andrii Nakryiko says:
====================
This patch set adds new libbpf APIs and their bpftool integration that allows
to perform static linking of BPF object files. Currently no extern resolution
across object files is performed. This is going to be the focus of the follow
up patches. But, given amount of code and logic necessary to perform just
basic functionality of linking together mostly independent BPF object files,
it was decided to land basic BPF linker code and logic first and extend it
afterwards.
The motivation for BPF static linking is to provide the functionality that is
naturally assumed for user-space development process: ability to structure
application's code without artificial restrictions of having all the code and
data (variables and maps) inside a single source code file.
This enables better engineering practices of splitting code into
well-encapsulated parts. It provides ability to hide internal state from other
parts of the code base through static variables and maps. It is also a first
steps towards having generic reusable BPF libraries.
Please see individual patches (mostly #6 and #7) for more details. Patch #10
passes all test_progs' individual BPF .o files through BPF static linker,
which is supposed to be a no-op operation, so is essentially validating that
BPF static linker doesn't produce corrupted ELF object files. Patch #11 adds
Makefile infra to be able to specify multi-file BPF object files and adds the
first multi-file test to validate correctness.
v3->v4:
- fix Makefile copy/paste error of diff'ing invalid object files (Alexei);
- fix uninitialized obj_name variable that could lead to bogus object names
being used during skeleton generation (kernel-patches CI);
v2->v3:
- added F(F(F(X))) = F(F(X)) test for all linked BPF object files (Alexei);
- used reallocarray() more consistently in few places (Alexei);
- improved bash completions for `gen object` (Quentin);
- dropped .bpfo extension, but had to add optional `name OBJECT_FILE`
parameter (path #8) to `gen skeleton` command to specify desired object
name during skeleton generation;
- fixed bug of merging DATASECS of special "license" and "version" sections.
Linker currently strictly validates that all versions and licenses matches
exactly and keeps only ELF symbols and BTF DATASEC from the very first
object file with license/version. For all other object files, we ignore
ELF symbols, but weren't ignoring DATASECs, which caused further problems
of not being able to find a corresponding ELF symbol, if variable name
differs between two files (which we test deliberately in multi-file
linking selftest). The fix is to ignore BTF DATASECS;
v1->v2:
- extracted `struct strset` to manage unique set of strings both for BTF and
ELF SYMTAB (patch #4, refactors btf and btf_dedup logic as well) (Alexei);
- fixed bugs in bpftool gen command; renamed it to `gen object`, added BASH
completions and extended/updated man page (Quentin).
====================
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf/btf.h')
-rw-r--r-- | tools/lib/bpf/btf.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 029a9cfc8c2d..3b0b17ba94a1 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -93,6 +93,8 @@ LIBBPF_API struct btf *libbpf_find_kernel_btf(void); LIBBPF_API int btf__find_str(struct btf *btf, const char *s); LIBBPF_API int btf__add_str(struct btf *btf, const char *s); +LIBBPF_API int btf__add_type(struct btf *btf, const struct btf *src_btf, + const struct btf_type *src_type); LIBBPF_API int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding); LIBBPF_API int btf__add_float(struct btf *btf, const char *name, size_t byte_sz); |