-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
{elf_reader,linker}: Add support for weak kfuncs
This commit allows users to mark their kfunc defintions as `__weak`. Weak kfuncs do not cause an error during loading if the kfunc in question can't be found. Instead, a poison value is written which will cause the verifier to bail out if the instruction is evaluated. In addition, this commit relocates LDIMM64 instructions with kfunc relocation entries. When relocated, the BTF id of the kfunc is written to the instruction's immediate field. Together these two changes allow users to write eBPF programs which can gracefully handle the absence of a kfunc. To do so the `bpf_ksym_exists` macro from `bpf_helpers.h` can be used to check if a kfunc is present. ``` void invalid_kfunc(void) __ksym __weak; __section("tp_btf/task_newtask") int weak_kfunc_missing(void *ctx) { if (bpf_ksym_exists(invalid_kfunc)) { invalid_kfunc(); return 0; } return 1; } ``` In this example the kfunc is always invalid, yet the program can still load since the branch calling the kfunc is unreachable. So this effectively provides CO-RE capabilities for kfuncs. Especially important since kfuncs are less stable than helpers, their availability depending on kernel version, kernel compilation flags, or kernel modules being loaded or not. Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
- Loading branch information
1 parent
607a1cd
commit 42cbe8f
Showing
7 changed files
with
122 additions
and
13 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
Binary file not shown.
Binary file not shown.
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