From patchwork Fri Mar 10 14:50:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 13169392 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68CAFC64EC4 for ; Fri, 10 Mar 2023 14:58:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233513AbjCJO6y (ORCPT ); Fri, 10 Mar 2023 09:58:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233525AbjCJO63 (ORCPT ); Fri, 10 Mar 2023 09:58:29 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D0E31B543 for ; Fri, 10 Mar 2023 06:53:08 -0800 (PST) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32AAmAW1026414; Fri, 10 Mar 2023 14:50:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=NKYzB1fXBT6kd3GjEcb3Yosl5mmtOzFl2r0oPTbs7iA=; b=tgjbwjx3y/hUsaOfLzmx1dh6Mz7iGnLlpz59o4xDlLPX9B2wLzDtjMlaLMAPUiWP/pD/ o77jEZysFbW095JaHyoH/zsOHKChFBsCPWE+Li+tmCw9Z560ok6/RhZIjWm5StPJBfrM IyHGyK49dftXKn5/ADk9nWLmRHxQjtSrsHz6m+u15gDnAWxDb/pv8VdHyUJl517xcqp0 KRIwXcAcCb2bMASut0leFYVOA+dL5fm1m4zYxMA8LcVeGfqwPf7a4o6YZhy5ODc4s2OZ DgreQfP1sV3NFES7dhK1e4CC6mcc0TAfAM49oMYPN5bKtha6DUv4sqVQ2ZOh9lQyRtne XA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p415j5g9q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Mar 2023 14:50:59 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32ADuVdV020762; Fri, 10 Mar 2023 14:50:58 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3p6fub0du7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Mar 2023 14:50:58 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 32AEosCN013152; Fri, 10 Mar 2023 14:50:57 GMT Received: from myrouter.uk.oracle.com (dhcp-10-175-184-199.vpn.oracle.com [10.175.184.199]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3p6fub0dkf-2; Fri, 10 Mar 2023 14:50:57 +0000 From: Alan Maguire To: acme@kernel.org Cc: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, eddyz87@gmail.com, haoluo@google.com, jolsa@kernel.org, john.fastabend@gmail.com, kpsingh@chromium.org, sinquersw@gmail.com, martin.lau@kernel.org, songliubraving@fb.com, sdf@google.com, timo@incline.eu, yhs@fb.com, bpf@vger.kernel.org, Alan Maguire Subject: [PATCH dwarves 1/3] dwarves_fprintf: generalize function prototype print to support passing conf Date: Fri, 10 Mar 2023 14:50:48 +0000 Message-Id: <1678459850-16140-2-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678459850-16140-1-git-send-email-alan.maguire@oracle.com> References: <1678459850-16140-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-10_06,2023-03-10_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303100121 X-Proofpoint-GUID: PfHB2J8n_8wVyDs_ljZxTAv4dM6nkVa3 X-Proofpoint-ORIG-GUID: PfHB2J8n_8wVyDs_ljZxTAv4dM6nkVa3 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org function__prototype() writes the function prototype to the passed-in buffer, but uses the default conf_fprint structure which prints parameter names. Generalize into function__prototype_conf() so that callers can pass in their own conf_fprintf; this will be useful for generating prototype strings for type matching. Signed-off-by: Alan Maguire --- dwarves.h | 5 +++++ dwarves_fprintf.c | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/dwarves.h b/dwarves.h index e92b2fd..d04a36d 100644 --- a/dwarves.h +++ b/dwarves.h @@ -133,6 +133,7 @@ struct conf_fprintf { uint8_t hex_fmt:1; uint8_t strip_inline:1; uint8_t skip_emitting_atomic_typedefs:1; + uint8_t skip_emitting_errors:1; }; struct cus; @@ -944,6 +945,10 @@ size_t function__fprintf_stats(const struct tag *tag_func, FILE *fp); const char *function__prototype(const struct function *func, const struct cu *cu, char *bf, size_t len); +const char *function__prototype_conf(const struct function *func, + const struct cu *cu, + const struct conf_fprintf *conf, + char *bf, size_t len); static __pure inline uint64_t function__addr(const struct function *func) { diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c index 30355b4..5c6bf9c 100644 --- a/dwarves_fprintf.c +++ b/dwarves_fprintf.c @@ -1102,21 +1102,33 @@ static size_t union__fprintf(struct type *type, const struct cu *cu, conf->suffix ? " " : "", conf->suffix ?: ""); } -const char *function__prototype(const struct function *func, - const struct cu *cu, char *bf, size_t len) +const char *function__prototype_conf(const struct function *func, + const struct cu *cu, + const struct conf_fprintf *conf, + char *bf, size_t len) { FILE *bfp = fmemopen(bf, len, "w"); if (bfp != NULL) { - ftype__fprintf(&func->proto, cu, NULL, 0, 0, 0, true, - &conf_fprintf__defaults, bfp); + ftype__fprintf(&func->proto, cu, NULL, 0, 0, 0, true, conf, + bfp); fclose(bfp); - } else + } else { + if (conf->skip_emitting_errors) + return NULL; snprintf(bf, len, "", __func__); + } return bf; } +const char *function__prototype(const struct function *func, + const struct cu *cu, char *bf, size_t len) +{ + return function__prototype_conf(func, cu, &conf_fprintf__defaults, + bf, len); +} + size_t ftype__fprintf_parms(const struct ftype *ftype, const struct cu *cu, int indent, const struct conf_fprintf *conf, FILE *fp) From patchwork Fri Mar 10 14:50:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 13169606 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12C77C64EC4 for ; Fri, 10 Mar 2023 16:35:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229844AbjCJQfp (ORCPT ); Fri, 10 Mar 2023 11:35:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbjCJQe0 (ORCPT ); Fri, 10 Mar 2023 11:34:26 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A459F0FFF for ; Fri, 10 Mar 2023 08:31:54 -0800 (PST) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32AAUZnd026354; Fri, 10 Mar 2023 14:51:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=lXjADzX0pkKJ77jDK0QzWuYsZ1iNQwL3vdiKcdaQxBU=; b=08fvTak57n6xVRY0hLOrhF638wUbmZhKRAgrmFfZLsRp47nYIPlRbh5n4ipE7hkVQd77 O/Yv5+3eBX6Xpgz14d2cNq3moG7EKVGtvcjZMxo7+CewYBTGHoMZK/QwYDNzL8B729Bh 6d0NdoUAsF8jfGzIdry5Hpkan4XoCFGgDI/1WEpSVSsoG6TiAirvOSvz3id14x5B95z0 tElov+ilAiUWRuDk+W4LLcLf7ujThO64HzTkmL+BSnALaBNqPbvFxR926ckTZPyhitm5 hHsZMWKGSnYt6BOIZrnJAVTmDrC5fkcVfPX2uX4t2iXO4K9rLdhHlO/e5sDdpiyTbw5b 6w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p415j5g9w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Mar 2023 14:51:03 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32AEMSss021509; Fri, 10 Mar 2023 14:51:02 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3p6fub0dxd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Mar 2023 14:51:02 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 32AEosCP013152; Fri, 10 Mar 2023 14:51:01 GMT Received: from myrouter.uk.oracle.com (dhcp-10-175-184-199.vpn.oracle.com [10.175.184.199]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3p6fub0dkf-3; Fri, 10 Mar 2023 14:51:01 +0000 From: Alan Maguire To: acme@kernel.org Cc: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, eddyz87@gmail.com, haoluo@google.com, jolsa@kernel.org, john.fastabend@gmail.com, kpsingh@chromium.org, sinquersw@gmail.com, martin.lau@kernel.org, songliubraving@fb.com, sdf@google.com, timo@incline.eu, yhs@fb.com, bpf@vger.kernel.org, Alan Maguire Subject: [PATCH dwarves 2/3] dwarves_fprintf: support skipping modifier Date: Fri, 10 Mar 2023 14:50:49 +0000 Message-Id: <1678459850-16140-3-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678459850-16140-1-git-send-email-alan.maguire@oracle.com> References: <1678459850-16140-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-10_06,2023-03-10_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303100121 X-Proofpoint-GUID: LbenSbZLSmk0PcaoFKeq7OSfynuWJWlD X-Proofpoint-ORIG-GUID: LbenSbZLSmk0PcaoFKeq7OSfynuWJWlD Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org When doing BTF comparisons between functions defined in multiple CUs, it was noticed a few critical functions failed prototype comparisons due to multiple "const" modifiers; for example: function mismatch for 'memchr_inv'('memchr_inv'): 'void * ()(const const void * , int, size_t)' != 'void * ()(const void *, int, size_t)' function mismatch for 'strnlen'('strnlen'): '__kernel_size_t ()(const const char * , __kernel_size_t)' != '__kernel_size_t ()(const char *, size_t)' (note the "const const" in the first parameter.) As such it would be useful to omit modifiers for comparison purposes. Also noted was the fact that for the "no_parm_names" case, an extra space was being emitted in some cases, also throwing off string comparisons of prototypes. Signed-off-by: Alan Maguire --- dwarves.h | 1 + dwarves_fprintf.c | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/dwarves.h b/dwarves.h index d04a36d..7a319d1 100644 --- a/dwarves.h +++ b/dwarves.h @@ -134,6 +134,7 @@ struct conf_fprintf { uint8_t strip_inline:1; uint8_t skip_emitting_atomic_typedefs:1; uint8_t skip_emitting_errors:1; + uint8_t skip_emitting_modifier:1; }; struct cus; diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c index 5c6bf9c..b20a473 100644 --- a/dwarves_fprintf.c +++ b/dwarves_fprintf.c @@ -506,7 +506,8 @@ static const char *tag__ptr_name(const struct tag *tag, const struct cu *cu, struct tag *next_type = cu__type(cu, type->type); if (next_type && tag__is_pointer(next_type)) { - const_pointer = "const "; + if (!conf->skip_emitting_modifier) + const_pointer = "const "; type = next_type; } } @@ -580,13 +581,16 @@ static const char *__tag__name(const struct tag *tag, const struct cu *cu, *type_str = __tag__name(type, cu, tmpbf, sizeof(tmpbf), pconf); - switch (tag->tag) { - case DW_TAG_volatile_type: prefix = "volatile "; break; - case DW_TAG_const_type: prefix = "const "; break; - case DW_TAG_restrict_type: suffix = " restrict"; break; - case DW_TAG_atomic_type: prefix = "_Atomic "; break; + if (!conf->skip_emitting_modifier) { + switch (tag->tag) { + case DW_TAG_volatile_type: prefix = "volatile "; break; + case DW_TAG_const_type: prefix = "const"; break; + case DW_TAG_restrict_type: suffix = " restrict"; break; + case DW_TAG_atomic_type: prefix = "_Atomic "; break; + } } - snprintf(bf, len, "%s%s%s ", prefix, type_str, suffix); + snprintf(bf, len, "%s%s%s%s", prefix, type_str, suffix, + conf->no_parm_names ? "" : " "); } break; case DW_TAG_array_type: @@ -818,9 +822,11 @@ print_default: case DW_TAG_const_type: modifier = "const"; print_modifier: { - size_t modifier_printed = fprintf(fp, "%s ", modifier); - tconf.type_spacing -= modifier_printed; - printed += modifier_printed; + if (!conf->skip_emitting_modifier) { + size_t modifier_printed = fprintf(fp, "%s ", modifier); + tconf.type_spacing -= modifier_printed; + printed += modifier_printed; + } struct tag *ttype = cu__type(cu, type->type); if (ttype) { From patchwork Fri Mar 10 14:50:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 13169428 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C9DAC6FD1F for ; Fri, 10 Mar 2023 15:43:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231211AbjCJPnE (ORCPT ); Fri, 10 Mar 2023 10:43:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234246AbjCJPmf (ORCPT ); Fri, 10 Mar 2023 10:42:35 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C639B14DA0B for ; Fri, 10 Mar 2023 07:29:26 -0800 (PST) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32AAsR5J008483; Fri, 10 Mar 2023 14:51:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=CGvSUrhfZOFum3e8EAeCRT1YAnPgrEAcp0iauA/dqWc=; b=VPrO/IRnqmhnjq3oqnPc0a/Mo6aMtsmmsuS38ERJFPOdAztX7JdpT1/rqSC5OGRUF7og FQzD11qoM3UJ7XKTVpTg1BvbFBS+M1Wy2QXRowA7bkBO6Z5bTKsjcPMojU0h7LY1PFFE CkpUwZyVbky5UXhul9OVrJKIQQFf/EHZn5utcpUJUbyam42FtE846lBmcvtvYyYl7908 CmhnzQjcKSOsEL+8I+NygvSEsrmwclO3Acsc398IQXgUiBKkhVXyD+yQDCqoSyW07bqG I/Cd+0u/mLPzBuR8KkLi7Otr5XP+zE14QcpTD+vMmCBhn0FwbLK2+euoywRSE7LqbA6l NQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p417cnc50-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Mar 2023 14:51:06 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32AEMSsu021509; Fri, 10 Mar 2023 14:51:05 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3p6fub0e15-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Mar 2023 14:51:05 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 32AEosCR013152; Fri, 10 Mar 2023 14:51:05 GMT Received: from myrouter.uk.oracle.com (dhcp-10-175-184-199.vpn.oracle.com [10.175.184.199]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3p6fub0dkf-4; Fri, 10 Mar 2023 14:51:04 +0000 From: Alan Maguire To: acme@kernel.org Cc: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, eddyz87@gmail.com, haoluo@google.com, jolsa@kernel.org, john.fastabend@gmail.com, kpsingh@chromium.org, sinquersw@gmail.com, martin.lau@kernel.org, songliubraving@fb.com, sdf@google.com, timo@incline.eu, yhs@fb.com, bpf@vger.kernel.org, Alan Maguire Subject: [PATCH dwarves 3/3] btf_encoder: compare functions via prototypes not parameter names Date: Fri, 10 Mar 2023 14:50:50 +0000 Message-Id: <1678459850-16140-4-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678459850-16140-1-git-send-email-alan.maguire@oracle.com> References: <1678459850-16140-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-10_06,2023-03-10_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303100121 X-Proofpoint-GUID: wGzOI2I6NUKSm_FFU-H0SFlMV9xtgHd1 X-Proofpoint-ORIG-GUID: wGzOI2I6NUKSm_FFU-H0SFlMV9xtgHd1 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Parameter names are a brittle choice for comparing function prototypes. As noted by Jiri [1], a function can have a weak definition in one CU with differing names from another definition, and because we require name-based matches, we can omit functions unnecessarily. Using a conf_fprintf that omits parameter names, generate function prototypes for string comparison instead. [1] https://lore.kernel.org/bpf/ZAsBYpsBV0wvkhh0@krava/ Reported-by: Jira Olsa Signed-off-by: Alan Maguire --- btf_encoder.c | 67 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 07a9dc5..65f6e71 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -33,13 +33,13 @@ #include /* for tsearch(), tfind() and tdestroy() */ #include -#define BTF_ENCODER_MAX_PARAMETERS 12 +#define BTF_ENCODER_MAX_PROTO 512 /* state used to do later encoding of saved functions */ struct btf_encoder_state { uint32_t type_id_off; - bool got_parameter_names; - const char *parameter_names[BTF_ENCODER_MAX_PARAMETERS]; + bool got_proto; + char proto[BTF_ENCODER_MAX_PROTO]; }; struct elf_function { @@ -798,25 +798,25 @@ static int32_t btf_encoder__add_decl_tag(struct btf_encoder *encoder, const char return id; } -static void parameter_names__get(struct ftype *ftype, size_t nr_parameters, - const char **parameter_names) +static bool proto__get(struct function *func, char *proto, size_t len) { - struct parameter *parameter; - int i = 0; - - ftype__for_each_parameter(ftype, parameter) { - if (i >= nr_parameters) - return; - parameter_names[i++] = parameter__name(parameter); - } + const struct conf_fprintf conf = { + .name_spacing = 23, + .type_spacing = 26, + .emit_stats = 0, + .no_parm_names = 1, + .skip_emitting_errors = 1, + .skip_emitting_modifier = 1, + }; + + return function__prototype_conf(func, func->priv, &conf, proto, len) != NULL; } static bool funcs__match(struct btf_encoder *encoder, struct elf_function *func, struct function *f2) { - const char *parameter_names[BTF_ENCODER_MAX_PARAMETERS]; + char proto[BTF_ENCODER_MAX_PROTO]; struct function *f1 = func->function; const char *name; - int i; if (!f1) return false; @@ -833,33 +833,27 @@ static bool funcs__match(struct btf_encoder *encoder, struct elf_function *func, if (f1->proto.nr_parms == 0) return true; - if (!func->state.got_parameter_names) { - parameter_names__get(&f1->proto, BTF_ENCODER_MAX_PARAMETERS, - func->state.parameter_names); - func->state.got_parameter_names = true; - } - parameter_names__get(&f2->proto, BTF_ENCODER_MAX_PARAMETERS, parameter_names); - for (i = 0; i < f1->proto.nr_parms && i < BTF_ENCODER_MAX_PARAMETERS; i++) { - if (!func->state.parameter_names[i]) { - if (!parameter_names[i]) - continue; - } else if (parameter_names[i]) { - if (strcmp(func->state.parameter_names[i], parameter_names[i]) == 0) - continue; - } - if (encoder->verbose) { - printf("function mismatch for '%s'(%s): parameter #%d '%s' != '%s'\n", - name, f1->alias ?: name, i, - func->state.parameter_names[i] ?: "", - parameter_names[i] ?: ""); + if (f1->proto.tag.type == f2->proto.tag.type) + return true; + + if (!func->state.got_proto) + func->state.got_proto = proto__get(f1, func->state.proto, sizeof(func->state.proto)); + + if (proto__get(f2, proto, sizeof(proto))) { + if (strcmp(func->state.proto, proto) != 0) { + if (encoder->verbose) + printf("function mismatch for '%s'('%s'): '%s' != '%s'\n", + name, f1->alias ?: name, + func->state.proto, proto); + return false; } - return false; } return true; } static int32_t btf_encoder__save_func(struct btf_encoder *encoder, struct function *fn, struct elf_function *func) { + fn->priv = encoder->cu; if (func->function) { struct function *existing = func->function; @@ -1022,7 +1016,8 @@ static int btf_encoder__collect_function(struct btf_encoder *encoder, GElf_Sym * } encoder->functions.entries[encoder->functions.cnt].generated = false; encoder->functions.entries[encoder->functions.cnt].function = NULL; - encoder->functions.entries[encoder->functions.cnt].state.got_parameter_names = false; + encoder->functions.entries[encoder->functions.cnt].state.got_proto = false; + encoder->functions.entries[encoder->functions.cnt].state.proto[0] = '\0'; encoder->functions.entries[encoder->functions.cnt].state.type_id_off = 0; encoder->functions.cnt++; return 0;