Skip to content

Commit d4680a1

Browse files
arighiAlexei Starovoitov
authored andcommitted
bpf: Mark kfuncs as __noclone
Some distributions (e.g., CachyOS) support building the kernel with -O3, but doing so may break kfuncs, resulting in their symbols not being properly exported. In fact, with gcc -O3, some kfuncs may be optimized away despite being annotated as noinline. This happens because gcc can still clone the function during IPA optimizations, e.g., by duplicating or inlining it into callers, and then dropping the standalone symbol. This breaks BTF ID resolution since resolve_btfids relies on the presence of a global symbol for each kfunc. Currently, this is not an issue for upstream, because we don't allow building the kernel with -O3, but it may be safer to address it anyway, to prevent potential issues in the future if compilers become more aggressive with optimizations. Therefore, add __noclone to __bpf_kfunc to ensure kfuncs are never cloned and remain distinct, globally visible symbols, regardless of the optimization level. Fixes: 57e7c16 ("bpf: Add __bpf_kfunc tag for marking kernel functions as kfuncs") Acked-by: David Vernet <[email protected]> Acked-by: Yonghong Song <[email protected]> Signed-off-by: Andrea Righi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent ceeaa71 commit d4680a1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/linux/btf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
* as to avoid issues such as the compiler inlining or eliding either a static
8787
* kfunc, or a global kfunc in an LTO build.
8888
*/
89-
#define __bpf_kfunc __used __retain noinline
89+
#define __bpf_kfunc __used __retain __noclone noinline
9090

9191
#define __bpf_kfunc_start_defs() \
9292
__diag_push(); \

0 commit comments

Comments
 (0)