From patchwork Wed Apr 24 15:55:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Ball X-Patchwork-Id: 88959 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 2DE233849AF7 for ; Wed, 24 Apr 2024 15:56:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2052.outbound.protection.outlook.com [40.107.241.52]) by sourceware.org (Postfix) with ESMTPS id 16EC6385840D for ; Wed, 24 Apr 2024 15:56:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16EC6385840D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 16EC6385840D Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.241.52 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1713974179; cv=pass; b=EvUy6Cia7uGSo0em0oyREqWXeg5GepFeI/Rzz9GAtaRHlP729vjp6CDN4BdSqjUBvBcdecQWL++FFoTSsX9KITlvdR8Iooj+B6Q9/CKE2tXfnXk5GFy7BT71rhrMlOyekEMvzR8Of6X9WJUprM3IFNw5che3kC2yKlAoqQigvcI= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1713974179; c=relaxed/simple; bh=+HrQwIPo/JX5wzKDASU3T0QcwEVrp0c2Tfuz47YMVrA=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:To:From:Subject: MIME-Version; b=PlGEGkfBvSLQs8itH53t/4d9j8Cci9eUSuTxmAZa1HNQ0BKeQlpAXhWqoREZ+MxF0JYupoYFHQdK0/cdhcek/k39uMYlRpORucZsvHo/GW/OVBM8slBgiXH0X64SDzpRldKQGFX023WlNV6a9F1DeZHWmJ8qyL4tkjRqr+FapzM= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=oJO/0O+vM9STBHFL00N/VWac/hNHkeoVumPgISp7SZLdPOUnN60mQPd5NdAJD6kuYPGNVt4CGRo+eFG7BwiVZt5lhV4tNVce+MAmh15jXqrV1TzwRCMdBaPBmRKT8ORazBK1KN03e68VDvxi5j+5GG0ELhKncJFrLtDO3Q8rf590Dq5Q/Pnjkk+4vHCLU0+qkmHGQwVxMcivrdwac46Z2R/9mj1JNxYO6Rc8eYtDV5byOyUxCCgmPfQYihy4yxxWGV0LKYiqVqUIGqcAkCK9so7z1pthM054IWvXw1F8EC59gq+g4d/83/qx9AJlXxzwfI8NRRw8vMav0FfuzQbh2Q== ARC-Message-Signature: i=2; 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=Ry94+tyt+z1jY33zBuraXPx2ZIuXnuWB/uZ8ytCg+ig=; b=V0T2d2w16mNzHE+njqDJfxiRvFefCq3hBy6No4rN+w8LScWQf5rPd7GZ0OUBjfIeesHQFcRrjc4/eKzNEKgJUGOHqU+rUGpIO3NiyiJM7UIwVODIntoMx6p1l3B8K1vIS8NIOUjSK1W94PjiosY9y0Df6ZQzHgVRUNT3CX6ZH08qryy34wbXQEQHef6tT9dM6k/kkF9jr4ahR88wmX9wZABRKjmfOKrTOnP9UIAQVwWkW8eQiI4stC0L38B3L9bTPWDX5TxsfRs96CifhZak5TMx3gOnK5tk2o7YmqJkTEnj0UBrbRlNHqi5V0ZUB3gOhasBrjP6FlEyOj1KBiD/yA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ry94+tyt+z1jY33zBuraXPx2ZIuXnuWB/uZ8ytCg+ig=; b=JiZDF1/aXVzB3hK3z15f7GxtNXzeVYxp1pM/ra0tZ+fn5u4r8LRC9oGzPND9uxJTpxBz3GH/y+eyGZ0U+Kx8fGcG/rvPyTFIycfHs23ebCLm+bF44UluiwphKomzcuqx5f98ZS0cVRD/KRlH0YWo80vHim3QJyMy0pD9eN8+xTM= Received: from DB9PR02CA0024.eurprd02.prod.outlook.com (2603:10a6:10:1d9::29) by AS2PR08MB10349.eurprd08.prod.outlook.com (2603:10a6:20b:57b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22; Wed, 24 Apr 2024 15:56:12 +0000 Received: from DB5PEPF00014B9A.eurprd02.prod.outlook.com (2603:10a6:10:1d9:cafe::38) by DB9PR02CA0024.outlook.office365.com (2603:10a6:10:1d9::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.35 via Frontend Transport; Wed, 24 Apr 2024 15:56:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5PEPF00014B9A.mail.protection.outlook.com (10.167.8.167) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:56:11 +0000 Received: ("Tessian outbound daa456608199:v315"); Wed, 24 Apr 2024 15:56:10 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: f2f6d9228ab5d9d7 X-CR-MTA-TID: 64aa7808 Received: from 73fa350548ce.3 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 34A53271-5E2B-4253-9E82-A547345AA1A8.1; Wed, 24 Apr 2024 15:55:59 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 73fa350548ce.3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 24 Apr 2024 15:55:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TZ/YSClRr9MK7QLY2BkSgSVU6m8/UsH1HjyEKz7HOZ9tGEv01bFuBijIK1DZ9N+JsPvExrJqYWDJ/hbNnCE9zhp+1cTn10pC58/wPfhEp8kTANNV2xnd8or2CVxD2Fp4HgzvPYZg9uAogzLdTToi3yc8AXdm+u6siarvJQksWoxieKd6Wz+kjapODGLKzC0zhqNh+/+G79qOBlqTtRwzB3qePZqlW8f72UxHrBucOdJctDZWc03VLedv+3ts+ziZLhhNTPJ9uNzjTKFsfLCXyjVcJg2Uzw3hJ1enGnfRM5ilp4jWM2SHvcr3XNDp4cqFE/hWl4bLzsVU3C4SFq68LQ== 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=Ry94+tyt+z1jY33zBuraXPx2ZIuXnuWB/uZ8ytCg+ig=; b=I1pBEXMkCYJyc+a4Xc9FIF4Qpg4bImpXv2AQx9JrJTraAzzBN0219JBhSlVVIKLdIPnkKqaHvdlAN60A+GgI8wzTu3Dr1uC99y/qFVuWVVt9qCJu7BkcBeDx/8UhyCXosZxmxtWuVV79Fl8QC48AVkMAYGYbNwUHW89lLIB7D6c5g5ezQMJtDPU2tkx9hfwKQBYQrvHKmJnR7NVcfjsa8le/S2DHrWompc2rV0kq/mGAuDu5lphP9YecndxvGA/3KvUjwi2voLA2du0Ml47jhExGojumvotNxAdKGSuEYonQX9JKeVF6EcWzF4d5doPTiWau1sWpXi7YJjxt7BQloA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ry94+tyt+z1jY33zBuraXPx2ZIuXnuWB/uZ8ytCg+ig=; b=JiZDF1/aXVzB3hK3z15f7GxtNXzeVYxp1pM/ra0tZ+fn5u4r8LRC9oGzPND9uxJTpxBz3GH/y+eyGZ0U+Kx8fGcG/rvPyTFIycfHs23ebCLm+bF44UluiwphKomzcuqx5f98ZS0cVRD/KRlH0YWo80vHim3QJyMy0pD9eN8+xTM= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from DB9PR08MB6957.eurprd08.prod.outlook.com (2603:10a6:10:2bc::10) by GV2PR08MB9325.eurprd08.prod.outlook.com (2603:10a6:150:d5::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 15:55:56 +0000 Received: from DB9PR08MB6957.eurprd08.prod.outlook.com ([fe80::5c14:ca3c:588b:1b39]) by DB9PR08MB6957.eurprd08.prod.outlook.com ([fe80::5c14:ca3c:588b:1b39%5]) with mapi id 15.20.7519.021; Wed, 24 Apr 2024 15:55:55 +0000 Message-ID: <33b2e8aa-9aa6-48e3-acef-0bab99676595@arm.com> Date: Wed, 24 Apr 2024 16:55:53 +0100 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "gcc-patches@gcc.gnu.org" , Richard Earnshaw , Richard Sandiford , Marcus Shawcroft , Kyrylo Tkachov From: Richard Ball Subject: [PATCH] arm: Zero/Sign extends for CMSE security X-ClientProxiedBy: LO2P265CA0045.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::33) To DB9PR08MB6957.eurprd08.prod.outlook.com (2603:10a6:10:2bc::10) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: DB9PR08MB6957:EE_|GV2PR08MB9325:EE_|DB5PEPF00014B9A:EE_|AS2PR08MB10349:EE_ X-MS-Office365-Filtering-Correlation-Id: bbc204da-51e0-4476-33ea-08dc64771093 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Nc6/4xpuRQVl2IZ/wtHfVzV2QRVT+/HcaTm4G54lQIoy60OqeLLG5Fw6KtLDWew0kvChQYikB2jwR2c8RaHE4/VJIy6D2EVRX36EvKZYNzAmCOcTvoNV7fPabyOTYwEN/CEgmIpGAb0qpK04N8JOq3P57uJXOs4lEpllKEes3NZR4tqClVZ8AOI/4xOECj4k+ygTZbGuBUKoc5wjogEbnSaxlv6AELY5UWOsS8brukKP9yRkefI9cTT3TAx+oxqqhmMjgYLHmnk7GiE+UQD14OrB5aC72LY0HEPiFH2ZLJrg4n0jn1k2w80mAmcFihpjy7QGhJiRAByKvlvnY4EMZfEAYfjhXtM7lwZFVPflyzSE1H/G6tZDbDkUymQR7M6r1xmbbimJpy/qiIzZgz37XZX45kqkhcgM5ccSEBiqDIj41EtHBaM0OSOeFJLExAPwjz9TCx5Qyph8KzQTX9fwY/PV2vvJqBC3zRr+jnkFs173WbG0/BYAiTh44Y9U6BaTHy53rjsGwZU+ivLNFF/FwyHGI2wQeYp7ctmIJPUZTH1RmNZyFjeM1pFYpYBPj1bFSo/xUOWTVuh7/aN6fQswKJpv5YmNyhD+QuRu/D+PC3OjYFXJUYhHKkkT6qRZn+1kLib6OeTrzLCehzqsFPEGMibC4HwvcFHhPk0ttzdCq1TrSKPb3tuLYedzePfgZdHLW0YI9CmY15Mph6dxvTm7/RWByFurV94vygu8OmRVGUPzcLjU5cAD/32zX42qEtK+isuePexbnjQ3VVtdychBoQ/phxdwWQ6gJRaQnC56Eu7OexL1drg+Y5KdeaN+E2hKg73YMCV6Ni8IBLcUU95ZfYegdctUw5VUDxLYFWx/lUjLkpJ59UVt5hTM4zsyh15Txpp5tcuXU8BW7hDZqKwWA0F2GQ93oHofzI03ihT3xtE9f15oZhXFMd6l3KxChjPEGN147iumdv5nZkmueKNooPDxKifAJA2H0J9iPJBzt/IigNGwTqz/3TUQalTlZ8ToDKZT/odEIuzwsy8mplcTHuXLXQz7ER51crCBzfwLQbnlIKxlfQ0U7lL4+FVpKQp5VZM5ICOr7QACzS/qKVbVMBdUbj3YWQKwXOYq9mRUuez1pAyJZmc3G0LGO9IzVIdVMoqj0llOvZ5/8E/7Nc66yWmE3jlHyACePwg0K1g0nSvhVlgt1IRfMSjpusjah9hXH7gOcBEEEJ3JX64gBpPEYSlm6ueiteWySxYtjaMBDE8= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB6957.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366007)(1800799015)(376005); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB9325 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5PEPF00014B9A.eurprd02.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 14f0506f-538c-4e94-879f-08dc6477068c X-Microsoft-Antispam: BCL:0; ARA:13230031|36860700004|376005|1800799015|82310400014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?pqLhAUDpriT97AoeAnmjxpepllFN9TS?= =?utf-8?q?NwUDDfGJjQc4uTJJrFyohKCaYUcG42tbIthd4ak59vB9c6Tr2k5eTnVMV1WzS2ooz?= =?utf-8?q?A+fdPxqbcI5IRS2yqRl3+tkDcVSpFXsjULgVVTslFUz17pnScVLA0VUxSrTb8hirJ?= =?utf-8?q?YMmHx20uXDl7q+wOYWPa+9PFqawu0cyDlAL2gSNaXNOoIig2TqYlEoz/1esgEICvu?= =?utf-8?q?Gae0SK7NLbEN9M9bBnrG2uzgkt7ivgf+KgZ4VTZUBWG1Z00KyKWAts8539S6TJAa9?= =?utf-8?q?2s1twlLVn2H4EiRXYJsjsLa6p6vJbMsquaBhQLUoZ9EqbagTm8naoGLBQwvb/jgzN?= =?utf-8?q?Y3pu535+RtTwe8O0pS/5xWrviZvtIyvH+xnRkzEKBKGoMmCqAs/P4tYOtjQ4VmhSv?= =?utf-8?q?OXXYNA57vWX8vBfHL7J2PXG80Rrs7fLDeJptNHOFwEIJZM1yIVU0pQ8pfjUElnFJY?= =?utf-8?q?RB/6WskhMVOyJspldGe9Sl3dK8Gjf1KD8aJzqTG7UlaUY158EW8T9gMDVvb3sQG5e?= =?utf-8?q?y1jqV8i/fXeSUIEj8qHf2zsioxOlhejCEism6eRJ/Pgo6WrJfoM9nh4dhzyGT3+U8?= =?utf-8?q?DRLqMduf4sSwt44CAQA9gPXBZFUbf1Wqof/uxS1AX0F9Ry8ZkwliMQGE5zOWTjCOU?= =?utf-8?q?HKv6h/BThXBC03NN2tDwmJRrW6dRcmL3YS9dp96KTA5fH6lMxO9guQKH2iICA9WLO?= =?utf-8?q?TPf+rbLj8fJVWh8wwjxm8hs7dyyi6bdWxJMLJTUJ/aHsQYJU9fXLsgHosCEiZyd0R?= =?utf-8?q?KGUdx1QB3WHxlRNV/NkA0HI72k6/3mLvmxvbkvs1x2fCDtZvubYV17JDdXbOBNq2C?= =?utf-8?q?PxeWeIRbUDfVQ/11pgUdZld8IPhDrOUmkAJBMUtvWt4OaMT+WX5Al4mDmhjh0y4Vm?= =?utf-8?q?7tp//v+xall7ZfpnxOxbh9GnHuDsNnQBhIyvLtpqRt/E6Lms/xY5DBjvB43brc3A2?= =?utf-8?q?ft7l5lus2Q96RsGn/9kaVG9PIo0z1kWzJwOQx++md93/JOJnAZBwk0Gypv4hP/pFF?= =?utf-8?q?ysFjgVeVOBzXvyMv9jH8axeYUfH2OWTXRrGLxm4o9jTjFpAEBHyqvuvZWS9Zele74?= =?utf-8?q?9ap+OKsLnPgTJGgkeWTz7YjK3REUgOISnKhOr2g8DczRH6D1ayfw0mELHVAwXDu71?= =?utf-8?q?cYUmi2PN7VXrIeyJ3nW/LCX/zBZTHS2d2jpc8ApqU2BHQZwm+zoN4D2+hsZSfaKqQ?= =?utf-8?q?Myr3TFMdyslVkyl/Ps0wetc8W+SdHHzPc9ds+9O0eeipWR1HvPl8dxSWy2rRaUv6f?= =?utf-8?q?DV9ZdwliaIcdfiW4svg4iqOCV39qNGo7Waw=3D=3D?= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230031)(36860700004)(376005)(1800799015)(82310400014); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:56:11.6579 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bbc204da-51e0-4476-33ea-08dc64771093 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5PEPF00014B9A.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB10349 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org This patch makes the following changes: 1) When calling a secure function from non-secure code then any arguments smaller than 32-bits that are passed in registers are zero- or sign-extended. 2) After a non-secure function returns into secure code then any return value smaller than 32-bits that is passed in a register is zero- or sign-extended. This patch addresses the following CVE-2024-0151. gcc/ChangeLog: PR target/114837 * config/arm/arm.cc (cmse_nonsecure_call_inline_register_clear): Add zero/sign extend. (arm_expand_prologue): Add zero/sign extend. gcc/testsuite/ChangeLog: * gcc.target/arm/cmse/extend-param.c: New test. * gcc.target/arm/cmse/extend-return.c: New test. diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index 0217abc218d60956ce727e6d008d46b9176dddc5..ea0c963a4d67ecd70e1571624e84dfe46d757df9 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -19210,6 +19210,30 @@ cmse_nonsecure_call_inline_register_clear (void) end_sequence (); emit_insn_before (seq, insn); + /* The AAPCS requires the callee to widen integral types narrower + than 32 bits to the full width of the register; but when handling + calls to non-secure space, we cannot trust the callee to have + correctly done so. So forcibly re-widen the result here. */ + tree ret_type = TREE_TYPE (fntype); + if ((TREE_CODE (ret_type) == INTEGER_TYPE + || TREE_CODE (ret_type) == ENUMERAL_TYPE + || TREE_CODE (ret_type) == BOOLEAN_TYPE) + && known_lt (GET_MODE_SIZE (TYPE_MODE (ret_type)), 4)) + { + machine_mode ret_mode = TYPE_MODE (ret_type); + rtx extend; + if (TYPE_UNSIGNED (ret_type)) + extend = gen_rtx_ZERO_EXTEND (SImode, + gen_rtx_REG (ret_mode, R0_REGNUM)); + else + extend = gen_rtx_SIGN_EXTEND (SImode, + gen_rtx_REG (ret_mode, R0_REGNUM)); + emit_insn_after (gen_rtx_SET (gen_rtx_REG (SImode, R0_REGNUM), + extend), insn); + + } + + if (TARGET_HAVE_FPCXT_CMSE) { rtx_insn *last, *pop_insn, *after = insn; @@ -23652,6 +23676,51 @@ arm_expand_prologue (void) ip_rtx = gen_rtx_REG (SImode, IP_REGNUM); + /* The AAPCS requires the callee to widen integral types narrower + than 32 bits to the full width of the register; but when handling + calls to non-secure space, we cannot trust the callee to have + correctly done so. So forcibly re-widen the result here. */ + if (IS_CMSE_ENTRY (func_type)) + { + function_args_iterator args_iter; + CUMULATIVE_ARGS args_so_far_v; + cumulative_args_t args_so_far; + bool first_param = true; + tree arg_type; + tree fndecl = current_function_decl; + tree fntype = TREE_TYPE (fndecl); + arm_init_cumulative_args (&args_so_far_v, fntype, NULL_RTX, fndecl); + args_so_far = pack_cumulative_args (&args_so_far_v); + FOREACH_FUNCTION_ARGS (fntype, arg_type, args_iter) + { + rtx arg_rtx; + + if (VOID_TYPE_P (arg_type)) + break; + + function_arg_info arg (arg_type, /*named=*/true); + if (!first_param) + /* We should advance after processing the argument and pass + the argument we're advancing past. */ + arm_function_arg_advance (args_so_far, arg); + first_param = false; + arg_rtx = arm_function_arg (args_so_far, arg); + gcc_assert (REG_P (arg_rtx)); + if ((TREE_CODE (arg_type) == INTEGER_TYPE + || TREE_CODE (arg_type) == ENUMERAL_TYPE + || TREE_CODE (arg_type) == BOOLEAN_TYPE) + && known_lt (GET_MODE_SIZE (GET_MODE (arg_rtx)), 4)) + { + if (TYPE_UNSIGNED (arg_type)) + emit_set_insn (gen_rtx_REG (SImode, REGNO (arg_rtx)), + gen_rtx_ZERO_EXTEND (SImode, arg_rtx)); + else + emit_set_insn (gen_rtx_REG (SImode, REGNO (arg_rtx)), + gen_rtx_SIGN_EXTEND (SImode, arg_rtx)); + } + } + } + if (IS_STACKALIGN (func_type)) { rtx r0, r1; diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c new file mode 100644 index 0000000000000000000000000000000000000000..01fac7862385f871f3ecc246ede95eea180be025 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c @@ -0,0 +1,96 @@ +/* { dg-do compile } */ +/* { dg-options "-mcmse" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +#include +#include + +#define ARRAY_SIZE (256) +char array[ARRAY_SIZE]; + +enum offset +{ + zero = 0, + one = 1, + two = 2 +}; + +/* +**__acle_se_unsignSecureFunc: +** ... +** uxtb r0, r0 +** ... +*/ +__attribute__((cmse_nonsecure_entry)) char unsignSecureFunc (unsigned char index) { + if (index >= ARRAY_SIZE) + return 0; + return array[index]; +} + +/* +**__acle_se_signSecureFunc: +** ... +** sxtb r0, r0 +** ... +*/ +__attribute__((cmse_nonsecure_entry)) char signSecureFunc (signed char index) { + if (index >= ARRAY_SIZE) + return 0; + return array[index]; +} + +/* +**__acle_se_shortUnsignSecureFunc: +** ... +** uxth r0, r0 +** ... +*/ +__attribute__((cmse_nonsecure_entry)) char shortUnsignSecureFunc (unsigned short index) { + if (index >= ARRAY_SIZE) + return 0; + return array[index]; +} + +/* +**__acle_se_shortSignSecureFunc: +** ... +** sxth r0, r0 +** ... +*/ +__attribute__((cmse_nonsecure_entry)) char shortSignSecureFunc (signed short index) { + if (index >= ARRAY_SIZE) + return 0; + return array[index]; +} + +/* +**__acle_se_enumSecureFunc: +** ... +** uxtb r0, r0 +** ... +*/ +__attribute__((cmse_nonsecure_entry)) char enumSecureFunc (enum offset index) { + + // Compiler may optimize away bounds check as value is an unsigned char. + + // According to AAPCS caller will zero extend to ensure value is < 256. + + if (index >= ARRAY_SIZE) + return 0; + return array[index]; + +} + +/* +**__acle_se_boolSecureFunc: +** ... +** uxtb r0, r0 +** ... +*/ +__attribute__((cmse_nonsecure_entry)) char boolSecureFunc (bool index) { + + if (index >= ARRAY_SIZE) + return 0; + return array[index]; + +} \ No newline at end of file diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c new file mode 100644 index 0000000000000000000000000000000000000000..cf731ed33df7e6dc101320c1970016f01b14c59a --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c @@ -0,0 +1,92 @@ +/* { dg-do compile } */ +/* { dg-options "-mcmse" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +#include +#include + +enum offset +{ + zero = 0, + one = 1, + two = 2 +}; + +typedef unsigned char __attribute__ ((cmse_nonsecure_call)) ns_unsign_foo_t (void); +typedef signed char __attribute__ ((cmse_nonsecure_call)) ns_sign_foo_t (void); +typedef unsigned short __attribute__ ((cmse_nonsecure_call)) ns_short_unsign_foo_t (void); +typedef signed short __attribute__ ((cmse_nonsecure_call)) ns_short_sign_foo_t (void); +typedef enum offset __attribute__ ((cmse_nonsecure_call)) ns_enum_foo_t (void); +typedef bool __attribute__ ((cmse_nonsecure_call)) ns_bool_foo_t (void); + +/* +**unsignNonsecure0: +** ... +** bl __gnu_cmse_nonsecure_call +** uxtb r0, r0 +** ... +*/ +unsigned char unsignNonsecure0 (ns_unsign_foo_t * ns_foo_p) +{ + return ns_foo_p (); +} + +/* +**signNonsecure0: +** ... +** bl __gnu_cmse_nonsecure_call +** sxtb r0, r0 +** ... +*/ +signed char signNonsecure0 (ns_sign_foo_t * ns_foo_p) +{ + return ns_foo_p (); +} + +/* +**shortUnsignNonsecure0: +** ... +** bl __gnu_cmse_nonsecure_call +** uxth r0, r0 +** ... +*/ +unsigned short shortUnsignNonsecure0 (ns_short_unsign_foo_t * ns_foo_p) +{ + return ns_foo_p (); +} + +/* +**shortSignNonsecure0: +** ... +** bl __gnu_cmse_nonsecure_call +** sxth r0, r0 +** ... +*/ +signed short shortSignNonsecure0 (ns_short_sign_foo_t * ns_foo_p) +{ + return ns_foo_p (); +} + +/* +**enumNonsecure0: +** ... +** bl __gnu_cmse_nonsecure_call +** uxtb r0, r0 +** ... +*/ +unsigned char __attribute__((noipa)) enumNonsecure0 (ns_enum_foo_t * ns_foo_p) +{ + return ns_foo_p (); +} + +/* +**boolNonsecure0: +** ... +** bl __gnu_cmse_nonsecure_call +** uxtb r0, r0 +** ... +*/ +unsigned char boolNonsecure0 (ns_bool_foo_t * ns_foo_p) +{ + return ns_foo_p (); +} \ No newline at end of file