Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
elf_reader,btf: support multiple programs per ELF section
This patch adds support for emitting multiple eBPF functions/programs to the same ELF section. Significant changes were necessary, both to the BPF linker and the BTF ext_info parser, as previously most of the code (rightfully) made the assumption that one ELF section equaled one BPF function. In order to remove this limitation, all 'offset' logic that used to track positions within an ELF section had to be modified to track positions within a function body instead. Secondly, in order to reassemble instruction streams and BTF func_infos, line_infos and also CO-RE relocations back into a flat format the kernel expects, the linking logic had to be broken up into smaller pieces. This allows the instruction linker and the BTF extinfo linkers to operate on the same source of truth, so they can generate their outputs using the same program layout. Additionally, by computing references (which requires scanning all progs' instruction streams for references to other programs) only once during ELF loading, any marshaling logic can simply request the flattened program layout, saving cycles. To simplify the reference discovery process, the internal distinction between 'libs' and 'progs' has been eliminated. This allows any function to be called from anywhere, regardless of section name. For backwards compatibility reasons, programs of type UnspecifiedProgram are not yet emitted to the CollectionSpec. How we treat functions from .text and other unknown sections is still to be debated. From a high level, the linker is now split into multiple stages: - Finding references - a program's instruction stream is checked for references to any other program in the ELF. If a direct dependency is found (a jump to another function), a pointer to that function is stored in the program's reference list. - Flattening - when the program is about to be marshaled for hand-off to the kernel, a unique, flat list of dependent programs is generated by stepping through each program's reference list in a depth-first manner. This list must be used by both the instruction and BTF extinfo linkers, so they generate their outputs using the same layout. - Marshaling - the flat list of programs is simply iterated over and its instructions and BTF extinfo's are marshaled to their respective output buffers. Signed-off-by: Timo Beckers <timo@isovalent.com>
- Loading branch information
Showing
14 changed files
with
786 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.