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 358793858283 for ; Thu, 28 Mar 2024 23:43:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 358793858283 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 358793858283 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=1711669442; cv=pass; b=Me/ZWGtq41dokUAlkTIpwMBkRVveLwb1UUmKSRX46aMSV2GZcTRv6AW4EfM84uFjjq0mj0xW7Xq1sfhCAsGujFJFUEPMdZEqCdynCWzE+Oan8O1Y3JXSk1EzBwjzUGKtkdBahydz/OMrYrYSs5UFZVrvZvHkx/lU7wymWfQus6w= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1711669442; c=relaxed/simple; bh=QM8D2X/qqdZoIah1GG/ulyi5MbZ2CRFNu+wAF02+CJQ=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=bMGTcG9XsYvGgaHTKPkNQYXX73sJxd0CbTMlQub5oNp+ebRPDG3ctQE5LCgiRiRnVtUCLX9kKN+Ag9xxz8WGcr3kwUrAV3eIoncuTQ0lghqh+COspcUICxpfK7MDV/L23RYTyR8Hinohpp8nT6xgqpB/82y7F3ll2zcqXdf0lMY= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 42SLgwAK000943 for ; Thu, 28 Mar 2024 23:43:56 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=eRaDgjqujDppeorxCAWlgsdUrdNLTEF5h/ikpNwRPEQ=; b=S+lPIW9omdGUvEoKmhcOWFPrLiWjlpnb2qIRCcdJucC33esLtnFjfFK9/KRCukgCAOAC x3zyH3tjXz7h5egXDvOLoWjCylALOjdN4ednjQ7OhNFJ8pqhKwNjUW/OfeUC3hg+ms77 8HKPtQNX4EnXz6jHcrSYy6QXtV431kFK4V9imjyiLernDwMIba5yl0FSeWcrZ0LabM7Z /FWL02Kr35SYC3mVQuD1mg6gMcwuqMH3RIt2mu6sKUX0B3bYo9XFtTXmtwqVLd8ww7Rp JxfPA6xSRgwPS+3stIxB5/d59vOSzFxjxTf/QDluFzrzzVSLiuij49h8Z+36kW3+u2zz bQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x28cta4gh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 28 Mar 2024 23:43:55 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 42SLPCjP015141 for ; Thu, 28 Mar 2024 23:43:54 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3x1nhgwny9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 28 Mar 2024 23:43:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N+BcCDJfJGOoyqPNwyxDfX9rGOv+t4EkdYvcJ7UsrDtpUmvlH1d5j7W7tj/ZLd2cb7mGEm39Hxy0gtHUP1TFgVNBY73ouvuw7vet7muHqLALZKSNGa5BSUtdRfOCTfyd0SLFcw59s9vcw2JB7IX/xsigercOgp7A1Q36hrtlya/kH/vDxyfX/J7B4/Np/jpQ5yN/Gu4XqcT1W7DGp+wXoT/OZJuWS+6cb7d5QZMVMNqS1V17mG17m4rNtsPOH2KaLYSdu7ML8We3KujOR1N0TabkBNuLqWLRtSHv0oVEV9Vz6v1Jiz4WD0PDWvXqLEi6aJHvgANMkal50lXRy8O72g== 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=eRaDgjqujDppeorxCAWlgsdUrdNLTEF5h/ikpNwRPEQ=; b=e43OJcMOV2Qg2Gk5pjGZJrKZYghQs96FIEFUq/SRfeqjkBKWVjC7RfxJsMRbzPh9Jht/+j/U3ygoUaeNbaOl2++Hg2O7ReEhVFRuzJRr8C5YQ/hxyx05MyvHPZvK7RI73DWHXQlfNc40qlWA0Q+9sQwXEtr8eWLEO0jLZZYRCMhB2NNcjrO2zg95NNUgSUiXujp2QW2WtamIF0kzZhrEFAClpPVrhOqMkVqGPvblbFVh+A5NLwENAeQ7IOJUL2ozSv7r7irOGXmMUojC5ZQmu3SujLFm7ewAybInsYMoSTipzUbT/9nLkVpV3/aXQg/WbV2WQVv27sLsS3VeWV+Y9Q== 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=eRaDgjqujDppeorxCAWlgsdUrdNLTEF5h/ikpNwRPEQ=; b=U/h4Irxwv9UPkrlWy5GRjXSg2tCtsS1hNVNhXA1GX4cmx1A67gWA+/qOnUqQx58lGN3davYCcLyh8tskpi4PyEbw6ckoUNOMcAKbcuAewZtZXNc/i3RN4J2TRSF4V0TT0AOArW9mYiO9ldPCRonchTAvaTS3igA9l/W4K9KciOU= Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by BY5PR10MB4147.namprd10.prod.outlook.com (2603:10b6:a03:20e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.33; Thu, 28 Mar 2024 23:43:52 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::6ae9:dd4d:17bc:4f2]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::6ae9:dd4d:17bc:4f2%7]) with mapi id 15.20.7409.031; Thu, 28 Mar 2024 23:43:52 +0000 From: Indu Bhagat To: binutils@sourceware.org Cc: Indu Bhagat Subject: [PATCH 1/2] gas: gcfg: add_bb_at_ginsn must return root_bb Date: Thu, 28 Mar 2024 16:43:42 -0700 Message-ID: <20240328234343.3397845-2-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328234343.3397845-1-indu.bhagat@oracle.com> References: <20240328234343.3397845-1-indu.bhagat@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW4PR04CA0159.namprd04.prod.outlook.com (2603:10b6:303:85::14) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2158:EE_|BY5PR10MB4147:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bAWJbtuAeIKnCsg2H8KreFW7lz8B7PT4/E0SeGgc4yMXbXVSDUsk/UAOoKvNv/3xYPj3P0/VL/iHMQJDJlOU120LKoI8Qt7/oB3T/yAm2QOfRE6fhZd/+zUBc2teJqII4MihDniysLselRt21asv5ZcJ5oAuF+Xan4mfKfQzE3+7KHpWXYud9hziOjNfNgNGfYB2yt1IeA1AcjtBC8O3/uAe1JLuhRNwiwNqD49uYLwLIgTZEhmn9r5ARZGlPJJt4KgJ5dnJWEeV3CQoYd+yEUKMEcXb/WA/kpAvNshCQHu+HW6A83AskTHpgwBH7fFKYdqxWIpa+tLb0s0Nuxp8tgUyEcPF/u401sAv11FftwRsgcU9F4jJ9pMZH/0DjywoeHr/C2mm2bBeBD0txCfj6n4QK+k3m4rnRHYHeNmMO0myThBF/7ccqI4QqOKDM+vS6XhSD0re0zsFhMcQGUjX4Jvp/zgFoXBpqew1EYXQPBTavfwqe6vQNQ5J/jAEXKphKEi5tW6yzuKOPad+pqtozuaI3UC2A9xQEUBnvBYLgTebKt8wXk8vqLhvIeoN87Wu1hKGjc1VSSh5xqv69fzlPfxI5LmahJelinvactV2pKQ68HAysLmZzx5T6wDn+3FEhFfzuWu+0U5ELYs11vrALR2BdIOav8yWV2XFcjJzTTs= 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)(1800799015)(376005)(366007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?gdJJtuG/YMNhpPsZnqij0DOyR5cTwcUJPxpNQ7IdquS8/Q6a2SNZrHAywnFC?= =?us-ascii?Q?eHUxunlLhN/7ErvmTb1sF4MR2OtymI7fA7UqEdO2zQtTxd8UpJzK1bFN4GwR?= =?us-ascii?Q?Ao0yw/B5VLmUQzcXwvy7zykS8CsOWn22UX/V+jlKUxNJBLbiWiRXVEL41bcR?= =?us-ascii?Q?R+nZfgK29Q7/ilzMKRHGliWs+4Eq+062eub+kL0gKxa5sTeO+COfZgqeFxN9?= =?us-ascii?Q?pQ7oscH4QBtqH8Q984KFsT2KZXIPJXQGdm544pIiz3ujg14fJ8slpWJFuQJz?= =?us-ascii?Q?lJDyXUPMfA3VPXhzifXJSmVs+riqqCTt9Kzp2UytWeULBs8Ifqs9yF1pV5WI?= =?us-ascii?Q?+Q4BSogXL+CrlRbqW+0sYlagKsmNz057qMCJ/JkCYYmdl8mmgPaW/7nE95uH?= =?us-ascii?Q?n2wk7LNqvhIGnWH6EwcY1tUbERKNnkPK3qOj64EXpK4IY311SpRvwPK2/NrI?= =?us-ascii?Q?Riz4NJs7mSBujh+lYVgtFNRTC93UmCb9foIx1TveJJxxur2nu7sTaXZsGsZw?= =?us-ascii?Q?pLvHQHptxVBGLOpyPf+H+lUOVgkhNSWkovwdeEUqjG4JF22KoMll3z2/T+Ko?= =?us-ascii?Q?a7ZJnf6rWspYspB88buR5NbhP546+mRoVT2iH/OAhO3uQhKfQsCEkFScAkwi?= =?us-ascii?Q?KPqDuUQlqCFdG4HXjBXpGBa5JiSKUrkEAoIT7cKO5XVSQ3p2f+USr7JSwyH5?= =?us-ascii?Q?3rgTYEE59xMN481X7VIzBJoXPBdrFHsY50Yn9xzsllqGhlKZQsb2cQFD5e0u?= =?us-ascii?Q?qCpyu9yekEv4F3znoGa3E1R7jDaG7NXcNN3Or4yzfRBDbqoROMSCbsoMNpWs?= =?us-ascii?Q?Ex5mxO91Pj9nEs+7nLWICHjZ96mZm/d5wWXV5W4eEoE0UUO/kBZKwFBryNGe?= =?us-ascii?Q?/FHkBfPMxudN+ktqpnzd6h87xn6fsThUIc+/RQMFPrAhKIO747oFtoXc1ohl?= =?us-ascii?Q?7F3OR6V0IK/8FiR/TdUJuBIEB72uHv+1ff6bj6vFPkPEndk0Kk/PJwr9MWw/?= =?us-ascii?Q?5Ks1pjr39x3FGgD3cHaRP7+YCo/Qc8T5SilFU73aAJ1PsqEZtuttZcE406IL?= =?us-ascii?Q?qBgVA3JBIU1tzGSC8u5llgE55ZXbKHAOr8Bkv2SqyFY0Nzb9ks0elGhljQbW?= =?us-ascii?Q?/LIhld9tp7XJFTdaTEzR/Uu9paTpCbGsPGDxEOOugM/Nh/cm1n14L8wFuCio?= =?us-ascii?Q?9xDCJeIFALdEsrXGJxPEjhhk5e5kkYm/UyvCuWL551fWgGrjbmDbkYn76Pde?= =?us-ascii?Q?k40MMO5cEvRCJ9dZaLeaj8PTeCRpXbAWllD0fhxMunXstsnVWyZN3JLMgGs4?= =?us-ascii?Q?+nEQkbPgBI7cdCqnxuGuxtvqUEiJl6DJsrwJU2XAO7QWl3xTgHtLqfZ7c3qv?= =?us-ascii?Q?4O5lT13HyqcE57RpXUngtJyMF080qwABRAyivt9OROlGp2Z7ncBvbantvVBO?= =?us-ascii?Q?OZkP0Dazzzer1iGDOCsQZBwOhzUgANpb55NcrN68Od056RbBT1oaEbYQIuyW?= =?us-ascii?Q?797Jgmwan56szs4yuT18g2BBZi8xxKPf4c0JoyvBiS5IIWbX4AnM3el9YbB4?= =?us-ascii?Q?2m69BHDHoM8JAZscgwuTdTruqUkpfKBECpiPPP8ym3x5C1ONaUdSTqPTX6Xv?= =?us-ascii?Q?qKSrcMjSkJounCxi343UGUw=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: N2PSa8z7RfN1n8tbZv58aO2IPvjd5cijV5IZXzA11tOVwJDm8wWqRQMhsPNrSIDt2KFRw/Kw61WbJpQNFUTnfHtojMiga6H/Iidfsvus7hrTxgmshUHAtcMGMKnoONoL1REbTw//L9j0Mnsbp1FhjNk/7fPNJCKxpbTw6GV30/QDndjRJ/w/kob3SPMQJpVdBdT6pTXQ92ANGzZGxiHxcF4+z3jtB/9hCAarreY4sTWKGKGtnmQcG1Rz3gPWkzo65sU6JkVrpAF+qIXvuA/1q9kPmgZTXXhhtH6ZsOiMZVOPW9SbjP71p1BGMoC17wb6BbpN04hWv8PIs0gFxYeaG3WEyPwycl2bJO6EfRYFczUVYMeQZEdSBfdhpZ5IFxr9BQmXKPzGt+yWGjWj8VEDY2apvNqxIMh06A2Z8RmEMTsXw76exnuhyggOy9acheru8OioGC9qGNBNaR4zzkRrY/f7qDobAg8FoVYQhv0SjxjQjg/fMA4u3i+LWke6T0ztjZcCxHlH87zCSSgrRuHsS5OrN4OBZ+nzt92wqiGXixWgXwwAdNv8wsMtp3TQE/PSHACmOqnNaJjoJ7eKcpqwcfwYBGbmpCDEIs556cpGRRI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17fba225-dad4-4ee2-b2a4-08dc4f80ecab X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2024 23:43:52.6321 (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: mmN7SePaCyPqk+M9dhAa0z6/C2TW9Dl0FxStlKSsfEsyT4ZlvI5r5zHN87564uUvfDmuGfylXcR9QlDIDTbdvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4147 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-03-28_17,2024-03-28_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 suspectscore=0 mlxlogscore=720 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403280171 X-Proofpoint-GUID: WbnYJiiY23LX3MDDCZhSWskFHzdzN5yt X-Proofpoint-ORIG-GUID: WbnYJiiY23LX3MDDCZhSWskFHzdzN5yt X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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 List-Id: A GCFG (ginsn control flow graph) is created for SCFI purposes in GAS. The existing GCFG creation process was ignoring some paths. add_bb_at_ginsn () is a recursive function which should return the root of the added basic blocks. This property was being violated in some traversals, e.g., where a taken path involving a sequence of a few basic blocks eventually culminated in a GINSN_TYPE_RETURN instruction. This patch fixes the issue by keeping an explicit variable root_bb to memorize the bb to be returned. Next, find_or_make_bb () must either create or find the bb with the first ginsn as the provided ginsn. Add a few assertions to ensure health of the cfg creation process. Note that the testcase, in its current shape, is not fit for catching regressions for the issue at hand. Although the testcase does exercise the updated code path, the testcase passes even without the current fix, because the added edge in this specific testcase does not alter the synthesized CFI. (The missing edge is the fallthrough edge of the conditional branch "jne .L13" in the testcase.) Using a manual gcfg_print (), one can see the missing edge without the fix. Lets keep the testcase for now, until there is a better way to test the GCFG for this issue (e.g., either by dumping the GCFG in textual format, or a case when the missing edge does cause wrong synthesized CFI). gas/ * ginsn.c (bb_add_edge): Fix a code comment. (find_bb): Likewise. (find_or_make_bb): Add new assertions to ensure health of cfg creation process. (add_bb_at_ginsn): Keep reference to the root_bb and return it. gas/testsuite/ * gas/scfi/x86_64/scfi-x86-64.exp: Add new test. * gas/scfi/x86_64/scfi-cfg-4.d: New test. * gas/scfi/x86_64/scfi-cfg-4.l: New test. * gas/scfi/x86_64/scfi-cfg-4.s: New test. --- gas/ginsn.c | 95 ++++++++++++++----- gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.d | 43 +++++++++ gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.l | 2 + gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.s | 42 ++++++++ gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp | 2 + 5 files changed, 158 insertions(+), 26 deletions(-) create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.d create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.l create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.s diff --git a/gas/ginsn.c b/gas/ginsn.c index 492e161876b..4b58ade3302 100644 --- a/gas/ginsn.c +++ b/gas/ginsn.c @@ -614,6 +614,8 @@ gbb_cleanup (gbbS **bbp) *bbp = NULL; } +/* Add an edge from the source bb FROM_BB to the sink bb TO_BB. */ + static void bb_add_edge (gbbS* from_bb, gbbS *to_bb) { @@ -638,7 +640,7 @@ bb_add_edge (gbbS* from_bb, gbbS *to_bb) } else { - /* Get the tail of the list. */ + /* Get the head of the list. */ tmpedge = from_bb->out_gedges; while (tmpedge) { @@ -689,6 +691,9 @@ static gbbS * add_bb_at_ginsn (const symbolS *func, gcfgS *gcfg, ginsnS *ginsn, gbbS *prev_bb, int *errp); +/* Return the already existing basic block (if present), which begins with + GINSN, in the given GCFG. Return NULL otherwise. */ + static gbbS * find_bb (gcfgS *gcfg, ginsnS *ginsn) { @@ -708,13 +713,18 @@ find_bb (gcfgS *gcfg, ginsnS *ginsn) break; } } - /* Must be found if ginsn is visited. */ + /* Must be found because ginsn is visited. */ gas_assert (found_bb); } return found_bb; } +/* Get the basic block starting at GINSN in the GCFG. + + If not already present, the function will make one, while adding an edge + from the PREV_BB to it. */ + static gbbS * find_or_make_bb (const symbolS *func, gcfgS *gcfg, ginsnS *ginsn, gbbS *prev_bb, int *errp) @@ -722,26 +732,40 @@ find_or_make_bb (const symbolS *func, gcfgS *gcfg, ginsnS *ginsn, gbbS *prev_bb, gbbS *found_bb = NULL; found_bb = find_bb (gcfg, ginsn); - if (found_bb) - return found_bb; + if (!found_bb) + found_bb = add_bb_at_ginsn (func, gcfg, ginsn, prev_bb, errp); - return add_bb_at_ginsn (func, gcfg, ginsn, prev_bb, errp); + gas_assert (found_bb); + gas_assert (found_bb->first_ginsn == ginsn); + + return found_bb; } -/* Add the basic block starting at GINSN to the given GCFG. - Also adds an edge from the PREV_BB to the newly added basic block. +/* Add basic block(s) for all reachable, unvisited ginsns, starting from GINSN, + to the given GCFG. Also add an edge from the PREV_BB to the root of the + newly added basic block(s). - This is a recursive function which returns the root of the added - basic blocks. */ + This is a recursive function which returns the root of the added basic + blocks. */ static gbbS * add_bb_at_ginsn (const symbolS *func, gcfgS *gcfg, ginsnS *ginsn, gbbS *prev_bb, int *errp) { + gbbS *root_bb = NULL; gbbS *current_bb = NULL; ginsnS *target_ginsn = NULL; const symbolS *taken_label; + /* Create a new bb. N.B. The caller must ensure bb with this ginsn does not + already exist. */ + gas_assert (!find_bb (gcfg, ginsn)); + root_bb = XCNEW (gbbS); + cfg_add_bb (gcfg, root_bb); + root_bb->first_ginsn = ginsn; + + current_bb = root_bb; + while (ginsn) { /* Skip these as they may be right after a GINSN_TYPE_RETURN. @@ -749,6 +773,8 @@ add_bb_at_ginsn (const symbolS *func, gcfgS *gcfg, ginsnS *ginsn, gbbS *prev_bb, end of bb, and a logical exit from function. */ if (GINSN_F_FUNC_END_P (ginsn)) { + /* Dont mark them visited yet though, leaving the option of these + being visited via other control flows as applicable. */ ginsn = ginsn->next; continue; } @@ -765,27 +791,27 @@ add_bb_at_ginsn (const symbolS *func, gcfgS *gcfg, ginsnS *ginsn, gbbS *prev_bb, bb_add_edge (prev_bb, current_bb); break; } - else if (current_bb && GINSN_F_USER_LABEL_P (ginsn)) + else if (current_bb && current_bb->first_ginsn != ginsn + && GINSN_F_USER_LABEL_P (ginsn)) { - /* Create new bb starting at this label ginsn. */ + /* Create new bb starting at ginsn for (user-defined) label. This is + likely going to be a destination of a some control flow. */ prev_bb = current_bb; - find_or_make_bb (func, gcfg, ginsn, prev_bb, errp); + current_bb = find_or_make_bb (func, gcfg, ginsn, prev_bb, errp); + bb_add_edge (prev_bb, current_bb); break; } if (current_bb == NULL) { - /* Create a new bb. */ current_bb = XCNEW (gbbS); cfg_add_bb (gcfg, current_bb); + current_bb->first_ginsn = ginsn; /* Add edge for the Not Taken, or Fall-through path. */ if (prev_bb) bb_add_edge (prev_bb, current_bb); } - if (current_bb->first_ginsn == NULL) - current_bb->first_ginsn = ginsn; - ginsn->visited = true; current_bb->num_ginsns++; current_bb->last_ginsn = ginsn; @@ -809,16 +835,21 @@ add_bb_at_ginsn (const symbolS *func, gcfgS *gcfg, ginsnS *ginsn, gbbS *prev_bb, taken_label = ginsn->src[0].sym; gas_assert (taken_label); - /* Preserve the prev_bb to be the dominator bb as we are - going to follow the taken path of the conditional branch - soon. */ + /* Preserve the prev_bb to be the source bb as we are going to + follow the taken path of the conditional branch soon. */ prev_bb = current_bb; /* Follow the target on the taken path. */ target_ginsn = label_ginsn_map_find (taken_label); /* Add the bb for the target of the taken branch. */ if (target_ginsn) - find_or_make_bb (func, gcfg, target_ginsn, prev_bb, errp); + { + current_bb = find_or_make_bb (func, gcfg, target_ginsn, + prev_bb, errp); + gas_assert (prev_bb); + bb_add_edge (prev_bb, current_bb); + current_bb = NULL; + } else { *errp = GCFG_JLABEL_NOT_PRESENT; @@ -826,27 +857,39 @@ add_bb_at_ginsn (const symbolS *func, gcfgS *gcfg, ginsnS *ginsn, gbbS *prev_bb, _("missing label '%s' in func '%s' may result in imprecise cfg"), S_GET_NAME (taken_label), S_GET_NAME (func)); } - /* Add the bb for the fall through path. */ - find_or_make_bb (func, gcfg, ginsn->next, prev_bb, errp); + + if (ginsn->type == GINSN_TYPE_JUMP_COND) + { + /* Add the bb for the fall through path. */ + current_bb = find_or_make_bb (func, gcfg, ginsn->next, + prev_bb, errp); + gas_assert (prev_bb); + bb_add_edge (prev_bb, current_bb); + current_bb = NULL; + } + else + /* Unconditional jump. Current BB has been processed. */ + current_bb = NULL; } else { gas_assert (ginsn->type == GINSN_TYPE_RETURN || (ginsn->type == GINSN_TYPE_JUMP && !ginsn_direct_local_jump_p (ginsn))); + /* Current BB has been processed. */ + current_bb = NULL; + /* We'll come back to the ginsns following GINSN_TYPE_RETURN or other (non-local) unconditional jmps from another path if they are indeed reachable code. */ break; } - - /* Current BB has been processed. */ - current_bb = NULL; } + ginsn = ginsn->next; } - return current_bb; + return root_bb; } static int diff --git a/gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.d b/gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.d new file mode 100644 index 00000000000..841fc3c7202 --- /dev/null +++ b/gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.d @@ -0,0 +1,43 @@ +#as: --scfi=experimental -W +#as: +#objdump: -Wf +#name: Synthesize CFI in presence of control flow 4 +#... +Contents of the .eh_frame section: + +00000000 0+0014 0+0000 CIE + Version: 1 + Augmentation: "zR" + Code alignment factor: 1 + Data alignment factor: -8 + Return address column: 16 + Augmentation data: 1b + DW_CFA_def_cfa: r7 \(rsp\) ofs 8 + DW_CFA_offset: r16 \(rip\) at cfa-8 + DW_CFA_nop + DW_CFA_nop + +0+0018 0+002c 0+001c FDE cie=00000000 pc=0000000000000000..0000000000000045 + DW_CFA_advance_loc: 1 to 0000000000000001 + DW_CFA_def_cfa_offset: 16 + DW_CFA_offset: r3 \(rbx\) at cfa-16 + DW_CFA_advance_loc: 6 to 0000000000000007 + DW_CFA_def_cfa_offset: 32 + DW_CFA_advance_loc: 15 to 0000000000000016 + DW_CFA_remember_state + DW_CFA_advance_loc: 4 to 000000000000001a + DW_CFA_def_cfa_offset: 16 + DW_CFA_advance_loc: 1 to 000000000000001b + DW_CFA_restore: r3 \(rbx\) + DW_CFA_def_cfa_offset: 8 + DW_CFA_advance_loc: 1 to 000000000000001c + DW_CFA_restore_state + DW_CFA_advance_loc: 35 to 000000000000003f + DW_CFA_def_cfa_offset: 16 + DW_CFA_advance_loc: 1 to 0000000000000040 + DW_CFA_restore: r3 \(rbx\) + DW_CFA_def_cfa_offset: 8 + DW_CFA_nop +#... + +#pass diff --git a/gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.l b/gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.l new file mode 100644 index 00000000000..abca835a642 --- /dev/null +++ b/gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.l @@ -0,0 +1,2 @@ +.*Assembler messages: +.*5: Warning: SCFI ignores most user-specified CFI directives diff --git a/gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.s b/gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.s new file mode 100644 index 00000000000..ebcc6ad0cd0 --- /dev/null +++ b/gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.s @@ -0,0 +1,42 @@ + .text + .globl foo_handler + .type foo_handler, @function +foo_handler: + .cfi_startproc + pushq %rbx + .cfi_def_cfa_offset 16 + .cfi_offset %rbx, -16 + movl %esi, %ebx + subq $16, %rsp + .cfi_def_cfa_offset 32 + movl current_style(%rip), %eax + cmpl $-1, %eax + je .L12 + testb $4, %al + jne .L13 +.L1: + .cfi_remember_state + addq $16, %rsp + .cfi_def_cfa_offset 16 + popq %rbx + .cfi_restore %rbx + .cfi_def_cfa_offset 8 + ret +.L13: + .cfi_restore_state + movq %rdi, 8(%rsp) + call foo_handler_v2 + testq %rax, %rax + jne .L1 + movl current_style(%rip), %eax + movq 8(%rsp), %rdi + jmp .L3 +.L12: + addq $16, %rsp + .cfi_def_cfa_offset 16 + popq %rbx + .cfi_restore %rbx + .cfi_def_cfa_offset 8 + jmp xstrdup + .cfi_endproc + .size foo_handler, .-foo_handler 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 c004d99b4ac..63f0d7e4700 100644 --- a/gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp +++ b/gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp @@ -80,6 +80,8 @@ if { ([istarget "x86_64-*-*"] && ![istarget "x86_64-*-linux*-gnux32"]) } then { run_list_test "scfi-cfg-2" "--scfi=experimental --warn" run_dump_test "scfi-cfg-3" run_list_test "scfi-cfg-3" "--scfi=experimental --warn" + run_dump_test "scfi-cfg-4" + run_list_test "scfi-cfg-4" "--scfi=experimental --warn" run_dump_test "scfi-asm-marker-1" run_list_test "scfi-asm-marker-1" "--scfi=experimental --warn" run_dump_test "scfi-asm-marker-2" -- 2.43.0