This series adds support to libbpf for relocating references to 32-bit static data inside ELF files, both for .data and .bss, similar to one of the approaches proposed in LPC 2018[0]. This improves a common workflow for BPF users, where the BPF program may be customised each time it is loaded, for example to tailor IP addresses for each instance of the loaded program. Current approaches require full recompilation of the programs for each load, however with templatized BPF programs, one ELF template program may be generated, then the static data can be easily substituted prior to loading into the kernel without invoking the compiler again.
The approach here is useful for templating limited static data for ELF programs, and will work regardless of kernel support for static data sections. Its main limitation is that static data must be defined as 32-bit values in the BPF C input code (or defined using macros that use 32-bit values as the underlying store). The alternative approach proposed at LPC would be more general and is being actively explored, however it requires kernel extension and so will not solve this problem for any existing kernels that are in use today. There are similar patches floating around for iproute2 which I would like to upstream as well[1]. [0] https://linuxplumbersconf.org/event/2/contributions/115/ [1] https://github.com/joestringer/iproute2/tree/bss Joe Stringer (4): libbpf: Refactor relocations libbpf: Support 32-bit static data loads libbpf: Support relocations for bss. selftests/bpf: Test static data relocation tools/lib/bpf/libbpf.c | 108 ++++++++++++------ tools/testing/selftests/bpf/Makefile | 2 +- tools/testing/selftests/bpf/test_progs.c | 44 +++++++ .../selftests/bpf/test_static_data_kern.c | 47 ++++++++ 4 files changed, 168 insertions(+), 33 deletions(-) create mode 100644 tools/testing/selftests/bpf/test_static_data_kern.c -- 2.19.1