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 (ftype->signature_changed && 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 "__" so the BTF reflects the value actually passed in the register. Signed-off-by: Yonghong Song --- btf_encoder.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/btf_encoder.c b/btf_encoder.c index d5af706..38455a4 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 && ftype->signature_changed && param->optimized) { + state->nr_parms--; + continue; + } + + name = parameter__name(param); + if (!name) { + name = ""; + } else if (encoder->true_signature && + ftype->signature_changed && + param->true_sig_member_name) { + /* Non-null param->true_sig_member_name indicates that the parameter + * name is __. + */ + 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; -- 2.53.0-Meta