From patchwork Wed Oct 2 23:52:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13820571 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0AEF19F11E; Wed, 2 Oct 2024 23:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727913186; cv=fail; b=eWnxaEx8S4r0q2fX4DL23wNZ31SxJf3ACBZdsljxjqhTlo/shrsNxjbSxl/EBE0aEwLN3m293W+DnKKLrCy30V3/VVGe9MJeRxQtyGqYPE9Y/5n/nAPQNhsORZcjQNEzPeatDUaP943VDt9YU1iSa69bDys/TzkfHXijwQSwxQ4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727913186; c=relaxed/simple; bh=MvLyetgH+KPoMxLmPBsS/gLHDNcqr80lXeEHNuLzfA0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=gsQLCSN0zIr3v5wTQDYKTy62geN0NKMqBh0MZrWyGq1G5nuX2Egel5FRBhnhfk/Ob2vH5WHmdx/d3fFcdjlv2lMh2N9ygOsPiuL/ti6FAYgHfYmkzscPsKlqusKzmsZCoNx0swjcJCHmH5fEVXsnv0pp19lxNsOe3rBfEWlQGBA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=IKbjaElp; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=SKsXdaHl; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="IKbjaElp"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="SKsXdaHl" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 492MffXa023095; Wed, 2 Oct 2024 23:53:02 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 :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=cS/5+NCdgo3qKZ3FTO8/7PyLt/sD7dGd/9NM+VvReBY=; b= IKbjaElpBcVUB+BS+68RUJI91dHagteUVp/jzq6jQ7BR+V8VEddDvY2Ubwiakf2x 6rIorYNPDhW+g9i0+IdI1bBeQ8QY1EHxGg8Fci8KivWEBy4XMTztjW3E9g7xPwcn tyTV41Z6cYqh897ZHRPONLWvfjFqDx8thTsV4WVBzlgN6B8w/b3nFrw1Q93SKGBd xfJvbXgh0rm20Ps6GJReNCIXSxL1gKydxdkr/WBcywLo6XUjKsnpsc03Y/Qw/0Kk /yAhUIXaMtRMbq/rKfUNnYGozDeThGYlsZ2ruZVHjXh3uqCZ/liuBvUkJfbosjPJ 7hRYFUKCLvUIJ6KinLlaxQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41xabttst9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 23:53:01 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 492LQoSI017460; Wed, 2 Oct 2024 23:53:01 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2171.outbound.protection.outlook.com [104.47.57.171]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41x889g60n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 23:53:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Wjhud2PGbr/dt2wN66YkxCuyrfpUiedETdrtpf5OloL7DYNrtz08sFng9eNJNpFmZu7/eQ2+OemLaU9L6c7jzQJcowjcuhAkBy5lxX+TWuORLFsAS9LGAi4+s707FcD5xEB1CufxDgegVXQaqX7+Kj3w2Bd9wrJgEkldBwXeLpVVbFmsqDW7FnjX7FNfMAsZR7Y0TlzqpqF5n/SThNFlk0dkTLVCvmC4WO/rtMIt+ff6Kf6RPCvPEQe+TR5eFZEYPdmWAwonAEQgZ0UDj9eIxNB8/sYDSmlaY4u8qpbUXs7S6VoraifuECTqrWEIOo/yBMbEbHx8vRmrYaloKt+Yuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cS/5+NCdgo3qKZ3FTO8/7PyLt/sD7dGd/9NM+VvReBY=; b=iqIg/BWFRx5/rlYSxP5zW8vbhFZzApwxTULv8WOYBRf3Mfpqt0EnFEsWwTriw7u6E867El8eYHe2VoGjGI/Hsx4EVV5iXkFbvntH+V3QN6MdB61Vlai6AqA+RK1uLsvMvMJCWKTU4vA1LUp16OpDaW4Zkw3n1T0MbpohxpkidBK7MFZY06sgm+aImN31rMpjau3n3x0sEAcQPqI/KkueV/Zj9FOFp6WKUJw3R5TNlwnjb9E7kxLHu6cGqInDEspHj1ltQJO78yu08QA6lJ9Y2D7o39Dk1F8v8kR+PHg0bfHoQMyFEbbRe/fynHTLVIF99zaKKQo8jx1jC66Heq38Iw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cS/5+NCdgo3qKZ3FTO8/7PyLt/sD7dGd/9NM+VvReBY=; b=SKsXdaHli/Rr3X9nny9w9hgiQJkA6QnPTYTdmkLi1eLJH+dpXotuPVfFEUVZ20xtWAMr5b0FFu1HMA+VgX51BVLfopa3ERRbQ8k8fiOeJfyYxMQhf3SRkIk4fzwe8o3DjZz2Wr3rgcA9aKYyaQ/vZju6wg7UIqsD6apfU1js3LY= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by SA2PR10MB4458.namprd10.prod.outlook.com (2603:10b6:806:f8::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.16; Wed, 2 Oct 2024 23:52:59 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8026.016; Wed, 2 Oct 2024 23:52:59 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v3 1/5] btf_encoder: use bitfield to control var encoding Date: Wed, 2 Oct 2024 16:52:43 -0700 Message-ID: <20241002235253.487251-2-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241002235253.487251-1-stephen.s.brennan@oracle.com> References: <20241002235253.487251-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: BLAPR05CA0029.namprd05.prod.outlook.com (2603:10b6:208:335::10) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|SA2PR10MB4458:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e699cc5-e053-4b17-95a0-08dce33d5801 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|10070799003|376014|366016; X-Microsoft-Antispam-Message-Info: baRnr1tikJ4QVrwjqUGvx0a1fmnzWmfPFhV036za5SOe7z4hjIS+a7tMQLomuhx/n36UemRlV7TW4ne8Ll0fw7X5DX1LCncYHT6TOWEPADYvi+neiquNJ+oms6PZtXCb54oWHtvmvJdNjgqPoctntGuW+KHyeHHVv2H6l442RjYnxfC7EmX5KALqlfzeEX1iTdosSfsTiZCcCNBFJJWkQhk+w9c2JsFyUEDvF0DNPvnBte0cFFaWhzNUJcYhbNwJzvIUCGLMVCkuvE9g+TIbFMFYshl9cNYov0H2V/5BICAQBr0wPdnQ0MlbmEs6sfOCcm0rxjGbpoqLfIdYGNQRG2MG0KrxSpydLfquHHoCZElWQtD8jB7torfPNx1hypXVmti3O5BsJgj+t/b+csJjPdp4x/IkGo1Ev39QCQKO8/s4WbtNfnimTHznqNxlLkvC171RpryYFHCN5LO+NcNBvohiWO4YV/pqpnPoEG7No7YCb8DFPapIYyjfaIbYg30Fxy7lNmGprbs7nZGxTPmCrDSC88lW+8wHxERj5df4aJJDo4cL2b0dMyIjRwdh0ahaO3gFcyA5JgJ72NEtj2mV1UY9N9pAxVCJmxF1XoQqWmSpwt+Aiud+d1r72Dn0iEABim7dla2A2SJh3a7FTYykp5iZ0fx9187l+SGNP3orZnPda8shNFPTCbTpCk63EuduZizIphmakNPptwgiKXqsgsKoEeBfTU4UfB4LPtMbvkcIp1+bmKFzIDZzoi0AOGTmsB0QAs0t0iQUoA//FzUG/wJqNMtMI70oIXjXzb33ftx+fR2C99qLWs+bRyzaiyQmDvb+4W5ISF0N0mEybYN7yn/QWeVzeFQT7b8XxV+dsHAXaziQhazvO+QTES6J3ZtfXsYsePluf3J3RrmRi8xdEKx9MZMS5fc4f0oB5huepBu+X2X8rTAyw5mw4LvR8+WRTDqhs2Dwq2wApz+EAfxa5f2ufrlcCqIbHgq/bf7KPJa6JTuwgqhLhCkwjyPB2BTRKwjQx5nTfW+6eig6c2BjO7vvkKD1FqiX2il/moABa2vEAjATMPfkPtYc/vHkgnRkorF8eRvXo0hUM36w9YbbaQ33kx/Rs+6Yaim30JKub9Y0BvXrXb0LtJA56CGcIRqzR9iyVLv4EK9hdkIjAfnc9L5+9jeX7nxVc60ZU2BWTGx8BGOJGLDEuAb3x+VANQLmnujtkeSd4fTyp4KnJSLT3T7LXyk9SCpb/H57j2zqwwVetVA+HdSmXm3NRDRr9Imf5xO2ByApT7OseP4sq7mzrw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(10070799003)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: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1KlEnp+mWGZicDe+LcDCCJKzsbsc7FCeOKK4TzAttgpp4MCT6FWOnh2A6itnp/NtTv6YF1bLRZqhgMCzihLgIclJWx2fxbWuxHUvtv3YABcK9gOBJ+DD/kJc3bZa2IkDsh5EaLgAWB9+whap8KrjL85A2d+Pck7EaDy9OL2UeSzWdBgRoWbGhnfHeTmMeXwXHsDv+XkHgyrcsrHq/oZkQ7JQogGE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e699cc5-e053-4b17-95a0-08dce33d5801 X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2024 23:52:58.9976 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xc9d7QOeH6xVQOkL5AHXbeqVm+ov3ef/6cHZ0AydfV4C9SoMP4ZSLw1sPArbo6u0+QlIqxtsQ8XQZIr3PxXjRxW19Sixi36KTROxQhlepJw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4458 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-02_21,2024-09-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2410020169 X-Proofpoint-ORIG-GUID: 7d5slh684KYydDnjCd4Eify4x_iy-YHG X-Proofpoint-GUID: 7d5slh684KYydDnjCd4Eify4x_iy-YHG We will need more granularity in the future, in order to add support for encoding global variables as well. So replace the skip_encoding_vars boolean with a flag variable named "encode_vars". There is currently only one bit specified, and it is set when percpu variables should be emitted. Signed-off-by: Stephen Brennan Reviewed-by: Alan Maguire --- btf_encoder.c | 10 ++++++---- btf_encoder.h | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 51cd7bf..652a945 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -119,7 +119,6 @@ struct btf_encoder { uint32_t type_id_off; bool has_index_type, need_index_type, - skip_encoding_vars, raw_output, verbose, force, @@ -137,6 +136,7 @@ struct btf_encoder { int allocated; uint32_t shndx; } percpu; + int encode_vars; struct { struct elf_function *entries; int allocated; @@ -2369,7 +2369,6 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->force = conf_load->btf_encode_force; encoder->gen_floats = conf_load->btf_gen_floats; - encoder->skip_encoding_vars = conf_load->skip_encoding_btf_vars; encoder->skip_encoding_decl_tag = conf_load->skip_encoding_btf_decl_tag; encoder->tag_kfuncs = conf_load->btf_decl_tag_kfuncs; encoder->gen_distilled_base = conf_load->btf_gen_distilled_base; @@ -2377,6 +2376,9 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->has_index_type = false; encoder->need_index_type = false; encoder->array_index_id = 0; + encoder->encode_vars = 0; + if (!conf_load->skip_encoding_btf_vars) + encoder->encode_vars |= BTF_VAR_PERCPU; GElf_Ehdr ehdr; @@ -2436,7 +2438,7 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam if (!encoder->percpu.shndx && encoder->verbose) printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION); - if (btf_encoder__collect_symbols(encoder, !encoder->skip_encoding_vars)) + if (btf_encoder__collect_symbols(encoder, encoder->encode_vars & BTF_VAR_PERCPU)) goto out_delete; if (encoder->verbose) @@ -2633,7 +2635,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, struct co goto out; } - if (!encoder->skip_encoding_vars) + if (encoder->encode_vars) err = btf_encoder__encode_cu_variables(encoder); if (!err) diff --git a/btf_encoder.h b/btf_encoder.h index f54c95a..91e7947 100644 --- a/btf_encoder.h +++ b/btf_encoder.h @@ -16,6 +16,12 @@ struct btf; struct cu; struct list_head; +/* Bit flags specifying which kinds of variables are emitted */ +enum btf_var_option { + BTF_VAR_NONE = 0, + BTF_VAR_PERCPU = 1, +}; + struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, bool verbose, struct conf_load *conf_load); void btf_encoder__delete(struct btf_encoder *encoder); From patchwork Wed Oct 2 23:52:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13820572 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35774199249; Wed, 2 Oct 2024 23:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727913198; cv=fail; b=VGwYioowDmgHoeZHiSYakQSS4L8X5bUuHTOngeBUkw8MeVDnZOw1esTn+V2h03PnLygG3fGQwnYI11nQZgos7QfviUrNtYznaGdvnTka0XHpmzJKwM0QkzLhuDFAOccsCAOq2fUn3/2JrBOHs2q3BBrMnGHUAMV1W4ixqLK3kl8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727913198; c=relaxed/simple; bh=nJ54YNPaypTPpJbuW6KySZNX5+pOYtAVFtU5ajR2yAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=AF8W15AtL/BmU53FR2RU5ADq17W4v5Yi33yRW+3Jj18HfqH6BKWWuOdPzxVUs8HXcm24wRpyC0UIc3L26BNA6powbiQ7UQ0eemZft9xd5z2wgKicyVnBwY85UgnRHUgAKEqiW2oQqytj9fEyvzGg5vhWtcV4VDpC1LabM9qQqJs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=dQj6ZOmi; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=vThWW4iI; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="dQj6ZOmi"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="vThWW4iI" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 492MghJe031788; Wed, 2 Oct 2024 23:53:05 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 :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=Bbyzpcs81t4JJ1/b4UtooRDZxXMzXkoXC1/woHpThUg=; b= dQj6ZOmicCmJyW23QJ5znFncI5XgWMX7HUxXfUGABug5eXgINZZTpg6wDCgULcFx 4oeidiUqTjeKNs4qjOVm0YCf9YJrw1zTvh3vPAfFD3jYoyWWKt1KQLYRQV/8Ubzx ALhTDBxTpcwR1omFO3fCNRwEmV8dxo72uKvcgDlcj66HXfz/YArEnK+D38/VKNSE QE74xYslB4AerBmyTlfl5B6ccDjwKwv4nLg+OhlJpXv6893B5maUgNePK/KODEeu lroqtaAZojmESrClOc3/6A/2u6JlDEjLukSGv0YO4VA9Uv4yeZb5Prhn8dP72wjW Hw/n1fnTeMcdEmkEBODhFg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41x87dauf9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 23:53:05 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 492LVZ2A028553; Wed, 2 Oct 2024 23:53:04 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2175.outbound.protection.outlook.com [104.47.57.175]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41x889r8kw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 23:53:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=czkqklhio0ERuv1Pa9Q1sLbBSRN4DPKZlphahOTPpGYI07186a/2s8rwqhpY/raNwDoPWwMGsy+03netCCELrgqj7TlQQo3DgVTkEWy20yIFRit4YtmdBxkWF0YGGmp+LAkEPLqStrI62HvaWe1qTintZVdt/Vsm/LXpAbIWp5Ru5nahR7ivQbUWHUNZePfgiix5GJv2f4dXOQaZIDWEgMiU05mdHQjYoP0i8LDiG+A9QNwZD3rMDuPEz+j7WZ3nk3CII0XKpxNuxBuxYmT9yoNy0J+pom1IX+CRSn9D/y38lGJM70hP4YiZ+eD3II7ThFFOqxylyJTfHQh4mT6PRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Bbyzpcs81t4JJ1/b4UtooRDZxXMzXkoXC1/woHpThUg=; b=WwjxffJCSsbEAnvZs8ahiTicN8cLXJ0CQRlOExE2tJoTXHUEiIsBcjfn3zMeT2uOBjhQfVWQVILn/Hp10FI84q/4mXD1tSsc85v+o+RiBtAa9ccL3vTatP9F3KtJ6euEAbnbSTAFfZf2wNOF6qozFH89RZqtOfktxtiOoZI8cUfAnu2+xAW/Yy+rUu0x6QVhz+uyqrekf9rDmC5EA5Us+l9mZR1LSZzUd92ZrToXf4cAgR3OM3bCOWZQUzQU7+4fsWEA4Rr/vJry0JNW+iSEDPYS3UWK+B31Thwq/fC0JyrkMhvt7MjZ9hk7gsUGMh795ziW17BFcMz9H4GWp1rysA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bbyzpcs81t4JJ1/b4UtooRDZxXMzXkoXC1/woHpThUg=; b=vThWW4iIWW23zW1SVGLtpVeZhal5kNXMlR+e1ag+KYpfD/YOnN6sugtLmow7SbVVN7jtmHhXVsU5hg4hQu7fq+5lbN3PWk8wZAjviSTmjICkCjdfEUruQfze01JSxrKigeHuDtEyIhEUEBVPwT5dNZCFL/XcnUAuvp5iYwjVscc= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by SA2PR10MB4458.namprd10.prod.outlook.com (2603:10b6:806:f8::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.16; Wed, 2 Oct 2024 23:53:01 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8026.016; Wed, 2 Oct 2024 23:53:01 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v3 2/5] btf_encoder: stop indexing symbols for VARs Date: Wed, 2 Oct 2024 16:52:44 -0700 Message-ID: <20241002235253.487251-3-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241002235253.487251-1-stephen.s.brennan@oracle.com> References: <20241002235253.487251-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: BN8PR12CA0014.namprd12.prod.outlook.com (2603:10b6:408:60::27) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|SA2PR10MB4458:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d09dde5-f5d0-4dac-6a5f-08dce33d599b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|10070799003|376014|366016; X-Microsoft-Antispam-Message-Info: cyZjSTcayOyjlUbT4MnMX6pDDGHlGyOqoYDr4y1g3qpnb+1KgMbjuqIWeiql9xCKEhyKC4AF2vB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OvnZbVEs/1LYZeli4QbGzJRGRKt8UnrDN1WN6EVi/dmeaI+B2MuzlOfuj99ltLJF5y7YlToR0SSFiSN0aG2AaL9ko8UyZWIwxQuy2dyfpZRFtDKnAlrXiPLSd4RI9jQu7hFUQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(10070799003)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: N2pwun9hbf/i3rXe9V/kueYPUAvVJpponKPjtAVpjI+vkQ+1VteqkHEMzzy3mJKP5hCMt5hRa9xoj+g7OZBq69I35YEzqNJRlBrX5a9l0EGD7BmXbooZ651KEYHhHOSWVU1g3+vh6O5LF2Nlfne6jmyjco2MmBlaY0mAJ1KLt4ILnaWxPbPATaKvjMB9thk3Da0Ue/5DbMRu8cvnpCMWS93VFJ3RpdEhCQSCejex6hTnIzjO62kBNbRjYJlQVUr322HVORQAspLH+kBnrCrHdSZfgVy8GWEoaSmF+KqQ5V2kkwNx/XG8tRKrBJuM3hPdDi3GcnhSCgZs32ztiDpWiQ9y/z6mPcqh44A0P3MldQIywJMaOT/haSSGkG5b9vtJCA9cHIOH0iLpQ2rr3L1kJG59kT7vZJK3aw4Javu42ZryKynm6hfuUrhuj9kLBuGYCUaSzIZe02FaE7EZGFyJnPuDaR4jZq3+TAZFH9L9zbSJvfy33ugRMuKmknBY7eRigMO+9bmVpheKbAMbyjPDyOZ+nHa6517THY7pakvBcEDMi1E7e2D4i9jSF5jnNj+zKzhsQrKYnOjKznGKrXUKrCN3XpgEXVNMq8haF7jPPXSNxiYuaSpSRsQUng3TvH+XLpmxcBUz8n0sigj0kOayKqzsB78xgkT+7BAVsNfuBt+KnXZakStePgKQ9yIid6O67Ux/5B4Ya80r8mWPOy+2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3mI2tcvlFWjZZJoAhC4y+4vkx+V+BZfU8Z+SAI1qTLbgrsZZ7T+ARJAQ/jV4n0aXgYU3FWH637JTNQoOArzVAGLaFAYZp1S9V1zpC2P7wxvVZhlU4nzi0NRT5Dg45BWNt39W7qc79BmY2Lr5TPyswfyBzazh/TF5M+S9Xer0AMNrREeLv7R2ax5ej5ltntJcHIl02Rev+BlMQsGCFQuuF2nO7zRCqcL9eU5PXazUe6agCYNO0WOk3XvfJv1dfXztElM9Wxt9sYRt0S/KWkYG+OlIXuar1bEHf3iEc4mO2N3AltFfRtynOi88NVeV/vepVWsYdWKsRfr2kTXEmfjPJnBdNIWV0TS2vw1FqdfJLj8NQ3A0gFshVttAqHX21fZAWhjpdePx6z07XSoIXUIHeRnEO4RP/tVXJS0DJuvgYlvOKYi0gWRLU6hXIQTObkpk7JRs+1qpVoQFJdAHue/UB3aXzB9QygrijBAanctrmjLtLGFtBE+eDrw35TwhACApTZ5P8fYO/TMKfJ9i5SlHTmF9SEiqfgGd+/Dc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d09dde5-f5d0-4dac-6a5f-08dce33d599b X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2024 23:53:01.7244 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8Xw/kxxUusRm686dsd7s6pdG6mcgRGXFu/kC3nRD1PfF3wWK49veVfe5UZQhyAQEosM/8i322ESqmR2INsDq39YpUMbp7sCn/ENXECB5ipE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4458 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-02_21,2024-09-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2410020169 X-Proofpoint-GUID: r32tOQnZ4qPhqsNxerHIVAy92sKI2qjt X-Proofpoint-ORIG-GUID: r32tOQnZ4qPhqsNxerHIVAy92sKI2qjt Currently we index symbols from the percpu ELF section, and when processing DWARF variables for inclusion, we check whether the variable matches an existing symbol. The matched symbol is used for three purposes: 1. When no symbol of the same address is found, the variable is skipped. This can occur because the symbol name was an invalid BTF identifier, and so it did not get indexed. Or more commonly, it can be because the variable is not stored in the per-cpu section, and thus was not indexed. 2. If the symbol offset is 0, then we compare the DWARF variable's name against the symbol name to filter out "special" DWARF variables. 3. We use the symbol size in the DATASEC entry for the variable. For 1, we don't need the symbol table: we can simply check the DWARF variable name directly, and we can use the variable address to determine the ELF section it is contained in. For 3, we also don't need the symbol table: we can use the variable's size information from DWARF. Issue 2 is more complicated, but thanks to the addition of the "artificial" and "top_level" flags, many of the "special" DWARF variables can be directly filtered out, and the few remaining problematic variables can be filtered by name from a kernel-specific list of patterns. This allows the symbol table index to be removed. The benefit of removing this index is twofold. First, handling variable addresses is simplified, since we don't need to know whether the file is ET_REL. Second, this will make it easier to output variables that aren't just percpu, since we won't need to index variables from all ELF sections. Signed-off-by: Stephen Brennan Reviewed-by: Alan Maguire --- btf_encoder.c | 250 +++++++++++++++++++------------------------------- 1 file changed, 96 insertions(+), 154 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 652a945..31a418a 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -93,16 +93,11 @@ struct elf_function { struct btf_encoder_func_state state; }; -struct var_info { - uint64_t addr; - const char *name; - uint32_t sz; -}; - struct elf_secinfo { uint64_t addr; const char *name; uint64_t sz; + uint32_t type; }; /* @@ -125,17 +120,11 @@ struct btf_encoder { gen_floats, skip_encoding_decl_tag, tag_kfuncs, - is_rel, gen_distilled_base; uint32_t array_index_id; struct elf_secinfo *secinfo; size_t seccnt; - struct { - struct var_info *vars; - int var_cnt; - int allocated; - uint32_t shndx; - } percpu; + size_t percpu_shndx; int encode_vars; struct { struct elf_function *entries; @@ -2098,111 +2087,18 @@ int btf_encoder__encode(struct btf_encoder *encoder) return err; } -static int percpu_var_cmp(const void *_a, const void *_b) -{ - const struct var_info *a = _a; - const struct var_info *b = _b; - - if (a->addr == b->addr) - return 0; - return a->addr < b->addr ? -1 : 1; -} - -static bool btf_encoder__percpu_var_exists(struct btf_encoder *encoder, uint64_t addr, uint32_t *sz, const char **name) -{ - struct var_info key = { .addr = addr }; - const struct var_info *p = bsearch(&key, encoder->percpu.vars, encoder->percpu.var_cnt, - sizeof(encoder->percpu.vars[0]), percpu_var_cmp); - if (!p) - return false; - - *sz = p->sz; - *name = p->name; - return true; -} - -static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym *sym, size_t sym_sec_idx) -{ - const char *sym_name; - uint64_t addr; - uint32_t size; - - /* compare a symbol's shndx to determine if it's a percpu variable */ - if (sym_sec_idx != encoder->percpu.shndx) - return 0; - if (elf_sym__type(sym) != STT_OBJECT) - return 0; - - addr = elf_sym__value(sym); - - size = elf_sym__size(sym); - if (!size) - return 0; /* ignore zero-sized symbols */ - - sym_name = elf_sym__name(sym, encoder->symtab); - if (!btf_name_valid(sym_name)) { - dump_invalid_symbol("Found symbol of invalid name when encoding btf", - sym_name, encoder->verbose, encoder->force); - if (encoder->force) - return 0; - return -1; - } - - if (encoder->verbose) - printf("Found per-CPU symbol '%s' at address 0x%" PRIx64 "\n", sym_name, addr); - - /* Make sure addr is section-relative. For kernel modules (which are - * ET_REL files) this is already the case. For vmlinux (which is an - * ET_EXEC file) we need to subtract the section address. - */ - if (!encoder->is_rel) - addr -= encoder->secinfo[encoder->percpu.shndx].addr; - - if (encoder->percpu.var_cnt == encoder->percpu.allocated) { - struct var_info *new; - - new = reallocarray_grow(encoder->percpu.vars, - &encoder->percpu.allocated, - sizeof(*encoder->percpu.vars)); - if (!new) { - fprintf(stderr, "Failed to allocate memory for variables\n"); - return -1; - } - encoder->percpu.vars = new; - } - encoder->percpu.vars[encoder->percpu.var_cnt].addr = addr; - encoder->percpu.vars[encoder->percpu.var_cnt].sz = size; - encoder->percpu.vars[encoder->percpu.var_cnt].name = sym_name; - encoder->percpu.var_cnt++; - - return 0; -} -static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collect_percpu_vars) +static int btf_encoder__collect_symbols(struct btf_encoder *encoder) { - Elf32_Word sym_sec_idx; + uint32_t sym_sec_idx; uint32_t core_id; GElf_Sym sym; - /* cache variables' addresses, preparing for searching in symtab. */ - encoder->percpu.var_cnt = 0; - - /* search within symtab for percpu variables */ elf_symtab__for_each_symbol_index(encoder->symtab, core_id, sym, sym_sec_idx) { - if (collect_percpu_vars && btf_encoder__collect_percpu_var(encoder, &sym, sym_sec_idx)) - return -1; if (btf_encoder__collect_function(encoder, &sym)) return -1; } - if (collect_percpu_vars) { - if (encoder->percpu.var_cnt) - qsort(encoder->percpu.vars, encoder->percpu.var_cnt, sizeof(encoder->percpu.vars[0]), percpu_var_cmp); - - if (encoder->verbose) - printf("Found %d per-CPU variables!\n", encoder->percpu.var_cnt); - } - if (encoder->functions.cnt) { qsort(encoder->functions.entries, encoder->functions.cnt, sizeof(encoder->functions.entries[0]), functions_cmp); @@ -2224,15 +2120,54 @@ static bool ftype__has_arg_names(const struct ftype *ftype) return true; } +static int get_elf_section(struct btf_encoder *encoder, unsigned long addr) +{ + /* Start at index 1 to ignore initial SHT_NULL section */ + for (int i = 1; i < encoder->seccnt; i++) + /* Variables are only present in PROGBITS or NOBITS (.bss) */ + if ((encoder->secinfo[i].type == SHT_PROGBITS || + encoder->secinfo[i].type == SHT_NOBITS) && + encoder->secinfo[i].addr <= addr && + (addr - encoder->secinfo[i].addr) < encoder->secinfo[i].sz) + return i; + return -ENOENT; +} + +/* + * Filter out variables / symbol names with common prefixes and no useful + * values. Prefixes should be added sparingly, and it should be objectively + * obvious that they are not useful. + */ +static bool filter_variable_name(const char *name) +{ + static const struct { char *s; size_t len; } skip[] = { + #define X(str) {str, sizeof(str) - 1} + X("__UNIQUE_ID"), + X("__tpstrtab_"), + X("__exitcall_"), + X("__func_stack_frame_non_standard_") + #undef X + }; + int i; + + if (*name != '_') + return false; + + for (i = 0; i < ARRAY_SIZE(skip); i++) { + if (strncmp(name, skip[i].s, skip[i].len) == 0) + return true; + } + return false; +} + static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) { struct cu *cu = encoder->cu; uint32_t core_id; struct tag *pos; int err = -1; - struct elf_secinfo *pcpu_scn = &encoder->secinfo[encoder->percpu.shndx]; - if (encoder->percpu.shndx == 0 || !encoder->symtab) + if (encoder->percpu_shndx == 0 || !encoder->symtab) return 0; if (encoder->verbose) @@ -2240,59 +2175,69 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) cu__for_each_variable(cu, core_id, pos) { struct variable *var = tag__variable(pos); - uint32_t size, type, linkage; - const char *name, *dwarf_name; + uint32_t type, linkage; + const char *name; struct llvm_annotation *annot; const struct tag *tag; + size_t shndx, size; uint64_t addr; int id; + /* Skip incomplete (non-defining) declarations */ if (var->declaration && !var->spec) continue; - /* percpu variables are allocated in global space */ - if (variable__scope(var) != VSCOPE_GLOBAL && !var->spec) + /* + * top_level: indicates that the variable is declared at the top + * level of the CU, and thus it is globally scoped. + * artificial: indicates that the variable is a compiler-generated + * "fake" variable that doesn't appear in the source. + * scope: set by pahole to indicate the type of storage the + * variable has. GLOBAL indicates it is stored in static + * memory (as opposed to a stack variable or register) + * + * Some variables are "top_level" but not GLOBAL: + * e.g. current_stack_pointer, which is a register variable, + * despite having global CU-declarations. We don't want that, + * since no code could actually find this variable. + * Some variables are GLOBAL but not top_level: + * e.g. function static variables + */ + if (!var->top_level || var->artificial || var->scope != VSCOPE_GLOBAL) continue; /* addr has to be recorded before we follow spec */ addr = var->ip.addr; - dwarf_name = variable__name(var); - /* Make sure addr is section-relative. DWARF, unlike ELF, - * always contains virtual symbol addresses, so subtract - * the section address unconditionally. - */ - if (addr < pcpu_scn->addr || addr >= pcpu_scn->addr + pcpu_scn->sz) + /* Get the ELF section info for the variable */ + shndx = get_elf_section(encoder, addr); + if (shndx != encoder->percpu_shndx) continue; - addr -= pcpu_scn->addr; - if (!btf_encoder__percpu_var_exists(encoder, addr, &size, &name)) - continue; /* not a per-CPU variable */ + /* Convert addr to section relative */ + addr -= encoder->secinfo[shndx].addr; - /* A lot of "special" DWARF variables (e.g, __UNIQUE_ID___xxx) - * have addr == 0, which is the same as, say, valid - * fixed_percpu_data per-CPU variable. To distinguish between - * them, additionally compare DWARF and ELF symbol names. If - * DWARF doesn't provide proper name, pessimistically assume - * bad variable. - * - * Examples of such special variables are: - * - * 1. __ADDRESSABLE(sym), which are forcely emitted as symbols. - * 2. __UNIQUE_ID(prefix), which are introduced to generate unique ids. - * 3. __exitcall(fn), functions which are labeled as exit calls. - * - * This is relevant only for vmlinux image, as for kernel - * modules per-CPU data section has non-zero offset so all - * per-CPU symbols have non-zero values. - */ - if (var->ip.addr == 0) { - if (!dwarf_name || strcmp(dwarf_name, name)) + /* DWARF specification reference should be followed, because + * information like the name & type may not be present on var */ + if (var->spec) + var = var->spec; + + name = variable__name(var); + if (!name) + continue; + + /* Check for invalid BTF names */ + if (!btf_name_valid(name)) { + dump_invalid_symbol("Found invalid variable name when encoding btf", + name, encoder->verbose, encoder->force); + if (encoder->force) continue; + else + return -1; } - if (var->spec) - var = var->spec; + if (filter_variable_name(name)) + continue; if (var->ip.tag.type == 0) { fprintf(stderr, "error: found variable '%s' in CU '%s' that has void type\n", @@ -2304,9 +2249,10 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) } tag = cu__type(cu, var->ip.tag.type); - if (tag__size(tag, cu) == 0) { + size = tag__size(tag, cu); + if (size == 0) { if (encoder->verbose) - fprintf(stderr, "Ignoring zero-sized per-CPU variable '%s'...\n", dwarf_name ?: ""); + fprintf(stderr, "Ignoring zero-sized per-CPU variable '%s'...\n", name); continue; } @@ -2388,8 +2334,6 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam goto out_delete; } - encoder->is_rel = ehdr.e_type == ET_REL; - switch (ehdr.e_ident[EI_DATA]) { case ELFDATA2LSB: btf__set_endianness(encoder->btf, BTF_LITTLE_ENDIAN); @@ -2430,15 +2374,16 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->secinfo[shndx].addr = shdr.sh_addr; encoder->secinfo[shndx].sz = shdr.sh_size; encoder->secinfo[shndx].name = secname; + encoder->secinfo[shndx].type = shdr.sh_type; if (strcmp(secname, PERCPU_SECTION) == 0) - encoder->percpu.shndx = shndx; + encoder->percpu_shndx = shndx; } - if (!encoder->percpu.shndx && encoder->verbose) + if (!encoder->percpu_shndx && encoder->verbose) printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION); - if (btf_encoder__collect_symbols(encoder, encoder->encode_vars & BTF_VAR_PERCPU)) + if (btf_encoder__collect_symbols(encoder)) goto out_delete; if (encoder->verbose) @@ -2480,9 +2425,6 @@ void btf_encoder__delete(struct btf_encoder *encoder) encoder->functions.allocated = encoder->functions.cnt = 0; free(encoder->functions.entries); encoder->functions.entries = NULL; - encoder->percpu.allocated = encoder->percpu.var_cnt = 0; - free(encoder->percpu.vars); - encoder->percpu.vars = NULL; free(encoder); } From patchwork Wed Oct 2 23:52:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13820573 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 484541991BD; Wed, 2 Oct 2024 23:53:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727913198; cv=fail; b=EVr6KYySIIUd0VNJxZNN4YF8Wpw7Q+kIUUw0GKeD/9oCQ3fgqxgFMMsdNLiJIxYtRhd+WYxDFWIrGu63TNkpZJOpW1Wa4BBjrvplIBd6gKcqLOLDclTAPc9abhRYO3HSS/qoc9XqbTCuisEGHmy2H2Tmd0ryqsb4CGjM2PCvku0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727913198; c=relaxed/simple; bh=CfvD+aMTqZnDxnmr8RS8e8SOnDZcmfDFeHmjYliiNTA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=HlDAf0xTAR7/FoFp5AbH0r9RZsQ2u1v+rwZnXkc1mGe/T9Qc/9pCEoOp68Y00AcbYSWojHfmMyuJsKiyc4/C7sUZDGUKX2cSy8LOyBO8KZbYa+3K3++egfOuQpP30C5pq7dkI/3pYbYulLHwCawDkuiog5eMd8MN3xR+yX50Hi4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=YXJ5R6fz; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=TiGQZsT+; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="YXJ5R6fz"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="TiGQZsT+" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 492MfaSD027749; Wed, 2 Oct 2024 23:53:08 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 :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=3K5LOgwm4TNCgRqXXYTFNxJXmqOneN/pDF5TZoOIawk=; b= YXJ5R6fz2RFc6or/IuECJs7qdb9q0nhgmThC74Eh/P9eqa+l9BaW/dYkXzXnLEyy mn3PMizWhg+q9YHuSvp7/8czvNI/e1kllKalFsOe8+NjWXBfCkLe07ZW8W/d3sci 8AT8eNoiMzwkVB6RIULAEZLJZtKvqKxA4iT5rJYKPbJrLQkgbvwzzDoGSl4Q3qiV BbGf2tJiO9xUVNxOhnhWZE/xAKg3T5KGBrY5YCvEKTyssRNpQVYXSrV+X/Sis2Ky ceWhKl+O1WcmkVxB/pSuzHn8U0rofZcag1EkFrY64P/+I92vcOXdgi/BpguuH1jl J/WqdaCqyfKDnf4ykV6yRA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41x9dt2xg1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 23:53:08 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 492MMtEb017377; Wed, 2 Oct 2024 23:53:06 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2171.outbound.protection.outlook.com [104.47.56.171]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41x889g638-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 23:53:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VK1vQZN1IwZGf/Dgi6wXRErPRF8ZN5OKB8KT/VkcDmojTNjpIgaTSbiGsWFkOisJYDnJC03x+EAkV1ZDlK+Rm+6ioYGOYlBzQMcBppu6b+zP0hxm5KTFzUGgBwacnyHI97zP7yQ+QGIWhOeClZzWKn07q1wwjdv5QJMw7zLWgHPuAmoJfA2RJpDfXZBB3NkKs3dt2cam3yAIkNq5M4RPKOZvvzifbDrD+dtGXe2Qk9WyynjpUazSj/hSaSfZy9IvrpE+Eg7yrkWXb/c8ltxJ3d38qJEgfZbCWRSFdYiCqTWHVGIxa4aUl7I6VDTOmstAZ6fW151KUvZy9AoF8SQUhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3K5LOgwm4TNCgRqXXYTFNxJXmqOneN/pDF5TZoOIawk=; b=mJ/6Wzya3gN9Ga3qtNWjEW8UNNfF00/s/fEh1ahUqF4QTPad51Lq5MH8tMhYQ+VGCLig7cj++ptwBJdoi5Y1J11cHr3Bgv6mXI/lXOJ9qv8XT2lNMh1TKfRrgivE+R7m7BG4TvB4UR31Hxjgab2KyxLFbJarUiYeERKaZmTGpw0GEFYf3efxUExsxuUHe3U9U/etiX3fgLHb/APcc8PysIOQ8j/zTnKYL/KH286i2blRTXJcYsarkWYEVM36IoQayIAbYJqqVkilQoUeJh+fFNdnszTbKzHPCHmxtqNMPCUwggSmurZf87PMO2TnBBHaZCBcIwuGYnZSAKatONcF+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3K5LOgwm4TNCgRqXXYTFNxJXmqOneN/pDF5TZoOIawk=; b=TiGQZsT+tDzY8DHPQKROVFPZzIUjktFCpgFqkzlA6wEZpfBz50t5nyyn86XIVnzna2RxjFemQpe88qC5hDLawSJ8Ad97c6h7+fjpkyX29oGLg0gTqq6bDaAzoclhWXg1vCu9H1JPscnWto5HUIkOHt3lEifWRGmoT7mrTBj6wi8= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by SA2PR10MB4458.namprd10.prod.outlook.com (2603:10b6:806:f8::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.16; Wed, 2 Oct 2024 23:53:04 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8026.016; Wed, 2 Oct 2024 23:53:04 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v3 3/5] btf_encoder: explicitly check addr/size for u32 overflow Date: Wed, 2 Oct 2024 16:52:45 -0700 Message-ID: <20241002235253.487251-4-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241002235253.487251-1-stephen.s.brennan@oracle.com> References: <20241002235253.487251-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: BN8PR16CA0016.namprd16.prod.outlook.com (2603:10b6:408:4c::29) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|SA2PR10MB4458:EE_ X-MS-Office365-Filtering-Correlation-Id: 76bbe1aa-cc96-4be3-f124-08dce33d5b70 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|10070799003|376014|366016; X-Microsoft-Antispam-Message-Info: Bc0RfEM/XIDWEPzH0kxR3nYsysgFfju3sNBESRA1RgZR69Cu/+oChEMxacBeQ5Eq55eS52KQTH0s68njpAxS+6geARMDRRoFTFzmwGkWYyzxPt2rli/ehJbHWVDUuLOyE6jvD4hRJpkbuMtgk+oud/OFOiJb1lAXPLmFVRpizUKjQ5SfTtuu8qqCbLgQZIMylHesxPzhHttspv53yHQb+ZGJ055OIvpagSAyQIvwjBodUMdwf7hWlR+tUM++D0FGq08suFzQ1hCKUpsoJ+HQf7fQOniv3FbaynxhcwpKK+MwX9DC6jakNKEem208e5ftWMO84PP8kmVEqIjxqqjCenFqRah4vENOrtVfHAOg3c7nKiWVpSa2D2H7PvVMyweDmXGgQc5HWu5tuC35XKXbe8H9M/D1hwygnwJ+TwYJV/v/u4MLIYAuFZJScq8rwevpltqhEMv8FB1jWf57qVi8hkcxUpAQvrKi/0+R7ZSr/Th9BZQJkwIjSHZihBalh5QxRbppIJvYCsLUzeVOhiC/H1pOzcEFbTfummyFoIy/E6Dq/7nDdjb0r8uYe5ZiE2Xbhirb4wfwRbQwpC3WlTnAGt9wyAg5G/cfbHwisZOJWJ+CC/HbrS+i2oGNY02MDPULZDE0X+nwXrgMLP0Lwifmgoj02Zqck8c50xGjq3h79sCLtrj6sEI5Czg7DGPm1CJ6KfgnJNT8T0smATUN8hFFCqGckyeLCkgq+AUL4VxQF9aAtC/CsoQzNtp7MKytumGIbv7cU8JD4UfhA7gAoap1OpDuvf/o/jg3qYJ9jZETR38N2TdZB/MmzBa9AeJWHmYndBPBhdi+jJUMK/6rKcaGYQKaTEn9xAO/9pLLEJzBeX3aatu7+QfHWQyoVWLGhQ80G1SZ8dawiQgPs6TezRPMFf9E9NpyyC7Qi13obrHQIvh7URBrL3DEUpPJGWzQxRd8Qji186O26jfKvDAyYilA9P3S84JXWq+bs5Ol0Cn/QsxzH/8baOJe0o1nNYJMgmbfam2mAaTZjjqVQ87tzFd2P2LxgLkBYWXq5gVt4insAufnhLRG6tb8azF7OE4zV0TIFazqvGwq3DtJSxJ5LTlidchYHq7HiNbLe2mEr34C3nXXES4Oj3ZkkMLsV9ncsrODbgN1B1+/LjAJA7L+fTPY/E+bUIvl0jS/dIvl2SS7A0i8BJuQtocymf+4lsI+cx8gb/PCuNas1kIei7ScPSo9T8Hp1bZ6qIbe/R6a7GbB4iec8/AdpK2TQrjl9LjQRi1HjIetMELNpOdn59GTs1icRg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(10070799003)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BEiVGpsau8f3wBe2mZ+IjivMIJvJZdvvr2Lr1WVHtOOB5m6UpLK8fGVUAylwJYJUpLJGSZ+ApVrtK1kSDL5Krh+wjpx+Vpn07mcrEgYwlig0XxsXAMWrZT9LS9ZkHopCg9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Bj0f0sTHDY6dNnN9Ii+gfAVYk4WCYVz1A1Phr+tp14jpAh/71bc5k1FUX8m67amFBU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 76bbe1aa-cc96-4be3-f124-08dce33d5b70 X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2024 23:53:04.7882 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HLqWpYriTE3byQi965XdqvSFktkQmTYo/7MAQL5uPePfGz6SDp5njSFOZDy5OByWb+3950NFXI8K0SySLEWAan3qBIAoL7Ot85lKHFz/o00= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4458 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-02_21,2024-09-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2410020169 X-Proofpoint-GUID: -nzxc_7L1cF7bOvmJQWTs0cqMuxSIzV5 X-Proofpoint-ORIG-GUID: -nzxc_7L1cF7bOvmJQWTs0cqMuxSIzV5 The addr is a uint64_t, and depending on the size of a data section, there's no guarantee that it fits into a uint32_t, even after subtracting out the section start address. Similarly, the variable size is a size_t which could exceed a uint32_t. Check both for overflow, and if found, skip the variable with an error message. Use explicit casts when we cast to uint32_t so it's plain to see that this is happening. Signed-off-by: Stephen Brennan Reviewed-by: Alan Maguire --- btf_encoder.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 31a418a..1872e00 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -2250,9 +2250,16 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) tag = cu__type(cu, var->ip.tag.type); size = tag__size(tag, cu); - if (size == 0) { + if (size == 0 || size > UINT32_MAX) { if (encoder->verbose) - fprintf(stderr, "Ignoring zero-sized per-CPU variable '%s'...\n", name); + fprintf(stderr, "Ignoring %s-sized per-CPU variable '%s'...\n", + size == 0 ? "zero" : "over", name); + continue; + } + if (addr > UINT32_MAX) { + if (encoder->verbose) + fprintf(stderr, "Ignoring variable '%s' - its offset %zu doesn't fit in a u32\n", + name, addr); continue; } @@ -2285,7 +2292,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) * add a BTF_VAR_SECINFO in encoder->percpu_secinfo, which will be added into * encoder->types later when we add BTF_VAR_DATASEC. */ - id = btf_encoder__add_var_secinfo(encoder, id, addr, size); + id = btf_encoder__add_var_secinfo(encoder, id, (uint32_t)addr, (uint32_t)size); if (id < 0) { fprintf(stderr, "error: failed to encode section info for variable '%s' at addr 0x%" PRIx64 "\n", name, addr); From patchwork Wed Oct 2 23:52:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13820574 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AE751A01B4; Wed, 2 Oct 2024 23:53:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727913203; cv=fail; b=cKyiGJILLxtZaAeButMT2f0/ZCjP91gVhMZbYACtKMQlXGmlU203ZMD2rT+Ohron3CVowsDP47I3XUXZsmd/Nka9ADtG3yai+wiMUZqOx/qd9Y31jPjDt+bVPpF5p4iFbJ/cJS9glph0HmnEqc1Vozgv8gFjMJo5cJG96O0/2ag= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727913203; c=relaxed/simple; bh=2LG0Kq/wKCYRduoIOMMvC56m0jC3cG2PokpnnZBthf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=KJp9KZMgOFR8vQtn1QTMmo1+4GigMMCgC+X4Cyr9eWNoRRbO4m2FZI7KtuUPlIXpOxRg5lgsxUWSgU7XhWNAuB8UO0BSkJ5qqGgFyVIljPPvQMQ14/f6escUDvmQm4HaCKTsFfg5/EZDw994PFSZKHVXfz6+KyoJUjytF7SJmoI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=D9htrK4j; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=RJxly5JP; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="D9htrK4j"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="RJxly5JP" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 492Mg3NZ030406; Wed, 2 Oct 2024 23:53:11 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 :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=pVK6nXB9t2ffgoFJ0L8YrQqV0yMTmG/WqLknci9FUNI=; b= D9htrK4jucAKWVltBjHFOdqCUtAhbIzXrSHc138Szfs6dsaqH4T9IR3hUw7+hVlF 63vCGTJVk0D/Pk0jvkXCZtjJ7VEfqDgAkPsdA5oSeazQoVJzjBhU2mxME8QnX0nJ GKCFkwf+LyX6G49DuPKmusbx/DzyxKL4ym1sCy2laHQIn0niI7UBkN3gFyzAIIRb A+bc1pxd6O8erfpjSl6lz3Y493ub/ymuB4Oaipx+sy/3Z/2EQNAHZ4H6jBBUDwIU 0Kbpg32ySuEUDtY2y/9VT7wyR5CkGiMVBEd7R0X3g8zDoxZtlLWtVsjbkHrgRTRl TW/8Bb847VZLx300JDWmkQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41x87daufa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 23:53:10 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 492LeH8R028425; Wed, 2 Oct 2024 23:53:09 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2177.outbound.protection.outlook.com [104.47.56.177]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41x889r8p2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 23:53:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=H4R9T352ohKDu6ZH8Yqc7uHTgNm6xJDLSNCyzC9B3bNQZAx3GRa+5uoAmMWY5Az1KkNCGFo1UTPi8wy0JvK4FqrQ3pAaTOv7ootrHrrZJzVcxFNpQjY9kV7msCNdroP6+oiRd3wpvKRmWgMnIyyENRW9IJsmIlqz34JR7gkB+F8FkmXwF8ssIJnMtVSl6tYA2/NKuFJH0kWa8F52jt4zyc3ESSz7Qa+pjaETSh4jfoWI3WOawmVREHBOL6Pvtb0t8TO4qZy0hSbI2gpe4Nwsd7wNZo+3plQdKZdfpXGqLehY/ydYvycWnV7Icm8c+Sja+Mjyh7mvCFfP+di5KRMzyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pVK6nXB9t2ffgoFJ0L8YrQqV0yMTmG/WqLknci9FUNI=; b=Oo3Bh90o+Ag6enjPuyBmobD2rxbCxn5HYPVNB6Cig4yfjkQ0kicq1D2etaLbviWyfvdu9xPFxu18GPmuu36YbqFy03QCSjORtDokhlVfVvtMFQGTCxIhIgrGHvTBNQOYbo4ljR/+gUvFL8Ow2ak8mIqilaoVvPw3SV2Xs6EMWr5PLPTMQqnl1fmVnT/7jUhmyoh//9W5hBl7arXUnY8AslL/ZCKx9Uq1EQyEC5Z2Gk6QmAupqqxcj371sRhaBBIW8OhwEdZ+DwVw9/MtLPowp3eRrwwoMVMaaW9t56nVOghzdgwDL5SZyTTxt8tmNHq+LosiL3SEUardpniFRzn8ww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pVK6nXB9t2ffgoFJ0L8YrQqV0yMTmG/WqLknci9FUNI=; b=RJxly5JPJUCcv6Gaq6DLj26EhDQkS1Lo+Oc82OKif3GtFWM/pXlBdogqFTL/vazpvovnKXTVadnMkMf+lFezg2hzWSaKgOXCDq3MjgpQLr2r5cIIN1g7oIh33D86a3XUMJ7Opp0HghD3VQJ7PzV/9s3SA2l/8gSZQjhC8oJUJOo= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by SA2PR10MB4458.namprd10.prod.outlook.com (2603:10b6:806:f8::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.16; Wed, 2 Oct 2024 23:53:07 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8026.016; Wed, 2 Oct 2024 23:53:07 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v3 4/5] btf_encoder: allow encoding VARs from many sections Date: Wed, 2 Oct 2024 16:52:46 -0700 Message-ID: <20241002235253.487251-5-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241002235253.487251-1-stephen.s.brennan@oracle.com> References: <20241002235253.487251-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: MN2PR04CA0002.namprd04.prod.outlook.com (2603:10b6:208:d4::15) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|SA2PR10MB4458:EE_ X-MS-Office365-Filtering-Correlation-Id: 435c72a0-1b03-466f-f7d9-08dce33d5d15 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|10070799003|376014|366016; X-Microsoft-Antispam-Message-Info: QIHdMnulkk98I6opoAnFFkMyz1XPTpfbX6GQIwdxEtEe07+IDkyykWAGN0TeTCmwJ08GAafVXsuRtp3x0Ay8Lydn9AE7M3g2+6dpWlTChiHascs8eXp72pn/lwunlbyEyGO1xZzIC6XVWzaVXBDWitErH5wck90yiNSL93TqrCPspxYqS0AxwYk6qKKZ/yr1U24imp0ffFvhVEfi12KzeV4Vu4t1GRbYUMLnMrSzkLrYrQcuz2DN6g5IQ4lbE+tOiY9Y8ycmqsBVEA+BhFKaaLcI3ReBbtSv/M88gxiZxvnJDCcgMaUOAX07x0jGQzu0uED1KN48IgWKmaLf1rejIpaUG6+5wXaYiqQU8c/MSz56J2UVk8Vch3dWAoS7XGIAPy0C3qWAz+3hrgRae9XtkSa8yfcszsLSBO8hCjYiQFupeDaAs4fH5Bcs/B6u0nTbTHY3oFQtDP3kfl0qIpfQrAiZa+f5IWFNXj8mZ/QvJLyEaIjKzLNiugceHzDI85Eh/zQXVQ+fLAfK08LZXT9qsacMCa3T2lmfebPQrb6F5JDbz3OGSItYHD84SY+yiV7bXQ2Mb8PuZxWBuHjcLeqoWTlGktw1CAnqV0dKXDsD2mp2maof8VlnesY4XGSCBdMHeiV4xIyAZE36BowdpVbEONXPIoLZN87AsOYg4kbAA9L5XNwwgM3ZqWQ0DukpBODmRMAbwS1uANXnYDX6HGiYkPfDkaXJtA9KN9IGIMbNRpxD9TVoTte8RCCDA9SKprkq941qJJY7TdV6+GMS/xrWtof26Y53QNSZtxpHY/t6qQp762h5G5eBdAj96/xHSNcNwy2hkkyBixdnJM+hRXXJ1AtjeJfqna98/+eKSoYI58g4+5zOecFJe2YP1pQlVnSr8nDt5i+HRem+TXcQ0jbYHJDJdqaW7qJIQPTi6F/ZMN2VtZqlXf01GB8A3D0Zsj7tLcPS6C12t/qWUFtRh9k25twJ9KN3EDyhzNhp0y3FwcKlYvm/iN0LY8+1unkzcRAaSG7/rGsWcUWOamKRsIVtnSjgrxV93hCTjkSRSQj25t/QxMDAWWUhmYGRcTjtfpQQBNiDvv2CGtolIM4uVCO5YBGLZdvn9qpgiVGWGzL81cbtEmaNVpMZHyiwOeK/eGDpx3gj+szazB9e/608x2xjGOMurH16FdzwyLRqhubFbb/hMrA5x4K5V967Bd50m0fRvVyVE+0nS/bmcggcsOK55cIA6n1VGFQs2H8iRhFaw4J6rFnnpuOSOTo1jj93eCR180q/K/YrQ3emGELhg6XQXA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(10070799003)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1QLJ3XhqlDScJLmzURDujA2JrGVxJm+NLTRgbGG3pJKDM+iGirf2AdUTW/oMHj3eF3HKhj9YB0aMOUENJvm0O2JFU9eKwE0KhiUY2frWIvq/WJikcK6PfaJ1SyHhaLoZouXh7qWWVdqoJHfhOdXIt568ZPl31J+F112Z7xdhpxwWyzqLlsfu619pgqvxd1goFAu092Rsz4366jRG9bhHnkeJ9P4qD203NaItwqvckDz/GmrR3+Inbscyqo7iassczmKM+4vXbe84OiKKzLfHER+lySpIpEOhnzz5ZKiRQd3aHL5d7NoT+ualPFIQ196UznHepo74l0PsLAPnadCbXKFmrz0kaj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DCyBJKfBirvxS8cLJ9hb1V77dFEedKVXw4ylmm9e02AqkkXkBmAShiMplm6NE9v6eYpBBY6Q3BvWKtzjN99eEza6w2REE4xtRzMRIvQM5y0/yFZ9ezXIKUFcP/Ek82utd06qs1gnnFpnZ34dhe5ExuMYIsPjDyZVIqzj9hqU8fX3nWhvQFntNQI3iUgkuzhSM5gQTsy8O4EEUBBM= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: ijkvaQwgfyUnnU/t5LoI25gUaESAsC2irH7khHz7BKpKkkgYboSW4Po9izdQfVCRgEF7gQrdrnzK610hw64JGbQdb2hxXH5ZcW+/nH3caOtWl2xWwz0IWlvW7jY/Q6rOKGYabDPgTuTq4PpXHJqsZ0J1gkMqvcgrBABWffhn7t10o/lDH+A7ws5QRV1iBguy6zac0hAvrbXcu6aBuZMBrrgFga3bVrG44NLcFaSmZBOcC0YymXP0705TMg4G1vg3B4lImQ160BTh6/wsbj3+iAecEcxv840XHKCxVAHDo1QoO9EkjgoiWhYl6sdyGeZBcoKG3WbjXY6s/tM+tPUzG9VWO0kF58I/ddbGDYvxAE8ze+Dfbz+sQARVR3OybYlS4zYQDznFIEdday19h2+EizAKjYnnIaKtSbrPpOx3dLRIfbk/cUjzfUW81ostU+uFbplIwc6Qf1zRIi2MovH3ezIem5qvxV72Jzmb6/kO2Mm9oL/t04UpDlAWZzH7CJtw4Yrniqv/z2NN11iGVpvxOh0lWFoWdK1X7AcvMWXmpTyN8MdXDCTZ0mNENbFAHJqcDPvL3w26CdGKSiNtg5235QEmdOnCCCaKUIOOmBddBM0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 435c72a0-1b03-466f-f7d9-08dce33d5d15 X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2024 23:53:07.5691 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VABEwd93gZlucXYCYTb+99b4ajZ1YK0bwnqoOl+QPL7d0GL0hhkKIj0eQRQ/zVr32yQZWlczS8GCTomiEkI62xAUOP70as/XeKYPY5P4zL0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4458 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-02_21,2024-09-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2410020169 X-Proofpoint-GUID: 7lmhBFxJkObRe020vB_aMb3DAgHFNMwt X-Proofpoint-ORIG-GUID: 7lmhBFxJkObRe020vB_aMb3DAgHFNMwt Currently we maintain one buffer of DATASEC entries that describe the offsets for variables in the percpu ELF section. In order to make it possible to output all global variables, we'll need to output a DATASEC for each ELF section containing variables, and we'll need to control whether or not to encode variables on a per-section basis. With this change, the ability to emit VARs from multiple sections is technically present, but not enabled, so pahole still only emits percpu variables. A subsequent change will enable emitting all global variables. Signed-off-by: Stephen Brennan Reviewed-by: Alan Maguire --- btf_encoder.c | 90 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 1872e00..2fd1648 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -98,6 +98,8 @@ struct elf_secinfo { const char *name; uint64_t sz; uint32_t type; + bool include; + struct gobuffer secinfo; }; /* @@ -107,7 +109,6 @@ struct btf_encoder { struct list_head node; struct btf *btf; struct cu *cu; - struct gobuffer percpu_secinfo; const char *source_filename; const char *filename; struct elf_symtab *symtab; @@ -124,7 +125,6 @@ struct btf_encoder { uint32_t array_index_id; struct elf_secinfo *secinfo; size_t seccnt; - size_t percpu_shndx; int encode_vars; struct { struct elf_function *entries; @@ -784,46 +784,56 @@ static int32_t btf_encoder__add_var(struct btf_encoder *encoder, uint32_t type, return id; } -static int32_t btf_encoder__add_var_secinfo(struct btf_encoder *encoder, uint32_t type, - uint32_t offset, uint32_t size) +static int32_t btf_encoder__add_var_secinfo(struct btf_encoder *encoder, size_t shndx, + uint32_t type, uint32_t offset, uint32_t size) { struct btf_var_secinfo si = { .type = type, .offset = offset, .size = size, }; - return gobuffer__add(&encoder->percpu_secinfo, &si, sizeof(si)); + return gobuffer__add(&encoder->secinfo[shndx].secinfo, &si, sizeof(si)); } int32_t btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other) { - struct gobuffer *var_secinfo_buf = &other->percpu_secinfo; - size_t sz = gobuffer__size(var_secinfo_buf); - uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo); - uint32_t type_id; - uint32_t next_type_id = btf__type_cnt(encoder->btf); - int32_t i, id; - struct btf_var_secinfo *vsi; - + size_t shndx; if (encoder == other) return 0; btf_encoder__add_saved_funcs(other); - for (i = 0; i < nr_var_secinfo; i++) { - vsi = (struct btf_var_secinfo *)var_secinfo_buf->entries + i; - type_id = next_type_id + vsi->type - 1; /* Type ID starts from 1 */ - id = btf_encoder__add_var_secinfo(encoder, type_id, vsi->offset, vsi->size); - if (id < 0) - return id; + for (shndx = 0; shndx < other->seccnt; shndx++) { + struct gobuffer *var_secinfo_buf = &other->secinfo[shndx].secinfo; + size_t sz = gobuffer__size(var_secinfo_buf); + uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo); + uint32_t type_id; + uint32_t next_type_id = btf__type_cnt(encoder->btf); + int32_t i, id; + struct btf_var_secinfo *vsi; + + if (strcmp(encoder->secinfo[shndx].name, other->secinfo[shndx].name)) { + fprintf(stderr, "mismatched ELF sections at index %zu: \"%s\", \"%s\"\n", + shndx, encoder->secinfo[shndx].name, other->secinfo[shndx].name); + return -1; + } + + for (i = 0; i < nr_var_secinfo; i++) { + vsi = (struct btf_var_secinfo *)var_secinfo_buf->entries + i; + type_id = next_type_id + vsi->type - 1; /* Type ID starts from 1 */ + id = btf_encoder__add_var_secinfo(encoder, shndx, type_id, vsi->offset, vsi->size); + if (id < 0) + return id; + } } return btf__add_btf(encoder->btf, other->btf); } -static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, const char *section_name) +static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, size_t shndx) { - struct gobuffer *var_secinfo_buf = &encoder->percpu_secinfo; + struct gobuffer *var_secinfo_buf = &encoder->secinfo[shndx].secinfo; + const char *section_name = encoder->secinfo[shndx].name; struct btf *btf = encoder->btf; size_t sz = gobuffer__size(var_secinfo_buf); uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo); @@ -2032,12 +2042,14 @@ int btf_encoder__encode(struct btf_encoder *encoder) { bool should_tag_kfuncs; int err; + size_t shndx; /* for single-threaded case, saved funcs are added here */ btf_encoder__add_saved_funcs(encoder); - if (gobuffer__size(&encoder->percpu_secinfo) != 0) - btf_encoder__add_datasec(encoder, PERCPU_SECTION); + for (shndx = 0; shndx < encoder->seccnt; shndx++) + if (gobuffer__size(&encoder->secinfo[shndx].secinfo)) + btf_encoder__add_datasec(encoder, shndx); /* Empty file, nothing to do, so... done! */ if (btf__type_cnt(encoder->btf) == 1) @@ -2167,7 +2179,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) struct tag *pos; int err = -1; - if (encoder->percpu_shndx == 0 || !encoder->symtab) + if (!encoder->symtab) return 0; if (encoder->verbose) @@ -2180,6 +2192,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) struct llvm_annotation *annot; const struct tag *tag; size_t shndx, size; + struct elf_secinfo *sec = NULL; uint64_t addr; int id; @@ -2211,7 +2224,9 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) /* Get the ELF section info for the variable */ shndx = get_elf_section(encoder, addr); - if (shndx != encoder->percpu_shndx) + if (shndx >= 0 && shndx < encoder->seccnt) + sec = &encoder->secinfo[shndx]; + if (!sec || !sec->include) continue; /* Convert addr to section relative */ @@ -2252,7 +2267,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) size = tag__size(tag, cu); if (size == 0 || size > UINT32_MAX) { if (encoder->verbose) - fprintf(stderr, "Ignoring %s-sized per-CPU variable '%s'...\n", + fprintf(stderr, "Ignoring %s-sized variable '%s'...\n", size == 0 ? "zero" : "over", name); continue; } @@ -2289,13 +2304,14 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) } /* - * add a BTF_VAR_SECINFO in encoder->percpu_secinfo, which will be added into - * encoder->types later when we add BTF_VAR_DATASEC. + * Add the variable to the secinfo for the section it appears in. + * Later we will generate a BTF_VAR_DATASEC for all any section with + * an encoded variable. */ - id = btf_encoder__add_var_secinfo(encoder, id, (uint32_t)addr, (uint32_t)size); + id = btf_encoder__add_var_secinfo(encoder, shndx, id, (uint32_t)addr, (uint32_t)size); if (id < 0) { fprintf(stderr, "error: failed to encode section info for variable '%s' at addr 0x%" PRIx64 "\n", - name, addr); + name, addr); goto out; } } @@ -2373,6 +2389,7 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam goto out_delete; } + bool found_percpu = false; for (shndx = 0; shndx < encoder->seccnt; shndx++) { const char *secname = NULL; Elf_Scn *sec = elf_section_by_idx(cu->elf, &shdr, shndx, &secname); @@ -2383,11 +2400,14 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->secinfo[shndx].name = secname; encoder->secinfo[shndx].type = shdr.sh_type; - if (strcmp(secname, PERCPU_SECTION) == 0) - encoder->percpu_shndx = shndx; + if (strcmp(secname, PERCPU_SECTION) == 0) { + found_percpu = true; + if (encoder->encode_vars & BTF_VAR_PERCPU) + encoder->secinfo[shndx].include = true; + } } - if (!encoder->percpu_shndx && encoder->verbose) + if (!found_percpu && encoder->verbose) printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION); if (btf_encoder__collect_symbols(encoder)) @@ -2415,12 +2435,14 @@ void btf_encoder__delete_func(struct elf_function *func) void btf_encoder__delete(struct btf_encoder *encoder) { int i; + size_t shndx; if (encoder == NULL) return; btf_encoders__delete(encoder); - __gobuffer__delete(&encoder->percpu_secinfo); + for (shndx = 0; shndx < encoder->seccnt; shndx++) + __gobuffer__delete(&encoder->secinfo[shndx].secinfo); zfree(&encoder->filename); zfree(&encoder->source_filename); btf__free(encoder->btf); From patchwork Wed Oct 2 23:52:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13820575 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E0B71991BD; Wed, 2 Oct 2024 23:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727913225; cv=fail; b=UzE3zukf+EHVhukfZEo/IIAecc1px+15tn9nSDMR/AFhobZ/Sp54AGq/1DqSUjSIWnKkR+OG8ZP3s1Fb+CwWhU+kV7/PVPM45u+5696SOnJwr/tUNwqod9AET8uqeIgdW6Xb1t35hFALSvweKvEWZulN4pOAhVQIuLlSm0/JHJc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727913225; c=relaxed/simple; bh=rXmZNM2jSdpu1QBTzUbSsKG4v4v4hsVu7KYkODgReec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=VfHjJ7yDiS2PVdbjvuP/Mxy6Ay9RN+gPLhsiFnyb/W8N16alZnwQBSsLDsoCdyZ+h5oZ9mWIMUGi9jYmtPscHRSs+ocSXvbLVCkv+RkPFA/2Sl7bPsChhK6f6vyB97AjAZ5jEphjNsBvgqRb5KKHFGBjIHwacwug4uafjIXE5nc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=NmAtQPJn; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=EPJco+X5; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="NmAtQPJn"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="EPJco+X5" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 492Mfawv027744; Wed, 2 Oct 2024 23:53:41 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 :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=UAxRwZtx5V2p0Ij2CY0NVjRU6jWJ/jcPAJvafwzIleM=; b= NmAtQPJnkXEVdNLqbk9BqnVcvOff3cGmdxL81ZzLiqd16BuHHw9XOOQtfJXQmSdC 5usPAHXFx2uOtLcdC66Cd8cs7a8zAFg606UMKXtdNhf/zfRfcf/4CWawAIxzz4AL 9zFC5onUxkLGwCSlR2TL71pMQdteTOlWQCi5J7+qjo8Ou7KEmFhMkcABOsHZNMUl Cs0HQWDsAeFcUlq3fBKJolvVq8MEF3jGryypQ0ONd0eQ4bA/sTFO/eidmKztLnwf p+DvKHcZIYcXMgW0npoggtkcwnowQj0V2q+kZUqRiZmfSP9VRdxhN/L4GS9k+m4c +UfFPLfvK0UHPmualXNi9w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41x9dt2xg7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 23:53:40 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 492Lrv6D029452; Wed, 2 Oct 2024 23:53:39 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2101.outbound.protection.outlook.com [104.47.58.101]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41x889r8q2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 23:53:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Gn9LSHPQRdlRpyNTViDxiNS41i42p6lbip4KIHC28+ZwI3uUwOpwmk1k6F6Tx3sTSRW+PB76zxuCzXn7cIqVIPBko4zlIRjyPd06bXpQe6x3ohPhRi+s2PIfWJRciOx1TaTwGMs55jPv5xSwc/6TUYxH2WT9t81/w2wkfLvWfoHO0aBf3ywKGr31pVUxtIQOX3xQjXwnzGpapTKaxBEyjzkKhHFqrlpgKIyMQnFDrYMUUV0uWZ+FWynCbU4YRnn0pFSNhiy9yA03kk8MNEIcR+DrDA3pQjOdlpdizMrW9azl3DsJwsLej655L0X5ORGkjz///SSXAvdMleSzbrUN7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UAxRwZtx5V2p0Ij2CY0NVjRU6jWJ/jcPAJvafwzIleM=; b=JhfrnyF93+TpUYzSn6rnFKHD/+wYs6FiPzk0D5Hti+me6FkL8YYuslhcMerdnPnvQ1EK/3kvSQPLNwh+8VkHiH0anQ8zlBAbaV0UjB4t2mGPUET9Y21o+Y7dVWNhSUYO64uqkdBHThDearI0du2LKqi+3aU0EtR9hA18DcHEs8zDnk31sjZkzGmzhDxEMuudR+edoYUnng0WwFspBGefC77raXLu37vv5afSafWZdrAEVj+5AFS2FR20XYqg7soL38WwiA9kDFNza8MW9J42LANQ7nkhPjkJPbFFKcqanvS1yF1vrBZmCelpCeiX2Rqx+KfsSMn8WIcwnH7oR0eHjQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UAxRwZtx5V2p0Ij2CY0NVjRU6jWJ/jcPAJvafwzIleM=; b=EPJco+X570lPtOn//HDnmsBakExYqd1aSmciO5lbEy3KaLa8dYx/AQKTNhkBI2nkm/o9zf7JmElq+8yAoKH3HYopaKn+X+wj2v4C5VBRiESBQyHttDgCFaCiY8OGNTKFSBMWDYYJKZJR8YN29pZur6KqWTFd+1B4TH7/B2KNTaw= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by BLAPR10MB4834.namprd10.prod.outlook.com (2603:10b6:208:307::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.16; Wed, 2 Oct 2024 23:53:11 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8026.016; Wed, 2 Oct 2024 23:53:10 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v3 5/5] pahole: add global_var BTF feature Date: Wed, 2 Oct 2024 16:52:47 -0700 Message-ID: <20241002235253.487251-6-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241002235253.487251-1-stephen.s.brennan@oracle.com> References: <20241002235253.487251-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: BN8PR16CA0032.namprd16.prod.outlook.com (2603:10b6:408:4c::45) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|BLAPR10MB4834:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e397948-7af5-460a-896c-08dce33d5ecb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|10070799003|376014|1800799024; X-Microsoft-Antispam-Message-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xnG5ZAHB7FPcolzKKa5L+a3Q7ujEgyrUIlN36Y+3GixZ3ftYUHqcchjQRwRxPM8Y/nW2K+m9c0vAs/o9lQ6rhrpnN4cjbQaAFIEram+4bnCTLsc45HNOl4LRqGTqfKy2TUvrzFVhIj2qqpbDqHZ9Vjv95Ef0VJVj2M3ovvMcbYofWAbNWiLdfC8vRY/sr2obwDn24LA6ycycHx38ELC5g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(10070799003)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KYGtiSNaCTlkfH0QqdFIDnhlvis7L3pDrSzOqYIwHUhIdSYFnEz6/tKP53vORFBBcxjE0vYDiGFXlxiub4n5MZ75KokXye1ZJNefyawBDEUK/ZDCCVQtnUQKHd+6ffQ+GoTc7wMDqv1IKR1fUZEyoC7tUTqyR5fw2yUdXzYRSxNpaXc5bzRYw+KI4smq52nHhJ7PvVGeLmYxZsMEY1ihRWPp7wP/QPf8uafpW6JZFfBAMp2y7+XzGEBQIAKvvUxOnU3MMirOoH6TxkhXlnSNAvveNN4MoCLFspGqH4wZkiM58VzWnW9FGvxXciLzVqevKEzSxvr2J/reoLKe4cS44zj3TizpENz5g/X4klo3XlCZ5Q726Yj3P+LkSJR6KGkLGBmEBMCHuh8WYljLWxvXLdYKwei3XMs2gITbea7ePdBATOBB2XTptLBhNAXdMSNZGAqIzP/2fRTWGEv1c+YdamOOE5ng+tr5vG+fnF/eBPTL8WTDURfBE4mkfs4fyi65on0MCvTe12yvil5UG6dSL8b8OgPtoJWdVkjCRBHHakAX7Mng2R9fQvXxVjv7Kkv8p7ZAxg56BxkHEYj2H3SCYhK7lPo49FpEeG37kfxhVy18MlZlW8juvyUauk1iss0Bf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Data-0: lPws5/Ccsasrh2AxtzNorI2pI4TU/0N62ty18EQCDJqPv5kFJfI6zCRje3VmtbuIla3tiEbf8fI0C4acofDE9BIQacEJmYhTtz57TvCBODFiOrQBalMNj4QVHtMvt4iJQ9mp0+eoLG4SX82dNEU2OfKSvSayzA17eCLw+XTam9VapVWDP8jx5jScK+GkzfJ6YjDkgm108MUSdgH/svsKggWh78LQU5VaZIoDuc58hQbzXL6+do0oBfzVuAP6jf5JASHtOBbMxQPObLZIlLls/AjCEavaXGL1xMWVu6/y0FtZlGBh8wcY0R4vNcJPpI85cGWzwNSheEnheHULaH/gzLshaq+BLEv6qrUpUdV7AH1tPaU2dl0jTOm34MDAINltTkvh+X/fPG7WglbJJGrrvWmcxLJKnN7LLlBFhP3SVJkbBt/duHijJppZREBH/CaXsdFgI/cDbSPhtnZBkxENIGHopN+YYqh+4AiseCOWFlx3Q+g9k9hHylrToDZfj/KfA5rx4XdBxBQBsuApb6EujMPe+BFl61jCQdZzL+eiu4GlW2PQllZA4+3yoI4Iyy6RPZUOH31U6AtkqfB2aUEvH1oS6FHGFYakd95h5IMxteY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e397948-7af5-460a-896c-08dce33d5ecb X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2024 23:53:10.4112 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: U1jCU85C9NcprUVLbhYvCKAyLTH9i5/oMG2lKDBHlM5sceJ4Sm9T8WspyAhpAQUl0VnMY+yIHBhKSj2Ds020G3TkCFkBNNYJAwvkdMoV5K0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4834 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-02_21,2024-09-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2410020170 X-Proofpoint-GUID: 5mVxvaVoV1GHSwcdBGYS6Utpx7ip9e0b X-Proofpoint-ORIG-GUID: 5mVxvaVoV1GHSwcdBGYS6Utpx7ip9e0b So far, pahole has only encoded type information for percpu variables. However, there are several reasons why type information for all global variables would be useful in the kernel: 1. Runtime kernel debuggers like drgn could use the BTF to introspect kernel data structures without needing to install heavyweight DWARF. 2. BPF programs using the "__ksym" annotation could declare the variables using the correct type, rather than "void". It makes sense to introduce a feature for this in pahole so that these capabilities can be explored in the kernel. The feature is non-default: when using "--btf-features=default", it is disabled. It must be explicitly requested, e.g. with "--btf-features=+global_var". Signed-off-by: Stephen Brennan Reviewed-by: Alan Maguire Tested-by: Alan Maguire --- btf_encoder.c | 5 +++++ btf_encoder.h | 1 + dwarves.h | 1 + man-pages/pahole.1 | 7 +++++-- pahole.c | 3 ++- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 2fd1648..2730ea8 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -2348,6 +2348,8 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->encode_vars = 0; if (!conf_load->skip_encoding_btf_vars) encoder->encode_vars |= BTF_VAR_PERCPU; + if (conf_load->encode_btf_global_vars) + encoder->encode_vars |= BTF_VAR_GLOBAL; GElf_Ehdr ehdr; @@ -2400,6 +2402,9 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->secinfo[shndx].name = secname; encoder->secinfo[shndx].type = shdr.sh_type; + if (encoder->encode_vars & BTF_VAR_GLOBAL) + encoder->secinfo[shndx].include = true; + if (strcmp(secname, PERCPU_SECTION) == 0) { found_percpu = true; if (encoder->encode_vars & BTF_VAR_PERCPU) diff --git a/btf_encoder.h b/btf_encoder.h index 91e7947..824963b 100644 --- a/btf_encoder.h +++ b/btf_encoder.h @@ -20,6 +20,7 @@ struct list_head; enum btf_var_option { BTF_VAR_NONE = 0, BTF_VAR_PERCPU = 1, + BTF_VAR_GLOBAL = 2, }; struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, bool verbose, struct conf_load *conf_load); diff --git a/dwarves.h b/dwarves.h index 0fede91..fef881f 100644 --- a/dwarves.h +++ b/dwarves.h @@ -92,6 +92,7 @@ struct conf_load { bool btf_gen_optimized; bool skip_encoding_btf_inconsistent_proto; bool skip_encoding_btf_vars; + bool encode_btf_global_vars; bool btf_gen_floats; bool btf_encode_force; bool reproducible_build; diff --git a/man-pages/pahole.1 b/man-pages/pahole.1 index b3e6632..7c1a69a 100644 --- a/man-pages/pahole.1 +++ b/man-pages/pahole.1 @@ -238,7 +238,9 @@ the debugging information. .TP .B \-\-skip_encoding_btf_vars -Do not encode VARs in BTF. +By default, VARs are encoded only for percpu variables. When specified, this +option prevents encoding any VARs. Note that this option can be overridden +by the feature "global_var". .TP .B \-\-skip_encoding_btf_decl_tag @@ -304,7 +306,7 @@ Encode BTF using the specified feature list, or specify 'default' for all standa encode_force Ignore invalid symbols when encoding BTF; for example if a symbol has an invalid name, it will be ignored and BTF encoding will continue. - var Encode variables using BTF_KIND_VAR in BTF. + var Encode percpu variables using BTF_KIND_VAR in BTF. float Encode floating-point types in BTF. decl_tag Encode declaration tags using BTF_KIND_DECL_TAG. type_tag Encode type tags using BTF_KIND_TYPE_TAG. @@ -329,6 +331,7 @@ Supported non-standard features (not enabled for 'default') the associated base BTF to support later relocation of split BTF with a possibly changed base, storing it in a .BTF.base ELF section. + global_var Encode all global variables using BTF_KIND_VAR in BTF. .fi So for example, specifying \-\-btf_encode=var,enum64 will result in a BTF encoding that (as well as encoding basic BTF information) will contain variables and enum64 values. diff --git a/pahole.c b/pahole.c index b21a7f2..9f0dc59 100644 --- a/pahole.c +++ b/pahole.c @@ -1301,6 +1301,7 @@ struct btf_feature { BTF_DEFAULT_FEATURE(decl_tag_kfuncs, btf_decl_tag_kfuncs, false), BTF_NON_DEFAULT_FEATURE(reproducible_build, reproducible_build, false), BTF_NON_DEFAULT_FEATURE(distilled_base, btf_gen_distilled_base, false), + BTF_NON_DEFAULT_FEATURE(global_var, encode_btf_global_vars, false), }; #define BTF_MAX_FEATURE_STR 1024 @@ -1733,7 +1734,7 @@ static const struct argp_option pahole__options[] = { { .name = "skip_encoding_btf_vars", .key = ARGP_skip_encoding_btf_vars, - .doc = "Do not encode VARs in BTF." + .doc = "Do not encode any VARs in BTF [if this is not specified, only percpu variables are encoded. To encode global variables too, use --encode_btf_global_vars]." }, { .name = "btf_encode_force",