Re: [PATCH dwarves v8 4/5] btf_encoder: Emit true function signatures

Yonghong Song <[email protected]> Tue, 23 Jun 2026 18:45:17 -0700
Newsgroups org.kernel.vger.dwarves,org.kernel.vger.bpf
Message-ID <[email protected]>

On 6/23/26 3:29 PM, Yonghong Song wrote:
> When true_signature is enabled, consume the per-parameter analysis the
> DWARF loader recorded while saving a function's BTF:
>   - Drop parameters that were optimized out of a signature-changed function
>     (cu->producer_clang && param->optimized), adjusting the saved
>     parameter count accordingly.
>   - When a parameter was reduced to a single aggregate member
>     (param->true_sig_member_name is set), emit it under the synthesized name
>     "<parameter>__<member>" so the BTF reflects the value actually passed in
>     the register.
>
> Signed-off-by: Yonghong Song <[email protected]>
> ---
>   btf_encoder.c | 26 +++++++++++++++++++++++++-
>   1 file changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/btf_encoder.c b/btf_encoder.c
> index d5af706..eb6ccaa 100644
> --- a/btf_encoder.c
> +++ b/btf_encoder.c
> @@ -1297,14 +1297,38 @@ static int32_t btf_encoder__save_func(struct btf_encoder *encoder, struct functi
>   	state->reordered_parm = ftype->reordered_parm;
>   	ftype__for_each_parameter(ftype, param) {
>   		const char *name;
> +		char *final_name = NULL;
>   
>   		/* No location info/optimized + reordered means optimized out. */
>   		if (ftype->reordered_parm && (!param->has_loc || param->optimized)) {
>   			state->nr_parms--;
>   			continue;
>   		}
> -		name = parameter__name(param) ?: "";
> +		if (encoder->true_signature && encoder->cu->producer_clang && param->optimized) {
> +			state->nr_parms--;
> +			continue;
> +		}
> +
> +		name = parameter__name(param);
> +		if (!name) {
> +			name = "";
> +		} else if (encoder->true_signature &&
> +			   encoder->cu->producer_clang &&
> +			   param->true_sig_member_name) {
> +			/* Non-null param->true_sig_member_name indicates that the parameter
> +			 * name is <parameter_name>__<field_name>.
> +			 */
> +			if (asprintf(&final_name, "%s__%s", name, param->true_sig_member_name) == -1) {
> +				err = -ENOMEM;
> +				goto out;
> +			}
> +			name = final_name;
> +		}
> +
>   		str_off = btf__add_str(btf, name);
> +		if (final_name)
> +			free(final_name);
> +
>   		if (str_off < 0) {
>   			err = str_off;
>   			goto out;

FindĀ another issue in this file, not related to the above.
Just give a simple example for

static inline void io_file_bitmap_set(struct io_file_table *table, int bit)
{
         WARN_ON_ONCE(test_bit(bit, table->bitmap));
         __set_bit(bit, table->bitmap);
         table->alloc_hint = bit + 1;
}

It is in a header file io_uring/filetable.h.

We have inlined subprogram:

0x04fb6857:   DW_TAG_subprogram
                 DW_AT_name      ("io_file_bitmap_set")
                 DW_AT_decl_file ("/home/yhs/work/bpf-next/io_uring/filetable.h")
                 DW_AT_decl_line (29)
                 DW_AT_prototyped        (true)
                 DW_AT_inline    (DW_INL_inlined)
                       
0x04fb685c:     DW_TAG_formal_parameter
                   DW_AT_name    ("table")
                   DW_AT_decl_file       ("/home/yhs/work/bpf-next/io_uring/filetable.h")
                   DW_AT_decl_line       (29)
                   DW_AT_type    (0x04fb6885 "io_file_table *")
                            
0x04fb6865:     DW_TAG_formal_parameter
                   DW_AT_name    ("bit")
                   DW_AT_decl_file       ("/home/yhs/work/bpf-next/io_uring/filetable.h")
                   DW_AT_decl_line       (29)
                   DW_AT_type    (0x04fa5103 "int")

and

0x04fb77d8:   DW_TAG_subprogram
                 DW_AT_low_pc    (0xffffffff8273d430)
                 DW_AT_high_pc   (0xffffffff8273d50c)
                 DW_AT_frame_base        (DW_OP_reg7 RSP)
                 DW_AT_call_all_calls    (true)
                 DW_AT_abstract_origin   (0x04fb6857 "io_file_bitmap_set")
                   
0x04fb77e5:     DW_TAG_formal_parameter
                   DW_AT_location        (indexed (0x11f) loclist = 0x00d4bcf7:
                      [0xffffffff8273d430, 0xffffffff8273d45c): DW_OP_reg5 RDI
                      [0xffffffff8273d45c, 0xffffffff8273d4c3): DW_OP_reg3 RBX
                      [0xffffffff8273d4c3, 0xffffffff8273d4e6): DW_OP_entry_value(DW_OP_reg5 RDI), DW_OP_stack_value
                      [0xffffffff8273d4e6, 0xffffffff8273d4f6): DW_OP_reg3 RBX
                      [0xffffffff8273d4f6, 0xffffffff8273d50c): DW_OP_entry_value(DW_OP_reg5 RDI), DW_OP_stack_value)
                   DW_AT_abstract_origin (0x04fb685c "table")
                   
0x04fb77ec:     DW_TAG_formal_parameter
                   DW_AT_location        (indexed (0x120) loclist = 0x00d4bd23:
                      [0xffffffff8273d430, 0xffffffff8273d464): DW_OP_reg4 RSI
                      [0xffffffff8273d464, 0xffffffff8273d50c): DW_OP_entry_value(DW_OP_reg4 RSI), DW_OP_stack_value)
                   DW_AT_abstract_origin (0x04fb6865 "bit")

0x04ff5f5e:   DW_TAG_subprogram
                 DW_AT_name      ("io_file_bitmap_set")
                 DW_AT_decl_file ("/home/yhs/work/bpf-next/io_uring/filetable.h")
                 DW_AT_decl_line (29)
                 DW_AT_prototyped        (true)
                 DW_AT_inline    (DW_INL_inlined)
                      
0x04ff5f63:     DW_TAG_formal_parameter
                   DW_AT_name    ("table")
                   DW_AT_decl_file       ("/home/yhs/work/bpf-next/io_uring/filetable.h")
                   DW_AT_decl_line       (29)
                   DW_AT_type    (0x04ff5f59 "io_file_table *")

0x04ff5f6c:     DW_TAG_formal_parameter
                   DW_AT_name    ("bit")
                   DW_AT_decl_file       ("/home/yhs/work/bpf-next/io_uring/filetable.h")
                   DW_AT_decl_line       (29)
                   DW_AT_type    (0x04fe77c6 "int")

I get the following error:

+io_file_bitmap_set : skipping BTF encoding of function due to param count mismatch; 2 params != 0 params
+io_file_bitmap_set : skipping BTF encoding of function due to inconsistet prototype

How do we resolve the issue like this?

If this is hard, we can try to resolve as a follow-up.