From patchwork Tue Feb 21 15:48:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 13148128 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 8A700C636D7 for ; Tue, 21 Feb 2023 15:49:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234719AbjBUPtP (ORCPT ); Tue, 21 Feb 2023 10:49:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230115AbjBUPtP (ORCPT ); Tue, 21 Feb 2023 10:49:15 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43E1C23309 for ; Tue, 21 Feb 2023 07:49:14 -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 31LDg3Am016180; Tue, 21 Feb 2023 15:48:54 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=YzNkA86FMIi5Lnanj3X8pW+hsNT7m0FSJtEZJAYKJ+U=; b=cz/A/KmZI+9D5nDkS/TqDliy4VcxrhkAgDPRL6OvDaY1+mefOrGN1/tViiH8Cw31pJ2f 7xOYHVHFtEDGF6T/sXZyXklRWO7cOl1mLy5CfhkzYNh3sHnXS7mmJcIQK2uCOr6mjxfr 1LBkBNfIvcMw8PkHyL/1k9FfYhoo9MwFOM9pt4YHQw4WlLLXA8RKLiHbob0qv7HNQqyD 4aY55P+nn4uF9irNjxJjwtt2YPFC1V9uA1g15dfGS08eJql8z28K0jOYJWP0WlJerjiX R8x8i8zGngnOIDRuTaMtFEqiAIoRPAkX1Y61ehsGAwOhoAt1ib+VPvfmjiIupqnnFVo6 wA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ntp9tnhj8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Feb 2023 15:48:54 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 31LFVwiW040888; Tue, 21 Feb 2023 15:48:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ntn458xx0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Feb 2023 15:48:53 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 31LFmmpE007236; Tue, 21 Feb 2023 15:48:52 GMT Received: from myrouter.uk.oracle.com (dhcp-10-175-204-58.vpn.oracle.com [10.175.204.58]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3ntn458xqw-2; Tue, 21 Feb 2023 15:48:52 +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: [RFC dwarves 1/3] dwarf_loader: fix detection of struct parameters Date: Tue, 21 Feb 2023 15:48:40 +0000 Message-Id: <1676994522-1557-2-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676994522-1557-1-git-send-email-alan.maguire@oracle.com> References: <1676994522-1557-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-21_08,2023-02-20_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 adultscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302210131 X-Proofpoint-GUID: Sc597oGMIPr5DMX3QFhsAaZhpAZfTSV_ X-Proofpoint-ORIG-GUID: Sc597oGMIPr5DMX3QFhsAaZhpAZfTSV_ Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-State: RFC In some cases, param__is_struct() was failing to notice that a parameter was a struct. The first was where a parameter was a const struct; the second was where the type information was in the original subroutine information, and additional parameters that referred to it via abstract origin did not also specify type information. We combine information about type, name etc in ftype__recode_dwarf_types(), but since we share the tag->type (rather than the dwarf tag), param__is_struct() was failing to handle this case as it represents parameters like this: <7e0f7d4> DW_AT_sibling : <0x7e0f924> <2><7e0f7d8>: Abbrev Number: 7 (DW_TAG_formal_parameter) <7e0f7d9> DW_AT_abstract_origin: <0x7e0dc80> <7e0f7dd> DW_AT_location : 0x2797488 (location list) <7e0f7e1> DW_AT_GNU_locviews: 0x2797484 <2><7e0f7e5>: Abbrev Number: 7 (DW_TAG_formal_parameter) <7e0f7e6> DW_AT_abstract_origin: <0x7e0dc8b> <7e0f7ea> DW_AT_location : 0x27974ca (location list) <7e0f7ee> DW_AT_GNU_locviews: 0x27974c8 ...which do not specify a type and did not use the tag->type information. Fix param__is_struct() to use cu__type(cu, tag->type) to look up type information, and to handle the const case. Signed-off-by: Alan Maguire --- dwarf_loader.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index 014e130..73e3670 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -2645,19 +2645,17 @@ out: static bool param__is_struct(struct cu *cu, struct tag *tag) { - const struct dwarf_tag *dtag = tag->priv; - struct dwarf_tag *dtype = dwarf_cu__find_type_by_ref(cu->priv, &dtag->type); - struct tag *type; + struct tag *type = cu__type(cu, tag->type); - if (!dtype) + if (!type) return false; - type = dtype->tag; switch (type->tag) { case DW_TAG_structure_type: return true; + case DW_TAG_const_type: case DW_TAG_typedef: - /* handle "typedef struct" */ + /* handle "typedef struct", const parameter */ return param__is_struct(cu, type); default: return false; From patchwork Tue Feb 21 15:48:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 13148129 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 4E4EFC636D7 for ; Tue, 21 Feb 2023 15:49:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234721AbjBUPtT (ORCPT ); Tue, 21 Feb 2023 10:49:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234720AbjBUPtS (ORCPT ); Tue, 21 Feb 2023 10:49:18 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1A1B26844 for ; Tue, 21 Feb 2023 07:49:17 -0800 (PST) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31LDSnDZ001381; Tue, 21 Feb 2023 15:48: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=ooPfe+yd7YRGMFJcFx0q14eJgWY8AE0qz9xHf6MNWLc=; b=Fhkb/BBHFT8LB+7wTAtMIMs0liVSYtXUIIQjnMW54Zv1qpErygHSyVMN0AHQ9tTD7nGn ky1nq3OJNscSamCbMAnOCO9BdQZgn0NTlrG7ZOiNLptQ6YrXDwuLHyAQv1u+M/c0xUwg IxOhP7UF22+FGmX7jUk9lucZoJsOi8MEmBMPyM0xey3VZJLI8wvO1YKAHWlDdIhndkp9 vnq4kiPIULdX4xMxtYyjqLaHPQihSJBsAOakvlAEb5ny0TvB0hZohXHGulonzmApCFE/ rm46mX9HzrP0cUdo6GVGPtKeshOYkBhkyGMrm9EWOcPRgCdgOahJUK1PwpccrP+H86DR 4Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ntn90nhwd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Feb 2023 15:48:58 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 31LFgV2u040789; Tue, 21 Feb 2023 15:48:58 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ntn458y21-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Feb 2023 15:48:58 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 31LFmmpG007236; Tue, 21 Feb 2023 15:48:57 GMT Received: from myrouter.uk.oracle.com (dhcp-10-175-204-58.vpn.oracle.com [10.175.204.58]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3ntn458xqw-3; Tue, 21 Feb 2023 15:48:56 +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: [RFC dwarves 2/3] dwarf_loader: fix parameter location retrieval for location lists Date: Tue, 21 Feb 2023 15:48:41 +0000 Message-Id: <1676994522-1557-3-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676994522-1557-1-git-send-email-alan.maguire@oracle.com> References: <1676994522-1557-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-21_08,2023-02-20_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 adultscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302210131 X-Proofpoint-ORIG-GUID: WOsixx6lOxd1CvIJlF03yQUTaNATgDEF X-Proofpoint-GUID: WOsixx6lOxd1CvIJlF03yQUTaNATgDEF Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-State: RFC dwarf_getlocation() does not work for location lists; use dwarf_getlocations() instead. For parameters we are only interested in the first expr - the location on function entry. Signed-off-by: Alan Maguire --- dwarf_loader.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index 73e3670..6ae0954 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1073,6 +1074,7 @@ static struct parameter *parameter__new(Dwarf_Die *die, struct cu *cu, struct parameter *parm = tag__alloc(cu, sizeof(*parm)); if (parm != NULL) { + Dwarf_Addr base, start, end; bool has_const_value; Dwarf_Attribute attr; struct location loc; @@ -1115,10 +1117,18 @@ static struct parameter *parameter__new(Dwarf_Die *die, struct cu *cu, * between these parameter representations. See * ftype__recode_dwarf_types() below for how this is handled. */ - parm->has_loc = dwarf_attr(die, DW_AT_location, &attr) != NULL; has_const_value = dwarf_attr(die, DW_AT_const_value, &attr) != NULL; + parm->has_loc = dwarf_attr(die, DW_AT_location, &attr) != NULL; + /* dwarf_getlocations() handles location lists; here we are + * only interested in the first expr. + */ if (parm->has_loc && - attr_location(die, &loc.expr, &loc.exprlen) == 0 && +#if _ELFUTILS_PREREQ(0, 157) + dwarf_getlocations(&attr, 0, &base, &start, &end, + &loc.expr, &loc.exprlen) > 0 && +#else + dwarf_getlocation(&attr, &loc.expr, &loc.exprlen) == 0 && +#endif loc.exprlen != 0) { int expected_reg = cu->register_params[param_idx]; Dwarf_Op *expr = loc.expr; From patchwork Tue Feb 21 15:48:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 13148130 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 5631AC636D7 for ; Tue, 21 Feb 2023 15:49:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230115AbjBUPt1 (ORCPT ); Tue, 21 Feb 2023 10:49:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234425AbjBUPt0 (ORCPT ); Tue, 21 Feb 2023 10:49:26 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80B7026844 for ; Tue, 21 Feb 2023 07:49:25 -0800 (PST) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31LDTScU010595; Tue, 21 Feb 2023 15:49: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=G5K9lfph9lh8VH3VEPHCa+6ChOPqIpYQaKe0Gka29Do=; b=0fuifpb42rLS3IhfC6lD/SV3wh4/2+0PRngnvL3jjealLvss4dWar13HWwqAKomzqGUp QgbmtjjQ/opEfPEWIsh+Qc1MAq0uV5rbr14XVRXX5V99UH3lxECTq2sD/Qaj/sNvsQOE lv07BCmTP3jyAkfaPmhSBFCROaVSPe/SzywM6gNWHOJ3QEArMEHS6xLtVqC3T1TReWoN t9q51t8bvuOxYcJIXzfxw3UOoxbQme7+XmeKfxnUWY9VLu9xCwYPdFNlL334WbgFtVdk 2PeFZRftEWTOBgDwsA++7uGF1E9UFvY0+CpmE/TH6CvB3ow/XztEuGuswmC3Q0QeAHuL hA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ntq7udev2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Feb 2023 15:49:02 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 31LFEUFs040784; Tue, 21 Feb 2023 15:49:02 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ntn458y4x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Feb 2023 15:49:02 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 31LFmmpI007236; Tue, 21 Feb 2023 15:49:01 GMT Received: from myrouter.uk.oracle.com (dhcp-10-175-204-58.vpn.oracle.com [10.175.204.58]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3ntn458xqw-4; Tue, 21 Feb 2023 15:49: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: [RFC dwarves 3/3] dwarf_loader: only mark parameter as using an unexpected register when it does Date: Tue, 21 Feb 2023 15:48:42 +0000 Message-Id: <1676994522-1557-4-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676994522-1557-1-git-send-email-alan.maguire@oracle.com> References: <1676994522-1557-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-21_08,2023-02-20_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 adultscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302210131 X-Proofpoint-GUID: BYYMAnKpKtCuyRslFawVk_T1_wBM_QBH X-Proofpoint-ORIG-GUID: BYYMAnKpKtCuyRslFawVk_T1_wBM_QBH Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-State: RFC It is important to distinguish between cases where a parameter uses an unexpected register versus cases where it is optimized out; the function may still be called with the right parameter values in the latter case, they just are not used. Suggested-by: Alexei Starovoitov Signed-off-by: Alan Maguire --- dwarf_loader.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index 6ae0954..791845a 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -1144,14 +1144,12 @@ static struct parameter *parameter__new(Dwarf_Die *die, struct cu *cu, if (expected_reg >= 0 && expected_reg != expr->atom) parm->unexpected_reg = 1; break; - case DW_OP_breg0 ... DW_OP_breg31: - break; default: - parm->unexpected_reg = 1; + parm->optimized = 1; break; } } else if (has_const_value) { - parm->unexpected_reg = 1; + parm->optimized = 1; } }