I wrote a BPF object file which included a section and a static inlined function, which defined as below:
static inline __attribute__((always_inline)) bpf_call_func(...);
__section("entry") bpf_func(...); // called bpf_call_func
It worked well and when I used llvm-objdump, it showed that bpf_call_func
has already been inlined.
But when I defined another ection in the same object file, also called bpf_call_func
static inline __attribute__((always_inline)) bpf_call_func(...);
__section("entry") bpf_func(...); // called bpf_call_func
__section("entry2") bpf_func2(...); // called bpf_call_func
llvm-objdump showed bpf_call_func
didn't inlined in neither bpf_func
nor bpf_func2
. It just defined in the .text
section, and bpf_func
and bpf_func2
used call
instruction to call bpf_call_func
.
The bpf_call_func
is about 600 instructions. The bpf_func
and bpf_func
are about 250 instructions.
I viewed gcc manual, it says:
Note that certain usages in a function definition can make it unsuitable for inline substitution. Among these usages are: variadic functions, use of alloca, use of computed goto (see Labels as Values), use of nonlocal goto, use of nested functions, use of setjmp, use of __builtin_longjmp and use of __builtin_return or __builtin_apply_args. Using -Winline warns when a function marked inline could not be substituted, and gives the reason for the failure.
But I didn't know which situations match my case.
I wonder to know why doesn't the bpf_call_func
inline when there are two sections call it?
Is it related to bpf_call_func
's instructions' number?