From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 1DA583858D33 for ; Fri, 2 Feb 2024 07:25:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1DA583858D33 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 1DA583858D33 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706858757; cv=pass; b=nxTjzttaEHtU1pbEHbD57/9SdcFyO5HxT5WrLo0WPdpTqPNvUr07yS/cXBuKaSQM71nd19CNJUN/h9pW7hGBcEE4jAFcqSXCim7OsYxsKHpDBH0NMWB/MDLcRpaPlQCO6WSSurIpFGDXAMbyaYg/uM7hzpPNW24xsOU3DsjiU5E= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706858757; c=relaxed/simple; bh=ONGsmSLi8mTKLkNQHS2POu2x4r3U9XaCT57wEf2tbZo=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=frud+j9eZu1So47YYkGRQbK1+WipcaBwjrC6hclB/6vb0A50ZRWFSYdKkxyd9N59Vl6OKb0QrUMH/xrT/FVLoXugJcYd3r6fHpZxKC3cqlJcp0W0kMfaC4UqvTcyYhMEUZwt1kk2a9QPxxvS/KG46tIiO4dnqCj19VHVj8EK1QE= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 4120iE7T008048 for ; Fri, 2 Feb 2024 07:25:54 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=DCtEQBTxsHVjfpHOT4hbHDi/PEUstvFxZTHeLGr3+i8=; b=Pf8F3l9gnUEEMv/5I3qTXf2SbVY3+KPhYsxVT07XlzkJah064fgCIu0Vcn4QulCJEY3P /ovzgfpQB0c+LLeJMA028QZU8AoJA9b0ISbmFEDM0rsKSABcGupuTA5aRVG0yvzLJB8w 8cFRGaJnSC0WvT4vpjR6O2jCB2/uyXL9dI05+lRngiOemWyM8f+iQSjYbhCM0Ql/AjnR CIOKw4lPOqcswHCtPdTWlblB197PkucM2CCCg26QnPdWyM+17QMGHyonTRCjgDdGgWun Ni78nFWwqY9uX8lIo5g4npmFHaxWlvjTGBfgxuRJfxCYkqxzWSqoDoDeadvNKzmk3LJi 3g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vvrm46sjd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 02 Feb 2024 07:25:54 +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 41269j4I011569 for ; Fri, 2 Feb 2024 07:25:53 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2101.outbound.protection.outlook.com [104.47.55.101]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vvr9bfde1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 02 Feb 2024 07:25:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OexsPYGHW4tDZGOr1mUIv3p/FomfguGVsukvfNLUksntk3/MqqcQ5azTB+6Vg6I4zxkorvSbtQDwoynkICq8b3DfLd9Ag6+a2sfW5oEPaFkImAfP3tVBIkL0ZB2UFyFkEYxcARITXErTGDaossW785CaS3QIiAT/Fd8AltQQ81wzbNUI0HbV1Kjnhnqm5oBU4XmICmAhJSw9n/YqXys4zGHIIxiSWEEvF810dtVFs7M4bhYzs1VF93ji7WaeamIxXlyo9Dnptk4Cm5ITcnICyn4m/wVZPYtU+eBW/5hXzZv8x/GB6LD+h55MHqtw+KOgqgZCID/nA03fpGolaF6UKg== 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=DCtEQBTxsHVjfpHOT4hbHDi/PEUstvFxZTHeLGr3+i8=; b=XEJwcEz3G+26LxHZyMYlA/B7ehj40hzs1nEjAj66EPuJ0axzZNuwHaMYNEC85DzLh3y2ncb9YwnVm3tQY4Q+ptsTGJmTLpucI5yovDXzWzwJ1cO+bn2l0CSl6XnXX6DVojXO5iT59WYvn/URmgXsg9FIk+MKBmX5gNhi2mnZ/rDWYb/G5j/z0e9P2JGdz0uc90Br3J+3kON0lx6zdDRX4TqU4o1pDpPhWtmSa6tVo4Xf1XuhWyVgZz1osOkedggE7vYxD+xqdLX1QD6LCwmEDXFgtbOJxHl6ahuFo2NH8X0ffZX62FznzNHMMsPzMs98sq9VO4CpFg+qkVXfeGTj5A== 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=DCtEQBTxsHVjfpHOT4hbHDi/PEUstvFxZTHeLGr3+i8=; b=AJFXrD6W8ly1aY4KdFNynXhUx5toD3VmQ3sYE6nBkQqx9dK+jFpyZfMhkWmSS5S1onY1GsxmwkAxCR4/lDS/Jy33JZyC2Xni5cqcynFjUXknHzYKcTgz55y0bNjaYOih32t8n+kEmPipxzEvFZuk8ikaQAkLv0BQHaiYH9vZp6Y= Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by CO1PR10MB4547.namprd10.prod.outlook.com (2603:10b6:303:96::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.29; Fri, 2 Feb 2024 07:25:51 +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.7249.024; Fri, 2 Feb 2024 07:25:50 +0000 From: Indu Bhagat To: binutils@sourceware.org Cc: Indu Bhagat Subject: [PATCH] gas: x86: ginsn: handle sub-QWORD ALU with imm and MOV ops correctly Date: Thu, 1 Feb 2024 23:25:47 -0800 Message-ID: <20240202072547.213705-1-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.43.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW4PR03CA0196.namprd03.prod.outlook.com (2603:10b6:303:b8::21) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2158:EE_|CO1PR10MB4547:EE_ X-MS-Office365-Filtering-Correlation-Id: a2dab04c-bcc2-4fe5-34c0-08dc23c02eda X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lQGgDCsT9U9ldhUKC3+JCdJPCovDPTf7UkJ+k6iOccLfiwha/UigNdB9A8Kv1GL6423zfUUHd1V/UwEp84E7xhaBpjoVCBI9yYkW3HayEkkSZqlma6nTX/cKVxkRG9Yir3UKASrdZDeZy+3ipAXKep3f3+VKrfsrY45xCMWqd6EDTwkaIk0tGugLowi1KFaiyhRRfpHlv12W/ksen+GfSUxYI9SIQMI1NEZGJ+ZsBrd4TCyHOVGcpbhFzqHuuy7Vo78HWMZG6t3koVY8DC5xnfnhokusvn7C7grQVEpuxHNXawhjGF9EHlqYldHc99BdYGJv3mSXXBWiEYaLULMEIsIT0M1W6lF1yG8c1M7qVWaYuVaxK++IfAGdpdte5Yhbkco+jP585ALSA3f8v1i1I9SUcWfOLcQdZgKzz8bpj1hmM5kAuEeMvOQ1zAh8CiVK5rEcPxQt6QhZUO4RQ32Bp+dHDxdXZbSnz58DKCT5MAPq+aDytZ+m3MBlzzADDdeZ2qSNg+DfvDkY9o44K8diU7wzzT96RvZkDLC355Y6Jeljw7xFOEuO0b6orUDMJ5b6 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)(376002)(346002)(136003)(366004)(230922051799003)(186009)(1800799012)(451199024)(64100799003)(83380400001)(107886003)(1076003)(41300700001)(2616005)(8936002)(38100700002)(66946007)(8676002)(2906002)(4326008)(66556008)(316002)(66476007)(30864003)(5660300002)(6916009)(44832011)(6506007)(6666004)(6486002)(6512007)(478600001)(86362001)(36756003)(66899024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?2Iz9LhZFez2xUGB+sXlWIhY1FCTyHbA6+wfs4sTtCbNRjgkbH9G8UekEFpTA?= =?us-ascii?Q?rFa+t3o9vMUAsul4R+r/x5Llax9nKk8s9mZ8gr1MCUCy+javXMjjQK4lxdW5?= =?us-ascii?Q?sCxdEnWyjVw0BpGL0EGvnPPlKUH8U43J9IA7l1xGl/q9eatvPxjM2V79Sgg7?= =?us-ascii?Q?oSkuvPjfTjt0FsA5HuxE8KillYeAh57Gy0sh8mYT/yjnZFQRuNQA/hgabWG2?= =?us-ascii?Q?jFJNykqbUVQBmEJLEe3dt6wZ+ksQF5RNWuUec497gA40Khq1nL1scV5hL/g5?= =?us-ascii?Q?ozWdLMSo0ZzDEJU2wRVb0AnBGX3fEgVbyKXd+sQrXN/tpLYlqFmzaD/CXlRY?= =?us-ascii?Q?xxPHGaoDwmFgBpOmFY74KOms46xxfRVq9QnYtjKoT/GmUhV0Id6QRMbvKL7N?= =?us-ascii?Q?yzW+M3oQn4hdxAxaOznErgpqOw7iQb6S8neKUboqdBDBtPWP/88+/qzBgyyP?= =?us-ascii?Q?mAMNceasL1bk6+P+yu1bxK9y9Wsui/QKDo4SI/XMbStOcxgazmW4/qEYtstO?= =?us-ascii?Q?t92nxlu5qwk8ZzaJPsT5HQ3LqUx5CjuZL9gUloqmJR84z33JKguiKUOkXmu+?= =?us-ascii?Q?FvyvPa5W1cvv4PSG3TlI2h9CHOMPJwCo49S38cLgTuXwKMdk0mZfYf6Evs10?= =?us-ascii?Q?wEZCO/WEnLyg2dWOwwYD79cKsWNk7JL0UfD9aY3oO5IA8Z6ieo8ejHVyYSrq?= =?us-ascii?Q?x8ME/J6EWTtsx4QcsOmvPvP3rl79Cdk5cgBcYNzd+1u1nWRBsWScSIurepEm?= =?us-ascii?Q?zuwBtYlnJ1gxOLAUOJpclIRpjDAIPUQJBk/3FsJG+UM8Q8IyrPBgdfoyBSCE?= =?us-ascii?Q?FsHLlbQPXUTbLa4/XKWywAclSPeGWWIhyELxSBUW7AKSuTnwr6HCE6Hl83B4?= =?us-ascii?Q?6RrnqDhrq7oztPi5HgkNPkq7BBLD9EB1Ewuk/Q8yiOqmNA0E8PJm4r4/JZJ2?= =?us-ascii?Q?WYUbzHhXyqVJRWV1UwN50BSMMkSh0ui2lsi198OrKsGjC7R94UCa/GFJi7NL?= =?us-ascii?Q?DWwG6AUrzKcHQl8NkyP3zpPpeyvGr8NzsjlxgrC6EPXd0qxAcrFusCk/vAKl?= =?us-ascii?Q?npqOg6ZhNZPFFa2tTCBEFuGcSJrqtfo6tJ9qO0SXBhplEQE+LephhOZtpaMp?= =?us-ascii?Q?jRelHN6UD/UDnGSiCLRvWoZN0LOmJjVK5OQCtVwErTIGC+apqDEpRlk2+fJc?= =?us-ascii?Q?lKscpT0NJg9y3c9zb1CBjeEsjBiFBWdqWhqql5rnP8wYCFSaIxH7IYkpdFyT?= =?us-ascii?Q?2QMyvO/BY+UXzuRxyyWA+YFhUWd+0yZ0ozD13uD76FiXOiLpIJqXog+CdCVy?= =?us-ascii?Q?OVJT0weqsYqSe8o30xGdkRo2xk7xkgsa+q4qeidumz57XMBRdMvSKJFSAfIx?= =?us-ascii?Q?Nis3puO+g6LBVEFsYrgIfAim0GNGW7YoiDzmoZkTDcSMQ3XUthMjANXVHJQS?= =?us-ascii?Q?KRWG1/OYy+ETyS4QyvIvSciBAzBx/Mb5Wn6w5AufZiNeKKxDtGGdBl9OWbdc?= =?us-ascii?Q?Q2xfOhi7KzbhF4ceo8+MrAobDiru6uFIEyYsyfJzSdc/uWmQ8RDO7VzP4mFC?= =?us-ascii?Q?6l89zVYys8QNEo/66TgQC4HoQ7DfR6JQ9U1igJDSOwRRAZ38WTjAQBNVOjns?= =?us-ascii?Q?UUF9LAvukNpqYJ5z5HwXgZY=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: B8bnqgXI7jDUN6CK06wlf8tPZnxwYmkOsAeEVp2QmVXK/def1fpWLoff51lpLmJQYhM57QYhRK/a6e2xuXSiGiH+Fdnm/jvuadqWcnD0upioUe1ggICRSx1u1pSgyhweIRIukp5jNZ6m2D0jxa+jK1p2aGh/Pe7oJOn3Wa5LHL34Y84wXy1y6ENIUXhKugv987OIJQB8zB/wmcHI030w42uz60TJLQ80kALU/nIdZTyUhH4z5wn6aS2yrptpYeWPTLrVsGTxCpVWBxFidrUwAdnk+lZ4ebgYfncZpoJmrHVYP0lc9YN94PTDTPqzKG34pLmM/X/7UNeeaypGYa+EJD6HkygrwGXHdrBdq2P/E2Hxr6LY4rv0WfEYdRg6TApxp8Cvaz3DtYaJAwnszS1utoMyoyLNJ//WKvB8xMSWEgUMhS4OrN2fE6aFP6mJqMj4QnJM+lNkPLFrV2DweRgl+hpOSaSVv07YaXay6imB66Ik1h2npV8ZelFTwW/4FTcx8husZMpLDcetN0UOdlXWVMfNsuZL6J0Z82H7/gXYTeGuROzjcVfIHDD54pt2T37cU0opvyg+z1hXntxIheZj5iMPRvfiHvXvAJ7XJbuTqC8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2dab04c-bcc2-4fe5-34c0-08dc23c02eda X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2024 07:25:50.7675 (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: EfhSO2hIs5kbivSJyWEDvz8LszXhrACT6Id5azgAlkE/OgrOrWgmLqZg4dscEQSR9auHb+2VpltKqzdbtJX+qg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4547 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-02-02_02,2024-01-31_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 malwarescore=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=996 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402020053 X-Proofpoint-GUID: jyPNwIEoZ89haHRTh_W2liXQuhlS5oGj X-Proofpoint-ORIG-GUID: jyPNwIEoZ89haHRTh_W2liXQuhlS5oGj X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_STOCKGEN,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SCC_5_SHORT_WORD_LINES,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: PR gas/31326 SCFI must handle non QWORD ALU with imm and MOV ops correctly As per the x86 ISA manual: - 32-bit operands generate a 32-bit result, zero-extended to a 64-bit result in the destination general-purpose register. - 8-bit and 16-bit operands generate an 8-bit or 16-bit result. The upper 56 bits or 48 bits (respectively) of the destination general-purpose register are not modified by the operation. Unlike previously thought, sub-QWORD ALU/imm and MOV ops do have implications on SCFI. SCFI/ginsn machinery does not track operation size in the ginsn representation. But given that these sub-QWORD ops update only a portion of a 64-bit destination register, for SCFI purposes, this needs to be deemed as an untraceable update (when the destination is REG_SP / REG_FP). Although in most cases, sub-QWORD ops are not expected for stack management, but the SCFI machinery must behave correctly, when such ops are indeed present. As mentioned earlier, ginsn representation does not carry operation size information. To resolve the issue raised in PR gas/31326, an option is to force the generation of GINSN_TYPE_OTHER for all cases when there is a 8/16/32 bit op. But this may dilute the utility of ginsn for other use-cases, when they pop up in future. The current approach is less disruptive than above in that it generates GINSN_TYPE_OTHER for all cases only when: - there is a 8/16/32 bit op, and - the 64-bit op is otherwise traceable. In other words this means: - For add/sub ops where dest is reg and src is reg/mem: these always make dest reg untraceable; So, the current handling is unchanged. We simply skip detecting 8/16/32-bit ops. - An x86 pop instruction is translated to a load ginsn followed by a stack increment add op. A load op always makes dest reg untraceable. Hence, if the pop instruction is sub-QWORD, we continue to (skip detecting 8/16/32-bit op, and) generate the load instruction as usual. This means that if input asm does have save and restore of unequal sized registers, gas/SCFI will not detect nor warn. - For ALU imm or MOV reg,reg, however, a GINSN_TYPE_OTHER is generated when a 8/16/32-bit op is seen. gas/ PR gas/31326 * config/tc-i386.c (x86_ginsn_addsub_reg_mem): Add a code comment. (x86_ginsn_addsub_mem_reg): Likewise. (x86_ginsn_alu_imm): Detect sub-QWORD opsize and exit early. (x86_ginsn_move): Likewise. (x86_ginsn_new): Add comment for 8-bit add/sub opcodes (in opcode_space SPACE_BASE) about skipped handling. gas/testsuite/: PR gas/31326 * gas/scfi/x86_64/ginsn-add-1.l: Update. * gas/scfi/x86_64/ginsn-add-1.s: Add some sub-QWORD add ops. * gas/scfi/x86_64/ginsn-dw2-regnum-1.l: Update. * gas/scfi/x86_64/ginsn-dw2-regnum-1.s: Use mov ops instead of add to invoke and test the ginsn_dw2_regnum code path. --- gas/config/tc-i386.c | 23 ++++ gas/testsuite/gas/scfi/x86_64/ginsn-add-1.l | 62 ++++----- gas/testsuite/gas/scfi/x86_64/ginsn-add-1.s | 2 + .../gas/scfi/x86_64/ginsn-dw2-regnum-1.l | 122 ++++++++++-------- .../gas/scfi/x86_64/ginsn-dw2-regnum-1.s | 36 ++++-- 5 files changed, 149 insertions(+), 96 deletions(-) diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 2e578e2b0d7..b854c08908c 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -5454,6 +5454,9 @@ x86_ginsn_addsub_reg_mem (const symbolS *insn_end_sym) if (i.mem_operands) return ginsn; + /* Skip detection of 8/16/32-bit op size; 'add/sub reg, reg/mem' ops always + make the dest reg untraceable for SCFI. */ + /* op reg, reg/mem. */ src1_dw2_regnum = ginsn_dw2_regnum (i.op[0].regs); /* Of interest only when second opnd is not memory. */ @@ -5492,6 +5495,9 @@ x86_ginsn_addsub_mem_reg (const symbolS *insn_end_sym) if (i.mem_operands && !i.base_reg && !i.index_reg) return ginsn; + /* Skip detection of 8/16/32-bit op size; 'add/sub reg/mem, reg' ops always + make the dest reg untraceable for SCFI. */ + /* op reg/mem, %reg. */ dw2_regnum = ginsn_dw2_regnum (i.op[1].regs); @@ -5572,6 +5578,11 @@ x86_ginsn_alu_imm (const symbolS *insn_end_sym) if (i.mem_operands == 1) return ginsn; + /* 8/16/32-bit op size makes the destination reg untraceable for SCFI. + Deal with this via the x86_ginsn_unhandled () code path. */ + if (i.suffix != QWORD_MNEM_SUFFIX) + return ginsn; + gas_assert (i.imm_operands == 1); src_imm = i.op[0].imms->X_add_number; /* The second operand may be a register or indirect access. For SCFI, only @@ -5618,6 +5629,12 @@ x86_ginsn_move (const symbolS *insn_end_sym) if (i.mem_operands == 1 && !i.base_reg && !i.index_reg) return ginsn; + /* 8/16/32-bit op size makes the destination reg untraceable for SCFI. + Handle mov reg, reg only. mov to or from a memory operand will make + dest reg, when present, untraceable, irrespective of the op size. */ + if (i.reg_operands == 2 && i.suffix != QWORD_MNEM_SUFFIX) + return ginsn; + gas_assert (i.tm.opcode_space == SPACE_BASE); if (opcode == 0x8b || opcode == 0x8a) { @@ -6014,6 +6031,12 @@ x86_ginsn_new (const symbolS *insn_end_sym, enum ginsn_gen_mode gmode) switch (opcode) { + + /* Add opcodes 0x0/0x2 and sub opcodes 0x28/0x2a (with opcode_space + SPACE_BASE) are 8-bit ops. While they are relevant for SCFI + correctness, skip handling them here and use the x86_ginsn_unhandled + code path to generate GINSN_TYPE_OTHER when necessary. */ + case 0x1: /* add reg, reg/mem. */ case 0x29: /* sub reg, reg/mem. */ if (i.tm.opcode_space != SPACE_BASE) diff --git a/gas/testsuite/gas/scfi/x86_64/ginsn-add-1.l b/gas/testsuite/gas/scfi/x86_64/ginsn-add-1.l index ff078d4d883..5190e45699d 100644 --- a/gas/testsuite/gas/scfi/x86_64/ginsn-add-1.l +++ b/gas/testsuite/gas/scfi/x86_64/ginsn-add-1.l @@ -12,38 +12,42 @@ GAS LISTING .* 7 0000 54 push %rsp 7 ginsn: SUB %r7, 8, %r7 7 ginsn: STORE %r7, \[%r7\+0\] - 8 0001 4889E5 movq %rsp, %rbp - 8 ginsn: MOV %r7, %r6 - 9 - 10 0004 48010425 addq %rax, symbol - 10 00000000 - 11 000c 03042500 add symbol, %eax - 11 000000 - 12 0013 670320 add \(%eax\), %esp - 12 ginsn: ADD \[%r0\+0\], %r7, %r7 - 13 0016 67012405 add %esp, \(,%eax\) - 13 00000000 - 14 001e 67032405 add \(,%eax\), %esp + 8 0001 01C5 add %eax, %ebp + 8 ginsn: ADD %r0, %r6, %r6 + 9 0003 4889E5 movq %rsp, %rbp + 9 ginsn: MOV %r7, %r6 + 10 + 11 0006 48010425 addq %rax, symbol + 11 00000000 + 12 000e 03042500 add symbol, %eax + 12 000000 + 13 0015 670320 add \(%eax\), %esp + 13 ginsn: ADD \[%r0\+0\], %r7, %r7 + 14 0018 67012405 add %esp, \(,%eax\) 14 00000000 - 14 ginsn: ADD \[%r0\+0\], %r7, %r7 - 15 - 16 0026 4801C3 addq %rax, %rbx - 16 ginsn: ADD %r0, %r3, %r3 - 17 0029 01C3 add %eax, %ebx + 15 0020 67032405 add \(,%eax\), %esp + 15 00000000 + 15 ginsn: ADD \[%r0\+0\], %r7, %r7 + 16 + 17 0028 4801C3 addq %rax, %rbx 17 ginsn: ADD %r0, %r3, %r3 - 18 - 19 002b 4883D408 adc \$8, %rsp + 18 002b 01C3 add %eax, %ebx + 18 ginsn: ADD %r0, %r3, %r3 + 19 002d 83C408 add \$8, %esp 19 ginsn: OTH 0, 0, %r7 20 - 21 002f 488345F0 addq \$1, -16\(%rbp\) - 21 01 + 21 0030 4883D408 adc \$8, %rsp + 21 ginsn: OTH 0, 0, %r7 22 - 23 0034 4803D8 \{load\} addq %rax, %rbx - 23 ginsn: ADD %r0, %r3, %r3 + 23 0034 488345F0 addq \$1, -16\(%rbp\) + 23 01 24 - 25 0037 C3 ret - 25 ginsn: RET - 26 .LFE0: - 26 ginsn: SYM .LFE0 - 27 .size foo, .-foo - 27 ginsn: SYM FUNC_END + 25 0039 4803D8 {load} addq %rax, %rbx + 25 ginsn: ADD %r0, %r3, %r3 + 26 + 27 003c C3 ret + 27 ginsn: RET + 28 .LFE0: + 28 ginsn: SYM .LFE0 + 29 .size foo, .-foo + 29 ginsn: SYM FUNC_END diff --git a/gas/testsuite/gas/scfi/x86_64/ginsn-add-1.s b/gas/testsuite/gas/scfi/x86_64/ginsn-add-1.s index f9398369531..f6bf5a0a5b8 100644 --- a/gas/testsuite/gas/scfi/x86_64/ginsn-add-1.s +++ b/gas/testsuite/gas/scfi/x86_64/ginsn-add-1.s @@ -5,6 +5,7 @@ .type foo, @function foo: push %rsp + add %eax, %ebp movq %rsp, %rbp addq %rax, symbol @@ -15,6 +16,7 @@ foo: addq %rax, %rbx add %eax, %ebx + add $8, %esp adc $8, %rsp diff --git a/gas/testsuite/gas/scfi/x86_64/ginsn-dw2-regnum-1.l b/gas/testsuite/gas/scfi/x86_64/ginsn-dw2-regnum-1.l index f242e1f2171..8a8edd5742d 100644 --- a/gas/testsuite/gas/scfi/x86_64/ginsn-dw2-regnum-1.l +++ b/gas/testsuite/gas/scfi/x86_64/ginsn-dw2-regnum-1.l @@ -1,69 +1,85 @@ GAS LISTING .* -.*# Testcase for DWARF regnum ginsn API + 1 # Testcase for DWARF regnum ginsn API 2 .text 3 .globl foo 4 .type foo, @function 4 ginsn: SYM FUNC_BEGIN 5 foo: 5 ginsn: SYM foo - 6 0000 0408 add \$8, %al - 7 0002 80C108 add \$8, %cl - 7 ginsn: ADD %r2, 8, %r2 - 8 0005 80C208 add \$8, %dl - 8 ginsn: ADD %r1, 8, %r1 - 9 0008 80C408 add \$8, %ah - 9 ginsn: ADD %r0, 8, %r0 - 10 000b 80C508 add \$8, %ch - 10 ginsn: ADD %r2, 8, %r2 - 11 000e 80C608 add \$8, %dh - 11 ginsn: ADD %r1, 8, %r1 - 12 0011 80C708 add \$8, %bh - 12 ginsn: ADD %r3, 8, %r3 - 13 - 14 0014 4080C008 add \$8, %axl - 14 ginsn: ADD %r0, 8, %r0 - 15 0018 4080C408 add \$8, %spl - 15 ginsn: ADD %r7, 8, %r7 + 6 0000 55 push %rbp + 6 ginsn: SUB %r7, 8, %r7 + 6 ginsn: STORE %r6, \[%r7\+0\] + 7 0001 4889E5 mov %rsp, %rbp + 7 ginsn: MOV %r7, %r6 + 8 + 9 0004 8A40FE mov -0x2\(%rax\), %al + 9 ginsn: MOV \[%r0\+-2\], %r0 + 10 0007 8A58FE mov -0x2\(%rax\), %bl + 10 ginsn: MOV \[%r0\+-2\], %r3 + 11 000a 8A50FE mov -0x2\(%rax\), %dl + 11 ginsn: MOV \[%r0\+-2\], %r1 + 12 000d 8A60FE mov -0x2\(%rax\), %ah + 12 ginsn: MOV \[%r0\+-2\], %r0 + 13 0010 8A68FE mov -0x2\(%rax\), %ch + 13 ginsn: MOV \[%r0\+-2\], %r2 + 14 0013 8A70FE mov -0x2\(%rax\), %dh + 14 ginsn: MOV \[%r0\+-2\], %r1 + 15 0016 8A78FE mov -0x2\(%rax\), %bh + 15 ginsn: MOV \[%r0\+-2\], %r3 16 - 17 001c 6683C008 add \$8, %ax - 17 ginsn: ADD %r0, 8, %r0 - 18 0020 664183C0 add \$8, %r8w - 18 08 - 18 ginsn: ADD %r8, 8, %r8 - 19 0025 6683C408 add \$8, %sp - 19 ginsn: ADD %r7, 8, %r7 - 20 - 21 0029 83C008 add \$8, %eax - 21 ginsn: ADD %r0, 8, %r0 - 22 002c 4183C008 add \$8, %r8d - 22 ginsn: ADD %r8, 8, %r8 - 23 0030 81C40040 add \$16384, %esp - 23 0000 - 23 ginsn: ADD %r7, 16384, %r7 - 24 - 25 0036 4883C508 add \$8, %rbp - 25 ginsn: ADD %r6, 8, %r6 - 26 - 27 003a 488D05FE lea -0x2\(%rip\), %rax - 27 FFFFFF - 27 ginsn: ADD %r4, -2, %r0 - 28 0041 67488905 mov %rax, 0x2\(%eip\) - 28 02000000 - 28 ginsn: MOV %r0, \[%r4\+2\] - 29 0049 67488B05 mov -0x2\(%eip\), %rax - 29 FEFFFFFF - 29 ginsn: MOV \[%r4\+-2\], %r0 + 17 0019 408A40FE mov -0x2\(%rax\), %axl + 17 ginsn: MOV \[%r0\+-2\], %r0 + 18 001d 408A60FE mov -0x2\(%rax\), %spl + 18 ginsn: MOV \[%r0\+-2\], %r7 + 19 + 20 0021 668B40FE mov -0x2\(%rax\), %ax + 20 ginsn: MOV \[%r0\+-2\], %r0 + 21 0025 66448B40 mov -0x2\(%rax\), %r8w + 21 FE + 21 ginsn: MOV \[%r0\+-2\], %r8 + 22 002a 668B60FE mov -0x2\(%rax\), %sp + 22 ginsn: MOV \[%r0\+-2\], %r7 + 23 + 24 002e 4080C408 add \$8, %spl + 24 ginsn: OTH 0, 0, %r7 + 25 + 26 0032 8B40FE mov -0x2\(%rax\), %eax + 26 ginsn: MOV \[%r0\+-2\], %r0 + 27 0035 448B40FE mov -0x2\(%rax\), %r8d + 27 ginsn: MOV \[%r0\+-2\], %r8 + 28 + 29 0039 81C40040 add \$16384, %esp + 29 0000 + 29 ginsn: OTH 0, 0, %r7 30 - 31 0051 C3 ret - 31 ginsn: RET + 31 003f 4883C508 add \$8, %rbp + 31 ginsn: ADD %r6, 8, %r6 + 32 + 33 0043 488D05FE lea -0x2\(%rip\), %rax GAS LISTING .* - 32 .LFE0: - 32 ginsn: SYM .LFE0 - 33 .size foo, .-foo - 33 ginsn: SYM FUNC_END + 33 FFFFFF + 33 ginsn: ADD %r4, -2, %r0 + 34 004a 67488905 mov %rax, 0x2\(%eip\) + 34 02000000 + 34 ginsn: MOV %r0, \[%r4\+2\] + 35 0052 67488B05 mov -0x2\(%eip\), %rax + 35 FEFFFFFF + 35 ginsn: MOV \[%r4\+-2\], %r0 + 36 + 37 005a 4889EC mov %rbp, %rsp + 37 ginsn: MOV %r6, %r7 + 38 005d 5D pop %rbp + 38 ginsn: LOAD \[%r7\+0\], %r6 + 38 ginsn: ADD %r7, 8, %r7 + 39 005e C3 ret + 39 ginsn: RET + 40 .LFE0: + 40 ginsn: SYM .LFE0 + 41 .size foo, .-foo + 41 ginsn: SYM FUNC_END #pass diff --git a/gas/testsuite/gas/scfi/x86_64/ginsn-dw2-regnum-1.s b/gas/testsuite/gas/scfi/x86_64/ginsn-dw2-regnum-1.s index 383c60f635b..09bf42e6e19 100644 --- a/gas/testsuite/gas/scfi/x86_64/ginsn-dw2-regnum-1.s +++ b/gas/testsuite/gas/scfi/x86_64/ginsn-dw2-regnum-1.s @@ -3,23 +3,29 @@ .globl foo .type foo, @function foo: - add $8, %al - add $8, %cl - add $8, %dl - add $8, %ah - add $8, %ch - add $8, %dh - add $8, %bh - - add $8, %axl + push %rbp + mov %rsp, %rbp + + mov -0x2(%rax), %al + mov -0x2(%rax), %bl + mov -0x2(%rax), %dl + mov -0x2(%rax), %ah + mov -0x2(%rax), %ch + mov -0x2(%rax), %dh + mov -0x2(%rax), %bh + + mov -0x2(%rax), %axl + mov -0x2(%rax), %spl + + mov -0x2(%rax), %ax + mov -0x2(%rax), %r8w + mov -0x2(%rax), %sp + add $8, %spl - add $8, %ax - add $8, %r8w - add $8, %sp + mov -0x2(%rax), %eax + mov -0x2(%rax), %r8d - add $8, %eax - add $8, %r8d add $16384, %esp add $8, %rbp @@ -28,6 +34,8 @@ foo: mov %rax, 0x2(%eip) mov -0x2(%eip), %rax + mov %rbp, %rsp + pop %rbp ret .LFE0: .size foo, .-foo -- 2.43.0