From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 56B993858D1E for ; Wed, 24 Jan 2024 06:40:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 56B993858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none 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 56B993858D1E 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=1706078459; cv=pass; b=PB+ZQ0lIIWSourD6lL5NJMr4SPMQEBdPJglItXwm/0vuKu6LzAZWJ+4rIQMBocEXl7FRaf3NIJlFIJmzMybPr4fCZ/Zgciu/BKQkStRQWLQcsOiauKfz3qk8HewYQaq+BE2hiDWZvRRyrZZtpzAaDv8WTbMGStq3Dpm9Duk0O80= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706078459; c=relaxed/simple; bh=KhTcbMDJtHgXixQNwqSpRj8+cmoKmy1+a8EG9AcRtEQ=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=xkRcTbHnobyROIaJSufU2Irqmr89+b294wRpfhlhs1QQq64VV6a5/MzEBdbMbPnAcQAvHJPQou1u68d0agv9c/TbvRvoey+PNZVTG5VAzB+sOO5ZiPpHDPN8H0fw4bE5hzRpAxhdrwBPBbzTyGwnWPFl1nzZuHlaecRhgIPYDns= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40O2x4UX017323 for ; Wed, 24 Jan 2024 06:40:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=qxqUn8PBZC4QpeZlqrnIVTofkA51X8mKMojtEvkKL2I=; b=fjAOIM1I2bJWK53OSSGP+LS2h/Qz7keSitePRqpVMj5rBxodhdRAKKxvw8NUBfSwgUdb BXpRoi81w2G0ABVxZY9NGYb4z3RceBkKEHtDWT7mmKx6UKHUbZrgnYROAkygcMy/6I+W E1VEBOysjJzRRJAD+EsHnt/ayFmdGbfcAW8ptkNSN6kT4+XIX0bfYpRHdW0OQcI27sZ5 Ay4f5DmkAq2PbQ0zfHJM/Kf4zYmPdDJEB6AUAAwDjS8Cs5q+mKP/WbgWm/7t0caGffpX Zw0Mrv11DQpBWylAHlGBtTnmcPLfXTgrU2hGCWeG2fXaCe/4tkZCAF6UFKJQMIR4lOhh Hw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr79ngb8f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 24 Jan 2024 06:40:56 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40O5ug5k040710 for ; Wed, 24 Jan 2024 06:40:55 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vs316et2e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 24 Jan 2024 06:40:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DcnUhB83DGrCMAMclvxEsore9teifMZqQ5930GBqN4FOTuwsrSqyyO9tYLLjy6Zv5DYTFyErHYRdpupM8oI5IEzH4bibmv7U1fIxl/10CearacHCDDUkeyOUrxPtQwXg/0OqSTvBbXj6tDolbQfAiQVdqA+Zn4AE1jt9PBXi2NiB1gLj20AuGO9BBstNwzJK7GUed6xfpPN7rPhlaXKww6bdInlCU+oP8uHTnMVOfoUrxzqvOkipxXN8pPWSbkfKU73K/6Ajy0ltiNK+AaZ9GdVb2pXJKyo5/xRK7CDQjicElfspJmMU3GwGbg5r3ZEfI1wTOhArSrIKSrOABBIJhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=qxqUn8PBZC4QpeZlqrnIVTofkA51X8mKMojtEvkKL2I=; b=TfvLdB/QIYa5wETBYfiar1ctCPWD8n+y/P2UoSsdk3GvfypoGdMm+o6jwKETMEk31/DvLS2WhXfYUHqKDpfvLzBaV0Lt7rgcPhK4smzBZcRxFrSFec9+akLKXnEuafHC1TECm2ewhSMVr74yPo6MEtPbHpbfeXOG8Fkqs9WFfr+QQVvVB6uoN2TKqNmNS+FG6xldpxXOkpy+KMDlAg0VwofKwWbxX0UrLR+4yDEN6O8VDvLPpypK8fDd9wrNyb4iJynUBotpuZUMar3hnAvMgtPSzFNg/f4sfOTFB0197okFxDlc2kAePF1Nzh1WnJSistYx25lS2jZv653PFQyd5w== 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=qxqUn8PBZC4QpeZlqrnIVTofkA51X8mKMojtEvkKL2I=; b=EHs7zBHQy/L5o3q9aOaB5EZTnI0g6LMijoJYBN3PXXf88uoPoVFgaQqx/wmVmmSb2coONc9UO005OHt+7pvEV1un9qhBFJXeuQVVHd0uOkSLxzeD7dfxQq5PwD+xqPxsz/lzWabpU0WHfJvIRL/K/sQ8JyYUeP/MCEkmGTwnXbM= Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by LV3PR10MB7795.namprd10.prod.outlook.com (2603:10b6:408:1b6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.37; Wed, 24 Jan 2024 06:40:53 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::fde7:fb92:8ea1:a5ac]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::fde7:fb92:8ea1:a5ac%4]) with mapi id 15.20.7202.031; Wed, 24 Jan 2024 06:40:52 +0000 From: Indu Bhagat To: binutils@sourceware.org Cc: Indu Bhagat Subject: [PATCH,V2] gas: x86: ginsn: adjust ginsns for certain lea ops Date: Tue, 23 Jan 2024 22:40:46 -0800 Message-ID: <20240124064046.1191952-1-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.43.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW4PR03CA0236.namprd03.prod.outlook.com (2603:10b6:303:b9::31) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2158:EE_|LV3PR10MB7795:EE_ X-MS-Office365-Filtering-Correlation-Id: ab1752de-2071-47c9-5624-08dc1ca7687e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ildVpvAo/aGmcg0gBngMQD4kb7iL6eL4/9drnHuQRYNP3O12KBQ9Jz/XbQaLKHneTrJ4tH7vM94fxkjT1SPYamPjpD6Te6ynhclIk1HJdYQaOqLl8Lp7mL3/Tfkqi9SGDiHH1DUV7ho7KoFqkhpVA//ReZq71r9pDkA58673uQGIEK7OAzhUKpXjPgvT6Q/QSvkFGOSpBfO3RYMSHErF57de2TZupNmBZ3WjjZS2SfV8FDbRfRzQIcqRNk3UZiMHb73l7MEfyZCaQrsWT+pgGmeOkr0EcwyD/3xjASj1walt+UOn6fWXee1W6G6Mznc5Ty2D57m6Iyy1wM4cLdsm59WxD1psmqSc5P/sANoSLfN0eSWd0cg4P6VexKjST8S5Kq+xyalbbxvO7XSeNxj+kfS33JoYfOR9FId8BLut3MPhY3myEhjnZp4Xo9QVf4hURdCDx1Z01pb1K26btQgRM2lbbf9ZGLfa+9WTNJ37rD+3B1H4R2rH/F86XSd8kS/pjleYUzZik30XNxHQlk7n409pOcJldOSJzuJx18hG0cWFJw4aNTSsN/wztqthu1YK X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR1001MB2158.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(39860400002)(346002)(376002)(366004)(136003)(230922051799003)(1800799012)(186009)(64100799003)(451199024)(66899024)(83380400001)(41300700001)(36756003)(86362001)(6486002)(38100700002)(2616005)(1076003)(6512007)(107886003)(66946007)(6506007)(2906002)(478600001)(316002)(6916009)(66556008)(66476007)(6666004)(5660300002)(44832011)(4326008)(8676002)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?oZOniTq2S4UBhYoLv3gdJ5fOqsRT9OUU3JlTHym/lzxCqtfxJCHXKWlUy0NW?= =?us-ascii?Q?s5pDyf9eAd62RIx2OQRm9Zwc74HRpCYtXMZRIaIEfkGHoSXo+aIZ8Pgm7Kyr?= =?us-ascii?Q?BEPUGPTxSrtsqon8hN/TuCo8rgnlWbUcg5pK9AzSuayd5GJCCeiGMYH8t6zc?= =?us-ascii?Q?u4en9541CGCzz0jgPpbmsb3pUAtfBrKYBFFtaJyJcWvo3l6IB5TOrBW84t2v?= =?us-ascii?Q?55LLdZpqgw3le0iaDxkpv3Ch1Jqarki5DZSF50WokJNqow66rpqkYeeyupBa?= =?us-ascii?Q?p/slL3VrHM9CUDk9LLC4xjedTzqESB600NzTIQC/yXdTtEoG55snoB7Hsy68?= =?us-ascii?Q?MFoJ6vqiNZtE4Gb23hUTlriwIC/woT1ZcucNxJiJykUdZAXMsquMAhpOQLXc?= =?us-ascii?Q?rSbJXnrs9yWVSvCB1QtIOzrw56KO37n7+0Mu/cd3oOextGFwupCJbZGD2/E6?= =?us-ascii?Q?KcYtnwibvjIoO1Yyw9OOwY3Kj/oP77RFQkqZ3aGm5khM8U80rQcAmYZ4CMnp?= =?us-ascii?Q?gEzQwXen/cpbQkViqeVwYzcmDCmZ5yZB504OGxfDxI8/J/wKNonKSNxd8SbO?= =?us-ascii?Q?AnBzbaJyxERRmaHm0qk3ckvkhuZWh+SberBpbT5TYldk9pfi0YVKlfUZa7Oc?= =?us-ascii?Q?ePb4ZEOQQPrUcueVcWOXRZVo2KYpHiEpXv/BKQbK0vCmIqPVj5zfyxVTylyr?= =?us-ascii?Q?U+/VA8mFYW2nI/wdeqQfgtUIU3+dEQPWlfC3nz8c3QMUIz/R9dUAZlG8iYBT?= =?us-ascii?Q?wVTgNLfPR4CbyUh+bXL+FV88RDPepo6VU1d5bpCxAP4QL8KrOrtk8RXhZ4yt?= =?us-ascii?Q?Wce+paLgY7OagMA/x7smosfqBWPbiOzAqY8DGW6oa46ceX+z/fx5ICKbRpMK?= =?us-ascii?Q?wbi4YIC1RpDi2OGz/enMuBrYSIWip/mKjRLkxbBxMe274LZKBkpjA81KMeFY?= =?us-ascii?Q?r6txl9mJtA/Ho0FVAFOsvioFNRVMNVrG7IpB7hkQIAlAaywO4SjtD2wFJQlv?= =?us-ascii?Q?5chXF5o8YYkxz8eO/085i9DFFn2bWfyI5GvGMOkJqP6yoL0D/9/3vrRUu2JQ?= =?us-ascii?Q?yfn/bzdCaB5j7xUYM9DqEfQIJKR5qcteIkWNRHuh9j8bRzuTV67YI4/++Zkt?= =?us-ascii?Q?YvdZl6G8C5uspw/bvmd4RZia00/V6+4uRiCYI49EO4cknQDG51xrV1prurAT?= =?us-ascii?Q?JWNIdZTB8UHXueRuXJJTr1Di7KMoj+NrGUXZ1PZ8MddY8Wz9gg0k5Dp2PAvJ?= =?us-ascii?Q?zq+tcDjt1aeQSFe7wrYHaOW4bwFEvwFydpPK1pB+dj8m5G22ugfCxbNXL1U9?= =?us-ascii?Q?YD3bVpGYvWjlAcoEsrnYgKmlxK1nd1Y/LI5IH4Xr621adQSTO+i3885h63EI?= =?us-ascii?Q?UuKtb3wV80kcOtrOjC7PDBRjqyEolZO+Kct797X0bh3T32a9rPCwqIgOCWIk?= =?us-ascii?Q?8PrRD79zRoeBq1k29lhHTxxhTWZWD/KEVBOV+zwbXEjLmTAr0W1gnIX4gb0h?= =?us-ascii?Q?1VVllHnBKTqrkzedNmFUj6r4aiB73oQcjMM3isHFX9LjoiMcdtUibiyImgFO?= =?us-ascii?Q?vwVlj6MG+y8zVi24fyrFlDDteWBCyLVReZ9C/7ralPy5oirzrU4lVyvhHOsC?= =?us-ascii?Q?lA2Q4oMNcWwif62eKA7NyW0=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: iAEe8+8RPGZlFGdDHn039D0Rm99V1TUcGkd8I16QrrAQEYLx/cRqG/PJJD5I5oCWBjXbUzxxXnrsIyZ5IvoTSrb/tq1yu1iz1oNdikoR1joUs34Fs3hpoRHB1wcoxjCzpjUYqPgRPV3H1y9ze1k0clRbuF1U1ukKj29awAVp8/kBTEgFMFGcHmKjnTq8XX4AJAUX31rqBn9jxbQi9OvxV4zLog/if36xCDO/FMfdInF6nmDSntI/l+JLZ+/2ERx0uAHFT0pFRarcfVc7CBJWSSqN859hYu16khh0oH7vlAM10igC9VVneC3HCBx40BWkPPSSoFx5JHAucwQtXOEWOT8qWPxUdmXn4EEa1l1JzjOFMI2+JMVS2abM+Vb1wKpghLgaGiRDNQsW06HLMtEXkiqwWTCuav264Q9Threi4btIecLOel2IAOga5J8dA+MhSJscLXA0zXyzhJHRI8hHBo8YfgJiauUCDbmSKgHD2z7MN1j/cpBcWBe/jS7KYT/TwnPezIlaHyQHGupKNc8XMHgdvhgKhjeqz6rvotAtpkWUVCfcvpY1TuZtgPZBUrHbcuDEmvY08er4qmJ7fRFftjSXzqUAEWW30zwe4CM/PDk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab1752de-2071-47c9-5624-08dc1ca7687e X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 06:40:51.9742 (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: mC6ohH/7uLa1Gu/Mnsjio9uWquw0NslpZD+F7Q1lENuOrKxl6TmI89X+8oCkssm/ZpRdVLFPlt53lNuzN4tZUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR10MB7795 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-24_02,2024-01-23_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=954 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240047 X-Proofpoint-GUID: haSLcUDgqkDL-VY37rzfm8pxITivUENV X-Proofpoint-ORIG-GUID: haSLcUDgqkDL-VY37rzfm8pxITivUENV X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: [Changes from V1] - Remove code paths creating GINSN_TYPE_OTHER explicitly. Let the existing x86_ginsn_unhandled code path deal with this, like it does for other ops. - Adjust code comments. - Updated testcase with few new ops. [End of changes from V1] A review comment on the SCFI V4 series was to handle ginsn creation for certain lea opcodes more precisely. Specifically, we should preferably handle the following two cases of lea opcodes similarly: - #1 lea with "index register and scale factor of 1, but no base register", - #2 lea with "no index register, but base register present". Currently, a ginsn of type GINSN_TYPE_OTHER is generated for the case of #1 above. For #2, however, the lea insn is translated to either a GINSN_TYPE_ADD or GINSN_TYPE_MOV depending on whether the immediate for displacement is non-zero or not respectively. Change the handling in x86_ginsn_lea so that both of the above lea manifestations are handled similarly. While at it, remove the code paths creating GINSN_TYPE_OTHER altogether from the function. It makes sense to piggy back on the x86_ginsn_unhandled code path to create GINSN_TYPE_OTHER if the destination register is interesting. This was also suggested in one of the previous review rounds; the other functions already follow that model, so this keeps functions symmetrical looking. gas/ * gas/config/tc-i386.c (x86_ginsn_lea): Handle selected lea with no base register similar to the case of no index register. Remove creation of GINSN_TYPE_OTHER from the function. gas/testsuite/ * gas/scfi/x86_64/ginsn-lea-1.l: New test. * gas/scfi/x86_64/ginsn-lea-1.s: Likewise. * gas/scfi/x86_64/scfi-x86-64.exp: Add new test. --- gas/config/tc-i386.c | 112 ++++++++---------- gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.l | 37 ++++++ gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.s | 15 +++ gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp | 1 + 4 files changed, 104 insertions(+), 61 deletions(-) create mode 100644 gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.l create mode 100644 gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.s diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 51166ef3f02..9c849f89190 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -5655,8 +5655,10 @@ x86_ginsn_move (const symbolS *insn_end_sym) } /* Generate appropriate ginsn for lea. - Sub-cases marked with TBD_GINSN_INFO_LOSS indicate some loss of information - in the ginsn. But these are fine for now for GINSN_GEN_SCFI generation + + Unhandled sub-cases (marked with TBD_GINSN_GEN_NOT_SCFI) also suffer with + some loss of information in the final ginsn chosen eventually (type + GINSN_TYPE_OTHER). But this is fine for now for GINSN_GEN_SCFI generation mode. */ static ginsnS * @@ -5664,76 +5666,64 @@ x86_ginsn_lea (const symbolS *insn_end_sym) { offsetT src_disp = 0; ginsnS *ginsn = NULL; - unsigned int base_reg; - unsigned int index_reg; + unsigned int src1_reg; + const reg_entry *src1; offsetT index_scale; unsigned int dst_reg; if (!i.index_reg && !i.base_reg) { - /* lea symbol, %rN. */ - dst_reg = ginsn_dw2_regnum (i.op[1].regs); - /* TBD_GINSN_INFO_LOSS - Skip encoding information about the symbol. */ - ginsn = ginsn_new_mov (insn_end_sym, false, - GINSN_SRC_IMM, 0xf /* arbitrary const. */, 0, - GINSN_DST_REG, dst_reg, 0); + if (i.disp_operands && i.op[0].disps->X_op == O_constant) + { + /* lea const, %rN. */ + src_disp = i.op[0].disps->X_add_number; + dst_reg = ginsn_dw2_regnum (i.op[1].regs); + ginsn = ginsn_new_mov (insn_end_sym, false, + GINSN_SRC_IMM, 0, src_disp, + GINSN_DST_REG, dst_reg, 0); + ginsn_set_where (ginsn); + } + /* Skip handling lea symbol, %rN here. Deal with it in the + x86_ginsn_unhandled code path. TBD_GINSN_GEN_NOT_SCFI. */ } - else if (i.base_reg && !i.index_reg) + else if ((i.base_reg && !i.index_reg) + || (!i.base_reg && i.index_reg)) { - /* lea -0x2(%base),%dst. */ - base_reg = ginsn_dw2_regnum (i.base_reg); - dst_reg = ginsn_dw2_regnum (i.op[1].regs); + /* lea disp(%base) %dst or lea disp(,%index,imm) %dst. */ - if (i.disp_operands) - src_disp = i.op[0].disps->X_add_number; - - if (src_disp) - /* Generate an ADD ginsn. */ - ginsn = ginsn_new_add (insn_end_sym, true, - GINSN_SRC_REG, base_reg, 0, - GINSN_SRC_IMM, 0, src_disp, - GINSN_DST_REG, dst_reg, 0); - else - /* Generate a MOV ginsn. */ - ginsn = ginsn_new_mov (insn_end_sym, true, - GINSN_SRC_REG, base_reg, 0, - GINSN_DST_REG, dst_reg, 0); - } - else if (!i.base_reg && i.index_reg) - { - /* lea (,%index,imm), %dst. */ - /* TBD_GINSN_INFO_LOSS - There is no explicit ginsn multiply operation, - instead use GINSN_TYPE_OTHER. Also, note that info about displacement - is not carried forward either. But this is fine because - GINSN_TYPE_OTHER will cause SCFI pass to bail out any which way if - dest reg is interesting. */ index_scale = i.log2_scale_factor; - index_reg = ginsn_dw2_regnum (i.index_reg); + src1 = (i.base_reg) ? i.base_reg : i.index_reg; + src1_reg = ginsn_dw2_regnum (src1); dst_reg = ginsn_dw2_regnum (i.op[1].regs); - ginsn = ginsn_new_other (insn_end_sym, true, - GINSN_SRC_REG, index_reg, - GINSN_SRC_IMM, index_scale, - GINSN_DST_REG, dst_reg); - /* FIXME - It seems to make sense to represent a scale factor of 1 - correctly here (i.e. not as "other", but rather similar to the - base-without- index case above)? */ - } - else - { - /* lea disp(%base,%index,imm) %dst. */ - /* TBD_GINSN_INFO_LOSS - Skip adding information about the disp and imm - for index reg. */ - base_reg = ginsn_dw2_regnum (i.base_reg); - index_reg = ginsn_dw2_regnum (i.index_reg); - dst_reg = ginsn_dw2_regnum (i.op[1].regs); - /* Generate an GINSN_TYPE_OTHER ginsn. */ - ginsn = ginsn_new_other (insn_end_sym, true, - GINSN_SRC_REG, base_reg, - GINSN_SRC_REG, index_reg, - GINSN_DST_REG, dst_reg); - } + /* It makes sense to represent a scale factor of 1 precisely here + (i.e., not using GINSN_TYPE_OTHER, but rather similar to the + base-without-index case). Ignore the case when disp has a symbol + instead. */ + if (!index_scale + && (!i.disp_operands + || (i.disp_operands && i.op[0].disps->X_op == O_constant))) + { + if (i.disp_operands) + src_disp = i.op[0].disps->X_add_number; - ginsn_set_where (ginsn); + if (src_disp) + /* Generate an ADD ginsn. */ + ginsn = ginsn_new_add (insn_end_sym, true, + GINSN_SRC_REG, src1_reg, 0, + GINSN_SRC_IMM, 0, src_disp, + GINSN_DST_REG, dst_reg, 0); + else + /* Generate a MOV ginsn. */ + ginsn = ginsn_new_mov (insn_end_sym, true, + GINSN_SRC_REG, src1_reg, 0, + GINSN_DST_REG, dst_reg, 0); + + ginsn_set_where (ginsn); + } + } + /* Skip handling other cases here, e.g., when (i.index_reg && i.base_reg) is + true. Deal with it in the x86_ginsn_unhandled code path by generating + GINSN_TYPE_OTHER when necessary. TBD_GINSN_GEN_NOT_SCFI. */ return ginsn; } diff --git a/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.l b/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.l new file mode 100644 index 00000000000..925153ce58e --- /dev/null +++ b/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.l @@ -0,0 +1,37 @@ +GAS LISTING .* + + + 1 ## Testcase with a variety of lea. + 2 .text + 3 .globl foo + 4 .type foo, @function + 4 ginsn: SYM FUNC_BEGIN + 5 foo: + 5 ginsn: SYM foo + 6 0000 488D2C25 lea symbol, %rbp + 6 00000000 + 6 ginsn: OTH 0, 0, %r6 + 7 0008 488D2425 lea 0x9090, %rsp + 7 90900000 + 7 ginsn: MOV 37008, %r7 + 8 0010 488D05FE lea -0x2\(%rip\), %rax + 8 FFFFFF + 8 ginsn: ADD %r4, -2, %r0 + 9 0017 678D6C18 lea -0x1\(%eax,%ebx\), %ebp + 9 FF + 9 ginsn: OTH 0, 0, %r6 + 10 001c 678D6C58 lea 0x55\(%eax,%ebx,2\), %ebp + 10 55 + 10 ginsn: OTH 0, 0, %r6 + 11 0021 678D0C1D lea -0x3\(,%ebx,1\), %ecx + 11 FDFFFFFF + 11 ginsn: ADD %r3, -3, %r2 + 12 0029 678D0C1D lea -0x3\(,%ebx,\), %ecx + 12 FDFFFFFF + 12 ginsn: ADD %r3, -3, %r2 + 13 0031 678D0C5D lea -0x3\(,%ebx,2\), %ecx + 13 FDFFFFFF + 14 .LFE0: + 14 ginsn: SYM .LFE0 + 15 .size foo, .-foo + 15 ginsn: SYM FUNC_END diff --git a/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.s b/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.s new file mode 100644 index 00000000000..ae8601b302e --- /dev/null +++ b/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.s @@ -0,0 +1,15 @@ +## Testcase with a variety of lea. + .text + .globl foo + .type foo, @function +foo: + lea symbol, %rbp + lea 0x9090, %rsp + lea -0x2(%rip), %rax + lea -0x1(%eax,%ebx), %ebp + lea 0x55(%eax,%ebx,2), %ebp + lea -0x3(,%ebx,1), %ecx + lea -0x3(,%ebx,), %ecx + lea -0x3(,%ebx,2), %ecx +.LFE0: + .size foo, .-foo diff --git a/gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp b/gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp index 2b291800b65..d32cb290d92 100644 --- a/gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp +++ b/gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp @@ -26,6 +26,7 @@ if { ([istarget "x86_64-*-*"] && ![istarget "x86_64-*-linux*-gnux32"]) } then { run_list_test "ginsn-dw2-regnum-1" "--scfi=experimental -ali" run_list_test "ginsn-add-1" "--scfi=experimental -ali" + run_list_test "ginsn-lea-1" "--scfi=experimental -ali" run_list_test "ginsn-pop-1" "--scfi=experimental -ali" run_list_test "ginsn-push-1" "--scfi=experimental -ali" -- 2.43.0