From patchwork Tue Feb 4 23:10:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Indu Bhagat X-Patchwork-Id: 105999 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 071D23858C56 for ; Tue, 4 Feb 2025 23:11:18 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 8938F385841C for ; Tue, 4 Feb 2025 23:10:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8938F385841C Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8938F385841C Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1738710653; cv=pass; b=lizSuvt+yAmCdwJUBec/xsHKPllR5orVnpIypOXKopVV8HNl2vM/SpawiV7FT0QPOrE7IW9MWUBQA+x50UbNi8KqpgV3om3RmuRkIajZj0gqoLdPDPWdhdJ1O0oPhAbcVrCAz3T16eyJhvGxpeMXB4mc3pxJW0j8rdTTeHlzeMY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1738710653; c=relaxed/simple; bh=4XG66mJx/JE9U5x+d5u7zTdMOah41zGp0wBtIijM/Ho=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=hQfXR20gnP8LIlhDWP/Rz19P3j15qAEaz9cm8iK8G8Y+w02DkV0a6rVoJbjAIHtP7YlSuTj5bMjD4i3YTO0icifWJrJLzTuBHOZGmWucM2pJg1sjcPZ/cUh+Uono4DWe3E8VKG+CbcNAHIqERCed8YixeCxKi+kug2iHIlEMBQA= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 514N0j6x011183; Tue, 4 Feb 2025 23:10:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=o1lep9EBj7ZGLyNPmppl1oP4EDLNo5G2oZE/brhLF8s=; b= Phdtf/D9js2+kN6pN6bH/jYag2bEsHWaqZVnXkquI9FAzjo7UMnUrZv0hwcy7Zi2 uQUg5wZr5uf4nHlmfKPdjrcfTGrbp4deFkXLXFTbg/dv+u/Q8fEyCr57w9wswd0y F+SHIfpYki8zhC/nTI9NCGDnXJ+h1tlLZlIxNS2AOcIBLIpjsZw9l46sQPjqYin7 pSKjhnrNl+k/jgmoxDE+qkc1H9OO7D7sY/Tv2hnm03ooAWfN0QkhYoVRHUklUMvM iPfRYx2ynV+glEJeyUUE9FB/A9ensl1gq4af7DoyUny5d7TCaThw8rFehUulFUKV 9flA/s/4hP824jqhDwemEg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44hhjtwxay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 04 Feb 2025 23:10:51 +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 514M5gi6037710; Tue, 4 Feb 2025 23:10:50 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44j8ghma0s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 04 Feb 2025 23:10:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FViINOzNnhVKzXOBy9mVu5guAjPuh2NjHummvWiW0b9bqKTOAeaHu8SFuiJDG9ZKNbMa/yo88fQiYwDphmVfv9KzbmqIQ09Uwy6b8n0qXvwYXOJQCaLiIHJ+8nLgiJ5fIWhinLimg1W/e65Bebg/tvqwmAMNNQKmPZmyx+nC6GsNpLfXq0M9RRQEeTqZ9/ax8SNLG/7w9lwZ8SQx3xQI9E1tFBz3xkWGQ3XRMR++TeWB4Wob6hpBhUIrqpE0y2CFrUZ+/Qz/LmoDQ8iZ1QTOCl6cEPfhK+iJIg46qcvCwl9pTw1jjno1M1r90IEz07KTYtQ6OBzt3AMWNq3JkPLBsQ== 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=o1lep9EBj7ZGLyNPmppl1oP4EDLNo5G2oZE/brhLF8s=; b=WlDsOAn6ve3ICRxQuhtt2TO4hcl6WWETFx7+LH4AUusl3DtVnUaqyl8VPUt6pP9mjIO27eVs8nQQba+Tel+d/ifStUzJzynabbwc1P9ODy/VmHsWuLia/Ztxv1UcoQRbfKdaxv/OwWDv8Fo90eGCOCFkyoUHVAAA8CMf0ir7SSScbhAFkdW9/3flcijccttR/5i5fOEdw5NpPz2taaY5iT46523G7vD9X+kQI4Q6D9C+Y3/UocFLQ6lgxrvBJBWAL9pZwPAiJVN5Ph8fGebOJSISlN4YEt2Q91YVNyWIcNu5J5FdgUWCEVNwXjryImVwAUj+N2ENpUCow4VnoJcKDA== 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=o1lep9EBj7ZGLyNPmppl1oP4EDLNo5G2oZE/brhLF8s=; b=NAPLfIkrXqOi68m/Qi28eEb0HwcS2eadhtHyZyvEXx3W1wa8wTPPm+2rprWTZhiaq4YP3H6GYqBKtpKJVLsZmmhOMF/KhWxAIsL2e3n/JrTiATYt+LUDpt/YzegM0nIheJXcLoTdpvNupEI7Exdi2fweVS6LeAoyBHBnNIfuLJ8= Received: from SA1PR10MB6365.namprd10.prod.outlook.com (2603:10b6:806:255::12) by DS0PR10MB8197.namprd10.prod.outlook.com (2603:10b6:8:1f8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8398.26; Tue, 4 Feb 2025 23:10:48 +0000 Received: from SA1PR10MB6365.namprd10.prod.outlook.com ([fe80::81bb:1fc4:37c7:a515]) by SA1PR10MB6365.namprd10.prod.outlook.com ([fe80::81bb:1fc4:37c7:a515%4]) with mapi id 15.20.8422.010; Tue, 4 Feb 2025 23:10:47 +0000 From: Indu Bhagat To: binutils@sourceware.org Cc: jbeulich@suse.com, jremus@linux.ibm.com, Indu Bhagat Subject: [PATCH, V2 2/2] gas: sframe: partially process DWARF expressions in CFI_escape Date: Tue, 4 Feb 2025 15:10:24 -0800 Message-ID: <20250204231024.3168487-3-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204231024.3168487-1-indu.bhagat@oracle.com> References: <20250204231024.3168487-1-indu.bhagat@oracle.com> X-ClientProxiedBy: MW3PR06CA0016.namprd06.prod.outlook.com (2603:10b6:303:2a::21) To SJ0PR10MB6374.namprd10.prod.outlook.com (2603:10b6:a03:47f::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA1PR10MB6365:EE_|DS0PR10MB8197:EE_ X-MS-Office365-Filtering-Correlation-Id: cead1e13-b76a-4c2f-1914-08dd4571281b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|10070799003|1800799024|376014; X-Microsoft-Antispam-Message-Info: bu1gbc1+b79Lhqt1eQo5E1dN5gIELi+R6SUhEO8IZUcCGUDruVUeHuGZXI6gDHMR0PoLsZF2t+1opv0jksItwF1llQuengO2xGZNUq2Dw2FyoByySClUsLwVypZ+V861lhDQ36ZSd0MebRE1R8cX9EwOUwhyjPWhA3pJu8aMtH/XdePNWbiS17drxwMvvAn6QoemECnYLN9n/wq6RP60h6TYUcH3C1jFuA4QIEqRcKFfgAg1XxcYzMvEegWlb85pW/Q4ih9366l6wvlISX0kPjJlaS8tZMltowKaCiWyoVO3x4kPztVqJlRcxUybMC7Bx6oO1Y0B6V67Q+bDzxkrW6sVjfTbwVX15RgI5ju+RVXWn1TdbX+eBOCgkMmwCHMyRrz0DT/HlxBVqfSEpwbIwvduC6GMR+OD7os42nVKyEnINOuo2YbeBkpPgABt7LyLaUd3uosEvjc+hBBzuSR9ojA7J1CLMf0dKrpZiv4bYwl5NYPNZxFT4poW6pqVDresixBw2E1bMVeUawe17CTcR79glLfFOWMt6az+t32S3YQAnueVHYNc2qcCu45B2cfm2Q5m+QFtSQR8ERSSSCaXmhlO5RmZhBJ3etvgo8a5SP+76WQxQ5sFhFoimPURNeW84zcoDuLt4gVUj3mep1r0YOlF2MUkyCk7ykndMHgnbW0hqTL07fK4/odY7yO0NYLkUc6pox61wIUWw9863TYDMV+Ba3hPTPNgHMIKDUewICoa0iANHrYXKGCLl5c/WFbTwpbeoG8+s7fnMM1scnR5zVQYJLAlZciCHUJXuWZB/VFk5JW9F444pLUp9w7HA7EO8XXj+OFG2kL1zGNHYVST+hT4FXHxaKaX2RWlOt2BL1hJ0fwOEdMZQdIunxAZdyqhin9L60329qcxfE039EPSlQdw4gLVA//vdsa+AAps/L/qgxUkR6vUNDIfcXPkif9ecsKlDJ3L5Dmm6VK1NqSVHrYvt3yaw2bDSFjK7tq6TEah/QshSKZ4SZHSdLV0N7o9mBNTNHHaYVd99AcRPBq7KYUKJWxSAt17qHVev5zq7LBLGdfJT3NTNg5ZwOc4H97uGNKnzcl5xLPOAoyKrVIBC4x7HiOWLwErCO0Gprcmjego8PtjAYPUffLonalui0F5ZVCoda2QtmNS3hdunBfS3b+ulvo6ejQcJ+1NiXY7udQOaR9h2S+kAo3fSXYzmAOf9hY6HbizyZGopzW9W7fbLECpsqz1IuFyRI6FSacjQY1WV9OWSrOUaEZ+syiOXOdroSzi8H9gbnnECEF2EJxZJBrrbYarX4IdlfiPNVhmsnWGaC0NL9/n8GacwqrSBaUlHAjz+L6sxASz90ys5QjsRoahiNS8iwGbxzlUccFstgPYDUU7IFLBoptFLoYZFVwn X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA1PR10MB6365.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(10070799003)(1800799024)(376014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ylS2It7Po3NbAmG7/87uf4wLg4B4gpDJUbfDDWd4zmp6c5YrZXEq9wpCsGFu/P0aqT2u7T8tyDiMGUOk1BmQAWCN2vd/+0zr0bFpgXrjZrHVfi1SIgrGBgQqhQGvUrx0s74GgaGBrDN8nBZ+Sl21nRtNRAL/Se9G+nZSw+riFxMzTO0Pq5W7MmXGWfJFa8aDECL3ZtZc+xpVWEwMdw42ZMQiEban5ecC2wo/Kf8OR48g8RpaL552yBSYWBQVpqboxAnc7b9BW2/aeiUKwan1EZjY7KFUxCHwvJIyHzWR/gTg/Z1KgI0eu3V2g4fJhA/lGKyayfNECMSXwQZjhMmztcfcy7oLHAJe/7R4bSv+r4ZNoybJU/sthtoOer324gvSX6dm5nWLBxf8xgsolNLmZMi50Etzrm2kUmLV8eQm24vhZLARXMPNi5GhiRFBfvzONGaFnqBllL6X8aJ+QdoeBKMPZLr0ZRGh7C+i+lV0hhWpt+XKtzkm20T1beBDn26WCPr7mbU/vifKMu89ktbHRW8QGvLdTiHQdSi4oFuJJ5tdicqmzcj1KY1JsfWZxNEp7ykgM85y4FE4OAdAxeJZgO8olCs6TmCHz9x2aCZEGZmRjU0o2BVCWL68YqjYucXkhuiPRq35LtVmnMmXOTyDlIsoAyxzi36qF2BxEJphdiuR+coqx7OMfTr7yOsnBbKAbOVF6K0tiERJMRTueeP3RKIuIJCVTmwmViDVKoY44aWbK74Qb3/xM8a3YP0sDezqH4Ks0b0GpK5NXiWByvUT7jwJoj7Cb+VkEGGzeT5izLrIgdIp9ztbVLdwNcx/8W68AR9ClAtlBmadiY7G/QJZFtQjecH18cra+QRBtlDBrEMW6k0M/C2ooDVJkZnEhfrNyLzWtaKkBOmmU5GKPRkIMVT5xnhW0RR8mYb1Y/qU7fPwKblTk2JQTDLTN7jotFylgeApeOIxplU+k5fBCzs9zyMG3aJRpzdGHDaR4PjVIM6fO9DjRjoOYAjb3djkAkf3w6htxoS/K00Mpc9s9DQbdpT4I3VUdl+3g19ove3HsxIiFeIWnIIike5hssmKgGdfL2zLguBanW3XTTpKuMU/hW3pfRu3RhJH540HIIPTrfJpuMGOahS5sGSJCFUd02ul0g/e8cm1Cnqp/exqWrIhzzXnxRJ02A96jquvBMv7PYh+sE+PMLVlcW5jom11Wbf9AnoWWWiHnNfNHW1zAKVf4zIuTehCxRyKZf1q/xPrEIY+lubJujKYnZ9NLrQOfIc+V3TXWwxvM6Aal4tk1H9AdewwtG9jFeqeAVC6kirxPg8RIE0C4cbI3GQ5aG+7Rmnm5TsV0sOOpTlO75EsvdNjCN06eM7fkKC1bQOeiJnZXvlYepG5tW7GIiXEXtd64Z9qAH/6bXSMRQh+OTSiHt+uhlzONHTjP2wmXO29zcdOjx/kr1+OfU6D3prduhOPoqWrPhf19+U7ueWwmFS5L2wcYtGciVyV+jBEwciF4BQJk+xOpvB6zZdzi20k3qY5CduSHFd5Nx2RBSOQqKXSj1fuQkvX+TNk0kNYb553msjI5EdTDi/TVjeZpep2JXESkVAuQ8H4XJHraehBJ6jEr7iY5o0JlxoX/5ec8CNn7Y89uag= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: E7A3ANez08iMx3/+2CCP7Yz0kYWO/8lReIiGJcuYt9YiyZL0sbn2OQLooPKdo2eMJRmaRlFWeUY90efRfCA630y7boyKwh7R3WFKXfyKLjDFeatICEHZz70ja7SpiXMrtisFK3B6IsWGfuq54clotXSdz5nLpHk+8E3jw98a+cFhX61wxaNJuQuSK9imrIBBsLJbVvVWL4/hDLUFzxWPrsj4yd+sT30jPujrmdBMNZ2SkiLxnAtR8lpWpbWAPWHUptUQVf/8GmB1teF3cmdacc6KpyQD2BBBSatyW1vslGvzy3IGLtUZA4lay+6qX72W6lBiPu+8t4/PVyu3qnDsV2QBqKXwnlHksmzfLFfu3h4UMUUP/quxuwM3Rmb1SnG0xS9luCbcHJKXM1b30nyM5EOA4CcNhRpwvOranGCp7eXww0U3KSK3xd1WvLRQ700lPL2Qt2r0snJVprC7iS3apy06wKChJkq22mNWZM9Frqs5zRM1jkze0RZTGdFwYru0vMwKQAVNxhIql9c09uPDFeoNXG37iVgKj6OmPK+ushja6V2RGI1sVrtCXS9B7WhDStR6m3NrLhiY3mMOYjMRjHRRlgeafM7n1qovLO2SoQE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: cead1e13-b76a-4c2f-1914-08dd4571281b X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB6374.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2025 23:10:47.7201 (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: sB9aRDIeCjXepmzH0hlSBrIAjSUtZLgWN6CrYs57TCfGEuSiQRkYuuiQ38CJWQ7FCzQQRFMAsb8jR9AMMG8eYw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB8197 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-04_10,2025-02-04_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 phishscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2501170000 definitions=main-2502040173 X-Proofpoint-GUID: WNC-HDKGgUDZAqs1Gg6CoECORlg7rAHm X-Proofpoint-ORIG-GUID: WNC-HDKGgUDZAqs1Gg6CoECORlg7rAHm X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org [Changes in V2] - Use pointer-to-const when applicable for local vars. - Early exit if there is no cfi_escape expression. - Restructure functionality to accommodate the fact that a valid unwind info may be split across multiple .cfi_escape. If this is the case, the current implementation bails out. Handling this case does not appear to be worth the effort. - Include checking with SFRAME_CFA_RA_REG because we need to detect the cases when .cfi_escape can affect RA. - Use if conditional instead of assert block. [End of changes in V2] CFI_escape is most commonly used to include DWARF expressions in the unwind information. One may also use CFI_escape to add OS-specific CFI opcodes. Up until now, SFrame generation process would skip generating SFrame FDE at the mere sight of a CFI_escape opcode. Fine tune the handling of CFI_escape for SFrame generation by explicitly checking for some "harmless" (in context of SFrame generation) CFI_escape DWARF expressions: - DW_CFA_expression affecting registers of no significance to SFrame stack trace info - DW_CFA_value_offset affecting registers of no significance to SFrame stack trace info Expose the current cfi_escape_data structure in dw2gencfi.c to the relevant header file to allow SFrame generation APIs to use it too. In future, SFrame stack trace may support non-SP/FP as base register (albeit in limited form). Add an explicit check in sframe_xlate_do_escape_expr (to test against the current CFA register) to ensure the functionality continues to work. Also, add a common test with DWARF reg 12 which is non SP / FP on both x86_64 and aarch64. gas/ * gas/dw2gencfi.c (struct cfi_escape_data): Move from ... * gas/dw2gencfi.h (struct cfi_escape_data): ... to. * gas/gen-sframe.c (sframe_xlate_do_val_offset): Include string for .cfi_escape conditionally. (sframe_xlate_do_escape_expr): New definition. (sframe_xlate_do_escape_val_offset): Likewise. (sframe_xlate_do_cfi_escape): Likewise. (sframe_do_cfi_insn): Handle CFI_escape explicitly. gas/testsuite/ * gas/cfi-sframe/cfi-sframe.exp: Add new tests. * gas/cfi-sframe/cfi-sframe-common-9.d: New test. * gas/cfi-sframe/cfi-sframe-common-9.s: New test. * gas/cfi-sframe/cfi-sframe-x86_64-empty-1.d: New test. * gas/cfi-sframe/cfi-sframe-x86_64-empty-1.s: New test. * gas/cfi-sframe/cfi-sframe-x86_64-empty-2.d: New test. * gas/cfi-sframe/cfi-sframe-x86_64-empty-2.s: New test. --- gas/dw2gencfi.c | 6 - gas/dw2gencfi.h | 6 + gas/gen-sframe.c | 181 +++++++++++++++++- .../gas/cfi-sframe/cfi-sframe-common-9.d | 22 +++ .../gas/cfi-sframe/cfi-sframe-common-9.s | 17 ++ .../cfi-sframe/cfi-sframe-x86_64-empty-1.d | 17 ++ .../cfi-sframe/cfi-sframe-x86_64-empty-1.s | 10 + .../cfi-sframe/cfi-sframe-x86_64-empty-2.d | 17 ++ .../cfi-sframe/cfi-sframe-x86_64-empty-2.s | 12 ++ gas/testsuite/gas/cfi-sframe/cfi-sframe.exp | 3 + 10 files changed, 280 insertions(+), 11 deletions(-) create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-common-9.d create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-common-9.s create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-1.d create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-1.s create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-2.d create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-2.s diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c index 012af0ff33e..41e15cd1463 100644 --- a/gas/dw2gencfi.c +++ b/gas/dw2gencfi.c @@ -368,12 +368,6 @@ generic_dwarf2_emit_offset (symbolS *symbol, unsigned int size) } #endif -struct cfi_escape_data -{ - struct cfi_escape_data *next; - expressionS exp; -}; - struct cie_entry { struct cie_entry *next; diff --git a/gas/dw2gencfi.h b/gas/dw2gencfi.h index 42eb3863a0a..9b0e5979c0d 100644 --- a/gas/dw2gencfi.h +++ b/gas/dw2gencfi.h @@ -93,6 +93,12 @@ extern void cfi_add_CFA_restore_state (void); #define MULTIPLE_FRAME_SECTIONS (SUPPORT_FRAME_LINKONCE || SUPPORT_COMPACT_EH \ || TARGET_MULTIPLE_EH_FRAME_SECTIONS) +struct cfi_escape_data +{ + struct cfi_escape_data *next; + expressionS exp; +}; + struct cfi_insn_data { struct cfi_insn_data *next; diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c index a592e0f718d..c06ae6b5a45 100644 --- a/gas/gen-sframe.c +++ b/gas/gen-sframe.c @@ -1121,7 +1121,8 @@ sframe_xlate_do_offset (struct sframe_xlate_ctx *xlate_ctx, static int sframe_xlate_do_val_offset (struct sframe_xlate_ctx *xlate_ctx ATTRIBUTE_UNUSED, - struct cfi_insn_data *cfi_insn) + struct cfi_insn_data *cfi_insn, + bool cfi_escape_p) { /* Previous value of register is CFA + offset. However, if the specified register is not interesting (SP, FP, or RA reg), the current @@ -1134,7 +1135,8 @@ sframe_xlate_do_val_offset (struct sframe_xlate_ctx *xlate_ctx ATTRIBUTE_UNUSED, /* Ignore SP reg, if offset matches assumed default rule. */ || (cfi_insn->u.ri.reg == SFRAME_CFA_SP_REG && cfi_insn->u.ri.offset != 0)) { - as_warn (_("skipping SFrame FDE; DW_CFA_val_offset with %s register %u"), + as_warn (_("skipping SFrame FDE; %sDW_CFA_val_offset with %s reg %u"), + cfi_escape_p ? ".cfi_escape " : "", sframe_register_name (cfi_insn->u.ri.reg), cfi_insn->u.ri.reg); return SFRAME_XLATE_ERR_NOTREPRESENTED; /* Not represented. */ } @@ -1310,6 +1312,173 @@ sframe_xlate_do_gnu_window_save (struct sframe_xlate_ctx *xlate_ctx, return SFRAME_XLATE_ERR_NOTREPRESENTED; /* Not represented. */ } +/* Handle DW_CFA_expression in .cfi_escape. */ + +static int +sframe_xlate_do_escape_expr (struct sframe_xlate_ctx *xlate_ctx, + struct cfi_insn_data *cfi_insn) +{ + const struct cfi_escape_data *e = cfi_insn->u.esc; + const struct sframe_row_entry *cur_fre = NULL; + unsigned int reg = 0; + int err = SFRAME_XLATE_OK; + int i = 0; + + if (!e || !e->next) + return SFRAME_XLATE_ERR_INVAL; + + /* Check roughly for expression of the kind + DW_CFA_expression: r1 (rdx) (DW_OP_bregN (reg): XXX) */ +#define CFI_ESC_NUM_EXP 4 + offsetT items[CFI_ESC_NUM_EXP] = {0}; + while (e->next) + { + e = e->next; + if (i >= CFI_ESC_NUM_EXP) + return SFRAME_XLATE_ERR_NOTREPRESENTED; + items[i] = e->exp.X_add_number; + i++; + } + + if (i <= CFI_ESC_NUM_EXP - 1) + return SFRAME_XLATE_ERR_NOTREPRESENTED; + + cur_fre = xlate_ctx->cur_fre; + reg = items[0]; +#undef CFI_ESC_NUM_EXP + + if (reg == SFRAME_CFA_SP_REG || reg == SFRAME_CFA_FP_REG +#ifdef SFRAME_FRE_RA_TRACKING + || (sframe_ra_tracking_p () && reg == SFRAME_CFA_RA_REG) +#endif + || reg == cur_fre->cfa_base_reg) + { + as_warn (_("skipping SFrame FDE; " + ".cfi_escape DW_CFA_expression with %s reg %u"), + sframe_register_name (reg), reg); + err = SFRAME_XLATE_ERR_NOTREPRESENTED; + } + + return err; +} + +/* Handle DW_CFA_val_offset in .cfi_escape. */ + +static int +sframe_xlate_do_escape_val_offset (struct sframe_xlate_ctx *xlate_ctx ATTRIBUTE_UNUSED, + struct cfi_insn_data *cfi_insn) +{ + const struct cfi_escape_data *e = cfi_insn->u.esc; + unsigned int reg = 0; + offsetT offset = 0; + int err = SFRAME_XLATE_OK; + int i = 0; + + if (!e || !e->next) + return SFRAME_XLATE_ERR_INVAL; + + /* Check for (DW_CFA_val_offset reg scaled_offset) sequence. */ +#define CFI_ESC_NUM_EXP 2 + offsetT items[CFI_ESC_NUM_EXP] = {0}; + while (e->next) + { + e = e->next; + if (i >= CFI_ESC_NUM_EXP) + return SFRAME_XLATE_ERR_NOTREPRESENTED; + items[i] = e->exp.X_add_number; + i++; + } + if (i <= CFI_ESC_NUM_EXP - 1) + return SFRAME_XLATE_ERR_NOTREPRESENTED; + + reg = items[0]; + offset = items[1]; +#undef CFI_ESC_NUM_EXP + + /* Invoke sframe_xlate_do_val_offset itself for checking. */ + struct cfi_insn_data *temp = XCNEW (struct cfi_insn_data); + temp->insn = DW_CFA_val_offset; + temp->u.ri.reg = reg; + temp->u.ri.offset = offset; + + err = sframe_xlate_do_val_offset (xlate_ctx, temp, true); + XDELETE (temp); + + return err; +} + +/* Handle CFI_escape in SFrame context. + + .cfi_escape CFI directive allows the user to add arbitrary bytes to the + unwind info. DWARF expressions commonly follow after CFI_escape (fake CFI) + DWARF opcode. One might also use CFI_escape to add OS-specific CFI opcodes + even. + + Complex unwind info added using .cfi_escape directive _may_ be of no + consequence for SFrame when the affected registers are not SP, FP, RA or + CFA. The challenge in confirming the afore-mentioned is that it needs full + parsing and validation of the bytes presented after .cfi_escape. Here we + take a case-by-case approach towards skipping _some_ instances of + .cfi_escape: skip those that can be *easily* determined to be harmless in + the context of SFrame stack trace information. + + This function partially processes bytes following .cfi_escape and returns + SFRAME_XLATE_OK if OK to skip. */ + +static int +sframe_xlate_do_cfi_escape (struct sframe_xlate_ctx *xlate_ctx, + struct cfi_insn_data *cfi_insn) +{ + const struct cfi_escape_data *e; + int err = SFRAME_XLATE_OK; + offsetT firstop; + + e = cfi_insn->u.esc; + + if (!e) + return SFRAME_XLATE_ERR_INVAL; + + firstop = e->exp.X_add_number; + switch (firstop) + { + case DW_CFA_nop: + while (e->next) + { + e = e->next; + if (e->exp.X_add_number != DW_CFA_nop) + { + err = SFRAME_XLATE_ERR_NOTREPRESENTED; + break; + } + } + break; + + case DW_CFA_expression: + return sframe_xlate_do_escape_expr (xlate_ctx, cfi_insn); + + case DW_CFA_val_offset: + return sframe_xlate_do_escape_val_offset (xlate_ctx, cfi_insn); + + /* FIXME - Also add processing for DW_CFA_GNU_args_size in future? */ + + default: + err = SFRAME_XLATE_ERR_NOTREPRESENTED; + break; + } + + if (err == SFRAME_XLATE_ERR_NOTREPRESENTED) + { + /* In all other cases (e.g., DW_CFA_def_cfa_expression or other + OS-specific CFI opcodes), skip inspecting the DWARF expression. + This may impact the asynchronicity due to loss of coverage. + Continue to warn the user and bail out. */ + as_warn (_("skipping SFrame FDE; .cfi_escape with op (%#lx)"), + (unsigned long)firstop); + } + + return err; +} + /* Returns the DWARF call frame instruction name or fake CFI name for the specified CFI opcode, or NULL if the value is not recognized. */ @@ -1384,7 +1553,7 @@ sframe_do_cfi_insn (struct sframe_xlate_ctx *xlate_ctx, err = sframe_xlate_do_offset (xlate_ctx, cfi_insn); break; case DW_CFA_val_offset: - err = sframe_xlate_do_val_offset (xlate_ctx, cfi_insn); + err = sframe_xlate_do_val_offset (xlate_ctx, cfi_insn, false); break; case DW_CFA_remember_state: err = sframe_xlate_do_remember_state (xlate_ctx); @@ -1406,6 +1575,9 @@ sframe_do_cfi_insn (struct sframe_xlate_ctx *xlate_ctx, case DW_CFA_register: err = sframe_xlate_do_register (xlate_ctx, cfi_insn); break; + case CFI_escape: + err = sframe_xlate_do_cfi_escape (xlate_ctx, cfi_insn); + break; /* Following CFI opcodes are not processed at this time. These do not impact the coverage of the basic stack tracing information as conveyed in the SFrame format. */ @@ -1413,8 +1585,7 @@ sframe_do_cfi_insn (struct sframe_xlate_ctx *xlate_ctx, case DW_CFA_same_value: break; default: - /* Following skipped operations do, however, impact the asynchronicity: - - CFI_escape. */ + /* Other skipped operations may, however, impact the asynchronicity. */ { const char *cfi_name = sframe_get_cfi_name (op); diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-common-9.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-common-9.d new file mode 100644 index 00000000000..80c92357073 --- /dev/null +++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-common-9.d @@ -0,0 +1,22 @@ +#as: --gsframe +#objdump: --sframe=.sframe +#name: SFrame cfi_escape test +#... +Contents of the SFrame section .sframe: + + Header : + + Version: SFRAME_VERSION_2 + Flags: NONE +#? CFA fixed FP offset: \-?\d+ +#? CFA fixed RA offset: \-?\d+ + Num FDEs: 1 + Num FREs: 2 + + Function Index : + func idx \[0\]: pc = 0x0, size = 8 bytes + STARTPC + CFA + FP + RA + +#... + 0+0004 +sp\+16 +u +[uf] + + +#pass diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-common-9.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-common-9.s new file mode 100644 index 00000000000..c93b8e66155 --- /dev/null +++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-common-9.s @@ -0,0 +1,17 @@ +## CFI_escape may be used to encode DWARF expressions among other things. +## Depending on the register applicable for the DWARF expression, skipping +## SFrame FDE may be OK: SFrame stack trace information is relevant for SP, FP +## and RA only. In this test, CFI_escape is safe to skip (does not affect +## correctness of SFrame data). The register 0xc is non SP / FP on both +## aarch64 and x86_64. + .cfi_startproc + .long 0 + .cfi_def_cfa_offset 16 +# DW_CFA_expression for reg 0xc + .cfi_escape 0x10,0xc,0x2,0x76,0x78 + .cfi_escape 0x0 + .cfi_escape 0x0,0x0,0x0,0x0 +# DW_CFA_val_offset for reg 0xc + .cfi_escape 0x14,0xc,0x4 + .long 0 + .cfi_endproc diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-1.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-1.d new file mode 100644 index 00000000000..01239944863 --- /dev/null +++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-1.d @@ -0,0 +1,17 @@ +#as: --gsframe +#warning: skipping SFrame FDE; \.cfi_escape DW\_CFA\_expression with SP reg 7 +#objdump: --sframe=.sframe +#name: CFI_escape with register of significance to SFrame +#... +Contents of the SFrame section .sframe: + + Header : + + Version: SFRAME_VERSION_2 + Flags: NONE +#? CFA fixed FP offset: \-?\d+ +#? CFA fixed RA offset: \-?\d+ + Num FDEs: 0 + Num FREs: 0 + +#pass diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-1.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-1.s new file mode 100644 index 00000000000..168ac06bc4f --- /dev/null +++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-1.s @@ -0,0 +1,10 @@ +## CFI_escape may be used to encode DWARF expressions among other things. +## In this test, a DWARF expression involving a register of interest (REG_SP on +## x86_64, which is also the CFA in the current FRE) is seen. SFrame +## generation, is skipped and a warning issued to the user. + .cfi_startproc + .long 0 + .cfi_def_cfa_offset 16 + .cfi_escape 0x10,0x7,0x2,0x76,0x78 + .long 0 + .cfi_endproc diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-2.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-2.d new file mode 100644 index 00000000000..482803b65a2 --- /dev/null +++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-2.d @@ -0,0 +1,17 @@ +#as: --gsframe +#warning: skipping SFrame FDE; \.cfi\_escape DW\_CFA\_val\_offset with FP reg 6 +#objdump: --sframe=.sframe +#name: CFI_escape with register of significance to SFrame II +#... +Contents of the SFrame section .sframe: + + Header : + + Version: SFRAME_VERSION_2 + Flags: NONE +#? CFA fixed FP offset: \-?\d+ +#? CFA fixed RA offset: \-?\d+ + Num FDEs: 0 + Num FREs: 0 + +#pass diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-2.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-2.s new file mode 100644 index 00000000000..90e1a7e0f28 --- /dev/null +++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-empty-2.s @@ -0,0 +1,12 @@ +## CFI_escape may be used to encode DWARF expressions among other things. +## In this test, a DWARF expression involving a register of interest (REG_SP on +## x86_64, which is also the CFA in the current FRE) is seen. SFrame +## generation, is skipped and a warning issued to the user. + .cfi_startproc + .long 0 + .cfi_def_cfa_offset 16 +# Equivalent to .cfi_val_offset rbp, -16 +# DW_CFA_val_offset, rbp, scaled offset + .cfi_escape 0x14,0x6,0x2 + .long 0 + .cfi_endproc diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp index b119b9da73d..fdf7d9518cb 100644 --- a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp +++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp @@ -78,6 +78,7 @@ if { ([istarget "x86_64-*-*"] || [istarget "aarch64*-*-*"]) \ run_dump_test "cfi-sframe-common-6" run_dump_test "cfi-sframe-common-7" run_dump_test "cfi-sframe-common-8" + run_dump_test "cfi-sframe-common-9" run_dump_test "common-empty-1" run_dump_test "common-empty-2" @@ -89,6 +90,8 @@ if { [istarget "x86_64-*-*"] && [gas_sframe_check] } then { if { [gas_x86_64_check] } then { set ASFLAGS "$ASFLAGS --64" run_dump_test "cfi-sframe-x86_64-1" + run_dump_test "cfi-sframe-x86_64-empty-1" + run_dump_test "cfi-sframe-x86_64-empty-2" set ASFLAGS "$old_ASFLAGS" } }