From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F05A38E5C0 for ; Thu, 26 Mar 2026 01:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.220.144.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774488807; cv=none; b=iPYOkz65jYmOXNc/jLCVstKWgKpgul/+HEQ5zYV/VH8iim/72gX0NAACzNSrlqIkGmiD6geX9XnQTgcB7s8NqjkCkTcaZ6X5shp2QJgyhaT8ioj2e6hXMwS+48NECFtP4/++msH1FO0B5RMWHUQCd4HivypNB9nZR9MWOlxrCpo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774488807; c=relaxed/simple; bh=wEoJ4qtF0gg2+89x6oXFOpRcBJcU6XuII/sHxSByq5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LcSzeCUxgaU9dJsV8krqwGMZ+eCYSwOngTxczcy1dCLX5vitP/7CfrHiFuPKIQ91f32Du9+uWYfoivqy9k8bkZNzEM7G6h7cMg/MA7y7qaBljb953fh5YKj4gjlQKDE7o8bTJra30rBT2UJThMHG9Evrv7mV5oa3AthFs3TptmA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev; spf=fail smtp.mailfrom=linux.dev; arc=none smtp.client-ip=66.220.144.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=linux.dev Received: by devvm16039.vll0.facebook.com (Postfix, from userid 128203) id EA78C2E281175; Wed, 25 Mar 2026 18:33:12 -0700 (PDT) From: Yonghong Song To: Alan Maguire , Arnaldo Carvalho de Melo , dwarves@vger.kernel.org Cc: Alexei Starovoitov , Andrii Nakryiko , bpf@vger.kernel.org, kernel-team@fb.com Subject: [PATCH dwarves v4 10/11] btf_encoder: Handle optimized parameter properly Date: Wed, 25 Mar 2026 18:33:12 -0700 Message-ID: <20260326013312.2912274-1-yonghong.song@linux.dev> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260326013144.2901265-1-yonghong.song@linux.dev> References: <20260326013144.2901265-1-yonghong.song@linux.dev> Precedence: bulk X-Mailing-List: dwarves@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Ensure to skip optimized parameter so btf can generate proper true signatures. In the first patch of the patch set, with DW_CC_nocall filtering, 875 fun= ctions have signature changed. With a series of improvement, eventually only 18 = functions remain and unfortunately these functions cannot be converted to true sign= atures due to locations. For example, 0x0242f1f7: DW_TAG_subprogram DW_AT_name ("memblock_find_in_range") DW_AT_calling_convention (DW_CC_nocall) DW_AT_type (0x0242decc "phys_addr_t") ... 0x0242f22e: DW_TAG_formal_parameter DW_AT_location (indexed (0x14a) loclist =3D 0x00= 5595bc: [0xffffffff87a000f9, 0xffffffff87a00178): DW_OP_reg5= RDI [0xffffffff87a00178, 0xffffffff87a001be): DW_OP_reg1= 4 R14 [0xffffffff87a001be, 0xffffffff87a001c7): DW_OP_entr= y_value(DW_OP_reg5 RDI), DW_OP_stack_value [0xffffffff87a001c7, 0xffffffff87a00214): DW_OP_reg1= 4 R14) DW_AT_name ("start") DW_AT_type (0x0242decc "phys_addr_t") ... 0x0242f239: DW_TAG_formal_parameter DW_AT_location (indexed (0x14b) loclist =3D 0x00= 5595e6: [0xffffffff87a000f9, 0xffffffff87a00175): DW_OP_reg4= RSI [0xffffffff87a00175, 0xffffffff87a001b8): DW_OP_reg3= RBX [0xffffffff87a001b8, 0xffffffff87a001c7): DW_OP_entr= y_value(DW_OP_reg4 RSI), DW_OP_stack_value [0xffffffff87a001c7, 0xffffffff87a00214): DW_OP_reg3= RBX) DW_AT_name ("end") DW_AT_type (0x0242decc "phys_addr_t") ... 0x0242f245: DW_TAG_formal_parameter DW_AT_location (indexed (0x14c) loclist =3D 0x00= 559610: [0xffffffff87a001e3, 0xffffffff87a001ef): DW_OP_breg= 4 RSI+0) DW_AT_name ("size") DW_AT_type (0x0242decc "phys_addr_t") ... 0x0242f250: DW_TAG_formal_parameter DW_AT_const_value (4096) DW_AT_name ("align") DW_AT_type (0x0242decc "phys_addr_t") ... The third parameter 'size' is not from RDX. Hence, true signature is not = possible for this function. I also did some experiments on arm64. The number of signature-changed fun= citons is 863 and finally there are 70 functions cannot be converted to true sig= natures. Through dwarf comparison of x86_64 vs. arm64, llvm arm64 backend looks li= ke having more relaxation to compute parameter values for those signature-changed f= unctions. Signed-off-by: Yonghong Song --- btf_encoder.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index d36984a..5632a60 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -1257,15 +1257,21 @@ static int32_t btf_encoder__save_func(struct btf_= encoder *encoder, struct functi struct btf *btf =3D encoder->btf; struct llvm_annotation *annot; struct parameter *param; - uint8_t param_idx =3D 0; + uint8_t param_idx =3D 0, skip_idx =3D 0; int str_off, err =3D 0; =20 if (!state) return -ENOMEM; =20 + if (encoder->true_signature && encoder->cu->producer_clang) { + ftype__for_each_parameter(ftype, param) { + if (param->optimized) skip_idx++; + } + } + state->addr =3D function__addr(fn); state->elf =3D func; - state->nr_parms =3D ftype->nr_parms + (ftype->unspec_parms ? 1 : 0); + state->nr_parms =3D ftype->nr_parms - skip_idx + (ftype->unspec_parms ?= 1 : 0); state->ret_type_id =3D ftype->tag.type =3D=3D 0 ? 0 : encoder->type_id_= off + ftype->tag.type; if (state->nr_parms > 0) { state->parms =3D zalloc(state->nr_parms * sizeof(*state->parms)); @@ -1297,14 +1303,34 @@ static int32_t btf_encoder__save_func(struct btf_= encoder *encoder, struct functi state->reordered_parm =3D ftype->reordered_parm; ftype__for_each_parameter(ftype, param) { const char *name; + char *final_name =3D NULL; =20 /* No location info/optimized + reordered means optimized out. */ if (ftype->reordered_parm && (!param->has_loc || param->optimized)) { state->nr_parms--; continue; } - name =3D parameter__name(param) ?: ""; + if (encoder->true_signature && encoder->cu->producer_clang && param->o= ptimized) + continue; + + name =3D parameter__name(param); + if (!name) { + name =3D ""; + } else if (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= ) =3D=3D -1) { + err =3D -ENOMEM; + goto out; + } + name =3D final_name; + } + str_off =3D btf__add_str(btf, name); + if (final_name) + free(final_name); + if (str_off < 0) { err =3D str_off; goto out; --=20 2.52.0