In the quest for ever more modularity, a new need has arisen - the ability to access data associated with a BPF library from a corresponding userspace library. The catch is that we don't want the userspace library to know about the structure of the final BPF object that the BPF library is linked into. In pursuit of this modularity, this patch series introduces *subskeletons.* Subskeletons are similar in use and design to skeletons with a couple of differences: 1. The generated storage types do not rely on contiguous storage for the library's variables because they may be interspersed randomly throughout the final BPF object's sections. 2. Subskeletons do not own objects and instead require a loaded bpf_object* to be passed at runtime in order to be initialized. By extension, symbols are resolved at runtime by parsing the final object's BTF. This has the interesting effect that the same userspace code can interoperate with the library BPF code *linked into different final objects.* 3. Currently, only globals are supported though the codegen can be extended to support non-owning pointers to maps, progs, links, etc. Areas that are RFC/TODO: * AFAICT, the ELF section names are the only way to find the correct maps in the final linked object. As a result, I've added bpf_map__section_name so bpftool can use the section names in the codegen. Do let me know if there's a better design I'm missing. * The bpf_object__{open,destroy}_subskeleton approach mirrors the corresponding skeleton support functionality. Do let me know if there's anything that needs to exist in it to ensure forward compatibility. (Unfortunately, I don't see any way for subskeletons to work with older libbpf versions, so I'd rather introduce all the new APIs they may need in a single version.) Delyan Kratunov (4): libbpf: expose map elf section name bpftool: add support for subskeletons libbpf: add subskeleton scaffolding selftests/bpf: test subskeleton functionality tools/bpf/bpftool/gen.c | 322 +++++++++++++++++- tools/lib/bpf/libbpf.c | 84 +++++ tools/lib/bpf/libbpf.h | 23 ++ tools/lib/bpf/libbpf.map | 7 + tools/lib/bpf/libbpf_version.h | 2 +- tools/testing/selftests/bpf/Makefile | 18 +- .../selftests/bpf/prog_tests/subskeleton.c | 38 +++ .../bpf/prog_tests/subskeleton_lib.c | 29 ++ .../selftests/bpf/progs/test_subskeleton.c | 20 ++ .../bpf/progs/test_subskeleton_lib.c | 22 ++ 10 files changed, 553 insertions(+), 12 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/subskeleton.c create mode 100644 tools/testing/selftests/bpf/prog_tests/subskeleton_lib.c create mode 100644 tools/testing/selftests/bpf/progs/test_subskeleton.c create mode 100644 tools/testing/selftests/bpf/progs/test_subskeleton_lib.c -- 2.34.1