Skip to content
Snippets Groups Projects
Commit 6d8b2716 authored by Alexei Starovoitov's avatar Alexei Starovoitov
Browse files

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: default avatarAlexei Starovoitov <ast@kernel.org>
parents fdc13979 a0964f52
No related branches found
No related tags found
No related merge requests found
Showing
with 2806 additions and 424 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment