From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id B8BA89419E5 for ; Thu, 26 Oct 2023 15:32:15 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=HmgYr+quTatODmoRTTo3M/bfNC9CwDhsowK5kb9sRrw=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1698334334; v=1; b=dloGmUHjNjIT8hbyzdivunBTWVHTn9ebRhRpaYv1+EodzDRsmMlz3G0qHtK/bWakb+7IkpKT rEaZCRQksSyHox571zB9spT+EkcG64+GAwk4XepDvl1u8oqmhcculzwomQwSdDLoVViTMtm3SfG W15ZDNO613oL52QVkip1pFrQ= X-Received: by 127.0.0.2 with SMTP id v18uYY7687511xhrLXIz7GL6; Thu, 26 Oct 2023 08:32:14 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.59]) by mx.groups.io with SMTP id smtpd.web10.203528.1698334333646106281 for ; Thu, 26 Oct 2023 08:32:13 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bBJZRRd1NJGk5RN1+C++vRyYj7FZ2lbveOzxOSIF+bn58qSJvE5v2f7YXCDEL+vHC7Pz7Es68cGefkIpoBp8o46rXK7YnTHDKs05ZAXL8jlaU3+sJ1DIDb2ZEB02gOSrrJn3usOfW6vSpOiwlajzV++Ncdfo51nF3JVaw0MTPhTeHxuqnsDYFdAGJUS8D1v+Sjs6GjBP0aTY2hYRl7suIKPkSoK9/p45R3JjEExjLLldT1tkbpnAewMD8m7TrnecioZhNT0Upz3I2kFvrZ9XZb6NepnK/hjBvrlPxmHSXJk5XWz+3re++p9Ezg8Mi3yhoAUs8PsU+pueDp83Iun2bg== 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=bF/nRi9WQlFhtMMiLzJf+KmGVipZJBYtHcw+I94L1Bg=; b=fbOZXrzsbn9u4RjTjyAp9kb4EY+yFlgP4c8s+B6JOw6zEE39KWypllp1Qh36j81/yIIrWOM11fpNWzNg4cfUeMGxnWRkZBb5OgvAQvauaRfpVZOGTYycWOA3nvO+pX0scEjr9wRcRTpCWZet7L7o/Sx8YH57iWrdim3FOKAlY+idGRAoP3IBjaAVfGMJmtmO3sMEfV5dsofM4y+ifaW7XJaOhMElIVfwR23Fl60vLcEOZT02KXqC5+drBNA3doB0ZSXiNJpOH4rJBB8srr/4kLNDF6Vv/jJBmkFqqMsIuUt3pB9UMWBGr8cprM3xbnEEf5aQjnWb/tMjHFMj/Qw+rg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) X-Received: from CY8P220CA0006.NAMP220.PROD.OUTLOOK.COM (2603:10b6:930:46::24) by SJ2PR12MB8062.namprd12.prod.outlook.com (2603:10b6:a03:4c8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19; Thu, 26 Oct 2023 15:32:10 +0000 X-Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:930:46:cafe::ae) by CY8P220CA0006.outlook.office365.com (2603:10b6:930:46::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.22 via Frontend Transport; Thu, 26 Oct 2023 15:32:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.118.233) by CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.15 via Frontend Transport; Thu, 26 Oct 2023 15:32:10 +0000 X-Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 26 Oct 2023 08:32:00 -0700 X-Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 26 Oct 2023 08:31:59 -0700 X-Received: from jake-build.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Thu, 26 Oct 2023 08:31:59 -0700 From: "Jake Garver via groups.io" To: CC: , , , , , Jake Garver Subject: [edk2-devel] [PATCH] BaseTools/GenFw: Change opcode when converting ADR to ADRP Date: Thu, 26 Oct 2023 08:31:48 -0700 Message-ID: MIME-Version: 1.0 X-NVConfidentiality: public X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9CD:EE_|SJ2PR12MB8062:EE_ X-MS-Office365-Filtering-Correlation-Id: a4aba57b-6bde-4caa-3ed8-08dbd638b84c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: xajsQmDNKj+BAjAmjZGcGutHNptTGCi6ibKAaxtUv8MFGJbJdxCfawuJ/34oYNS2v33iViTKDmONUtROurgQcsFQE1SBEWaBleqUzzP6dYwPIOvcmE9oX8yfuEO0iwQ/vX8PbbWoqPjANNBmBlsJwMzNgUNsxkMCgYxrNSpmxSkZxKO0h0xOCPfnx45Z0zw27quQnNgL27ay2S5aoekFBi8S8GWbXbnhb8Q2xJ7D8M60jfcgG+FELfOEWRNWdh13EdSNx2aAlInKvlDL9qH+akMwQeTVdca+txHuFN60vihkgn52EiwAND/YPDk1SC6o2EY7g3Mu23IqXQCjuxy0TwBSLJ6MovkplVi7K99sYHcc9jEXSKP5EnelTErvMKXzO+LxZbGaJ5xta98LrtHcTqFoBrFWnpJR9rFEv2U78BWIfXbKs8qARHjgXr5x+276PVn7DlMaPdwqUSts47QFc9zUhM0bxhX0+xNJQzaKvyJxTKgsslR1XpojXu0xlj6jjioL0azev19+34a20iiEGNCgGT9/GkQf4+CQrl30b2559r1A0Gzq8/NNPfjp62RgMTtGpd/G8ZPlp8x0f9JmFqZfjowVGbl5dYOjegfBMMNmS9EKQfjSinSV4QDGGt1NzYkk/ZCHYBidPpzz9d+F9ZqypgA6SFwee4ZxhOeXwW2DJMD56QwXuE6A5ta+WP+OUD+nCRbc51VusEowKHgEkUqiZlYXCwa7K3cJbCll56PWrwFJ8bJc3KmneiyhBF2k X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2023 15:32:10.0636 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a4aba57b-6bde-4caa-3ed8-08dbd638b84c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8062 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,jake@nvidia.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: m5IPSI5fbM20sZXcDe2KHtWKx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=dloGmUHj; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io In the R_AARCH64_ADR_GOT_PAGE case on AARCH64, be sure to change the opcode to ADRP. Prior to this change, we updated the address, but not the opcode. This resolves an issue experienced when building a StandaloneMm image with stack protection enabled on GCC 10.5. This scenario generates an ADR where an ADRP is more common in other versions of GCC tested. That explains the obscurity of the issue. However, an ADR is valid and should be handled by GenFw. Using the stack protection scenario as an example, the following code is being generated by the toolchain: # Load to set the stack canary 2ffc: 10028020 adr x0, 8000 3008: f940d400 ldr x0, [x0, #424] # Load to check the stack canary 30cc: b0000020 adrp x0, 8000 30d0: f940d400 ldr x0, [x0, #424] GenFw rewrote that to: # Load to set the stack canary 2ffc: 10000480 adr x0, 0x308c 3008: 912ec000 add x0, x0, #0xbb0 # Load to check the stack canary 30cc: f0000460 adrp x0, 0x92000 30d0: 912ec000 add x0, x0, #0xbb0 Note that we're now setting the stack canary from the wrong address, resulting in an erroneous stack fault. After this fix, the opcode is also updated, so GenFw rewrites it to: 2ffc: 90000480 adrp x0, 0x92000 3008: 912ec000 add x0, x0, #0xbb0 And the stack canary is set correctly. Signed-off-by: Jake Garver --- BaseTools/Source/C/GenFw/Elf64Convert.c | 1 + 1 file changed, 1 insertion(+) diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/G= enFw/Elf64Convert.c index 9911db65af..4669ac3a2d 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -1565,6 +1565,7 @@ WriteSections64 ( Offset =3D (Sym->st_value - (Rel->r_offset & ~0xfff)) >> 12; =20 *(UINT32 *)Targ &=3D 0x9000001f; + *(UINT32 *)Targ |=3D 0x90000000; *(UINT32 *)Targ |=3D ((Offset & 0x1ffffc) << (5 - 2)) | ((Offs= et & 0x3) << 29); =20 /* fall through */ --=20 2.34.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110120): https://edk2.groups.io/g/devel/message/110120 Mute This Topic: https://groups.io/mt/102202314/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-