From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140053.outbound.protection.outlook.com [40.107.14.53]) by sourceware.org (Postfix) with ESMTPS id CB1CA3858294 for ; Fri, 5 Aug 2022 14:59:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB1CA3858294 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-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=SAKgEch4Dt443PZCWOJPi4F2CoR4tIUMdozLYzddchOlHEKZXDKwnPhdd/JdiJsH3U7xcmC8VYkNQTfDEl3XnJuE5bxS3vYrGiqB0/mcVu7RKqsedm0vCP9TnTIGXrDgUoz9ZzbWAK8rt1ad912zdcrYok9b5eBD4DxCGPMWlfO64sKlhLjNchdXB9ZuCkR4NjFoPQ6uelX4VBs1m679c1ME2kv82DQDCN4LfkiUWv/52GMv4TTSYWlAfnRDQIbNxp6yfuLznt18Cp68LvmivZ5nyjv9VH6Q76pMi6cIBR+MpvpK7jnfUqrTT+GtkXQhq+J5bNvMCXYWi9m7PFThXg== 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=JccqPfkKFv35rcCsZJq3m8MRl6KAsAw4OTbQ6SGSs3s=; b=HljFV/AH/VvYqgkwruFnlb9Rk5EiYSQg6wu3rx+RH/qYEuno2pnrJR/QYhl1XOBeHtVqsbnX7z3xxXGkK//IddtJ2fbt0ss79Vl8PShJkT18KZ9r9iOrZJw5uXeDPKThCG2MZ3A5bkMz3LTVcUIFX/5G44/2EGEa68s/NnxJMJ4Z5+qQIHQUURWQdeQoauI21uzw7OSwupgujpG7i+R2rV0PEkZ8rXXH6aGGqsUjAGOR7SWjZ1fmpXNTTQURpDE4wTe0qCPA58d5AQBq1/FKiyE902JwurYhcKALKhThYoD7ZyB9mIbHghlVPd5iS4uNalfsaYUMVWhBjvFVp2yyxA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.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=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1, 1, smtp.mailfrom=arm.com] dmarc=[1, 1, header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JccqPfkKFv35rcCsZJq3m8MRl6KAsAw4OTbQ6SGSs3s=; b=wwMVMs2Z8XPSNGqkz2hE12AGuAwgQ/wGKf8tHR6SzHsX98uwxPtRDl+7soP98BsLs371Wt18IwYpLqytvzyEvwRsx0G1CRjMEFXj2xsDQR9SFyy8xkER21XixCPYFyDVncWJ4ITCCnBebqubijS9Q8ezQZ/zLbxf24FcfuH5DjU= Received: from AS9PR06CA0136.eurprd06.prod.outlook.com (2603:10a6:20b:467::28) by AM9PR08MB6209.eurprd08.prod.outlook.com (2603:10a6:20b:283::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14; Fri, 5 Aug 2022 14:59:05 +0000 Received: from VE1EUR03FT048.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:467:cafe::9a) by AS9PR06CA0136.outlook.office365.com (2603:10a6:20b:467::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.15 via Frontend Transport; Fri, 5 Aug 2022 14:59:05 +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=armh.onmicrosoft.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 VE1EUR03FT048.mail.protection.outlook.com (10.152.19.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16 via Frontend Transport; Fri, 5 Aug 2022 14:59:05 +0000 Received: ("Tessian outbound 63c09d5d38ac:v123"); Fri, 05 Aug 2022 14:59:05 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 9f686c484253c3c6 X-CR-MTA-TID: 64aa7808 Received: from 16456c18073c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 306822C2-9E94-44F4-8E6D-517BA8F609AA.1; Fri, 05 Aug 2022 14:58:57 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 16456c18073c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 05 Aug 2022 14:58:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HBVpuzPZ/N572tLZZnO4rzovB17D38bwBg03KscKv4A9TEn0+1PRqWTXHfdzfy8hr7+UV62iaJr2JQyafyqLfznO0ovj0Qd12dYzUHKjh7zrXey9IbH+5jN7IloDpqDW++jc/kMcJ3A/c8BwxP5F9zKcQ1chmnmlvabLQ6hi3+mo3jLwYs5DScl1P+Wrt/5KLGrnciT3c3udqFzQtDCN0CC1LsfcFsqInf+4WRxyvH/7L1hyjpJ3qhAxm+KE81eeR0TKHVfbAMrIJzkhllKn0fQoFjE+d8kyHeVOi9xP6oRLry3zrJVF5llgYCIeluVSWbWR7KGZ6CQ92AungqVmKw== 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=JccqPfkKFv35rcCsZJq3m8MRl6KAsAw4OTbQ6SGSs3s=; b=ayYjLE+yjGAfr7M06U6F5uSOicOnvqvzf9BmgH5nm2qjmTWmlo8Ftpb9y9MKSxgCIUbl8fCzHbeGP0MaUgfGXKUaIwUiZoZMn2Te45PAXSc7PerOfXtbCU5o/vMpEC3ooKn/gLzyLUCCJ6D0aLlbDJ9N4lM0K836MYGaV9/lWW5+Wpf8w84lWigL0Q6LfeARYYjjTfSFCTG9TwEtLNXOWSUswTDvn2q3dLR7X+XuM9844MzObu9LchzVu4Bt6h8KBtTDl4HtaZVyZYsSbDOhvbiO/ybvpXcCDAa9qzrdFV27wAKkohvhP7xjrYXzvsa+JB9+GFOE5XMPdhGBHcnymw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JccqPfkKFv35rcCsZJq3m8MRl6KAsAw4OTbQ6SGSs3s=; b=wwMVMs2Z8XPSNGqkz2hE12AGuAwgQ/wGKf8tHR6SzHsX98uwxPtRDl+7soP98BsLs371Wt18IwYpLqytvzyEvwRsx0G1CRjMEFXj2xsDQR9SFyy8xkER21XixCPYFyDVncWJ4ITCCnBebqubijS9Q8ezQZ/zLbxf24FcfuH5DjU= Received: from DU2PR04CA0200.eurprd04.prod.outlook.com (2603:10a6:10:28d::25) by DB7PR08MB3562.eurprd08.prod.outlook.com (2603:10a6:10:49::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.14; Fri, 5 Aug 2022 14:58:56 +0000 Received: from DBAEUR03FT012.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:28d:cafe::55) by DU2PR04CA0200.outlook.office365.com (2603:10a6:10:28d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.15 via Frontend Transport; Fri, 5 Aug 2022 14:58:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT012.mail.protection.outlook.com (100.127.142.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5504.16 via Frontend Transport; Fri, 5 Aug 2022 14:58:56 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2507.9; Fri, 5 Aug 2022 14:58:55 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.9; Fri, 5 Aug 2022 14:58:55 +0000 Received: from e125768 (10.2.78.50) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.9 via Frontend Transport; Fri, 5 Aug 2022 14:58:55 +0000 From: "Victor L. Do Nascimento" To: Richard Earnshaw CC: , Subject: Re: [PATCH v2 2/8] newlib: libc: strcmp M-profile PACBTI-enablement In-Reply-To: (Richard Earnshaw's message of "Fri, 5 Aug 2022 15:34:39 +0100") References: <20220803153524.20631-1-victor.donascimento@arm.com> <20220803153524.20631-3-victor.donascimento@arm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) Date: Fri, 5 Aug 2022 15:58:55 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 71867f97-c316-4915-1db7-08da76f30ac1 X-MS-TrafficTypeDiagnostic: DB7PR08MB3562:EE_|VE1EUR03FT048:EE_|AM9PR08MB6209:EE_ 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: bxfjTvJJymZ4s7klq5MEasIpliNSBUuU3VrodX5hxjAzz2+qqkE0DBf+RQVqRlJEPSLJE2SZTFdKgAEYN8wwSTMGirQ2blExoARKDzCfzmdvmQHyU6Mo/JW4NyPFUX8jiYEd+2ws1lTJOSH6bvluiH/iqldkhEhj8hOWdBD1wC3Fpji1+3aOD367X7HBRgk9oldYrbll5lopx2OAg/C4d7DNLGyEhMGM2fK6Qodqa5e4BI3HuG2J5/12tHK/YWwucJWTQYoAJBg2WRW+VNZU9Atj44IL3phOhQlW2IzvQhTgpMxQV1Vpzo10mPQO7P8xv5M9vAQEvu5ZaABFsCBEY3XPYmcHYXWEw0ffI+GkKlJZ892Qk0PS1Mq5fDYj8GudFMU9vNBHY/jekmcpiHw1HcgRaPVyWkdpEb1T7PzI4s5Ntu6DwXPixeOUJKgIryRQaDkuzoHBX9xBCzPWzwFHC/IbFglubfpJR1f8O7GvnrW7SpIPsROpCoyYcrrHZto4KQF5IjQ7EULC84MPZxUo0UmYfl+YwR59tFBdMwEDrGx845V9OM2IZHZFVY19o7P4IxrZ75o9I1876lCZ+l+xHgzW7cFtJ3QWDljxypgNtMZsG+zqI2Dh/xFEJzMd5EjMKXjwhRJcjD2uLt617GRxis3tVaP/X3muz6E4kdCD098meaRKqg1spKj2u3gpePArdUOry2GlsEDrtQSjyNDBb6KmaMH8mNJOuaPy1v8GMTO208xDXGhBkd5ibRJxJnpDqX2+3e7ORLyNGL5dg9aNcqCAh1yWZ9ePPSSrxx10PuyFEGl2YP6DK9XJoXgIqOihGMfG3RYTkWXBsB5oGVxeOok2z/8trst8HDJRXpuS3jc= X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(346002)(396003)(39860400002)(136003)(376002)(40470700004)(46966006)(36840700001)(5660300002)(30864003)(40460700003)(70586007)(6862004)(70206006)(336012)(186003)(8936002)(82310400005)(4326008)(86362001)(2906002)(40480700001)(81166007)(83380400001)(426003)(356005)(47076005)(478600001)(82740400003)(36860700001)(8676002)(26005)(316002)(54906003)(53546011)(2616005)(41300700001)(36756003)(40753002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3562 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 198b349d-9a26-4821-ccfb-08da76f30525 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NZUntJuwiDeWxaesX3NWJjCXscejVgFmHGMG7qLg7YVX+VBoYfCYd4ChfYMW5WF+FRY9lWJk8+//icdQmHlWEhUEoeckmZD9wVJyFIzk9xzj75EhI0cLq0S/O74INxdZXQBHxkSbJ1vm4CwB9ImRK7Kdy8kD3ewzEi2ROZgsVvmKYph9VnqRLoVQh7zYaGCKM9uusoLq1B7BBX4LHJaGArxUKaVhjv0mEYvZbVHpnnzxuTXx3o0D5kLWixPljlP9wvDWpRUam87rjh9IAGHCGGPpvZ8wisiHveW18lH4a9+ql+0La9iJnGsD3p+ptdyBC9biZccak2Fx6ACXLYKrtHZAiuTjri1d6T2GMCTmNM4W+mXHSpYzAAh4FupIdlXh/t8M2ibadaZ526arFOtfmZuSOZDix6RNpQI2DG3RBfbNYm032Sym1TfWuLLW6QDMkgw6hHsiktltXY55m08und9sNR9CQM7yZp7vP/ArWjX+ivLLBwH1mJHEUS2RLyTFO75H6EDNJzjhcAkmsTDlnJzTt8GIqq/YgXe1hRjosuIgIpDZD1D2uz9TLbfQ0mECLOE0k45A22SuQnJlACRx4rppz2SObIvJF/V/wIsDp9BP17tW+S96OlMEwOKrKX4XG9Fb5gHvTjgqPSVbylOAms2hx/InR0EpbhUCNx11EZ5Ivqixgjt9/RrXxpeU+kTSxlkFYXWJ5hO9diQZc095OPBo7D4FEPzYLU638IkfJtx6YbVq8bsx/T3xWtcJwROw/NQ0K8XC0sI3R1QqGbOzuHnNE+eoRiHDH5kudVorpQx34aZec3xMZlw7QzuJCsZYdrCkVH/cfaAxn26HuMLwxg== 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:(13230016)(4636009)(376002)(346002)(136003)(396003)(39860400002)(36840700001)(40470700004)(46966006)(70206006)(36860700001)(86362001)(70586007)(316002)(336012)(426003)(2616005)(53546011)(186003)(54906003)(47076005)(8676002)(40480700001)(26005)(82740400003)(82310400005)(478600001)(81166007)(4326008)(41300700001)(83380400001)(40460700003)(30864003)(6862004)(8936002)(36756003)(5660300002)(2906002)(40753002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2022 14:59:05.4499 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 71867f97-c316-4915-1db7-08da76f30ac1 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: VE1EUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6209 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, 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: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Aug 2022 14:59:13 -0000 Richard Earnshaw writes: > On 05/08/2022 11:51, Victor L. Do Nascimento wrote: >> Richard Earnshaw writes: >> >>> On 03/08/2022 16:35, Victor Do Nascimento wrote: >>>> Add function prologue/epilogue to conditionally add BTI landing pads >>>> and/or PAC code generation & authentication instructions depending on >>>> compilation flags. >>>> This patch enables PACBTI for all relevant variants of strcmp: >>>> * Newlib for armv8.1-m.main+pacbti >>>> * Newlib for armv8.1-m.main+pacbti+mve >>>> * Newlib-nano >>>> --- >>>> newlib/libc/machine/arm/strcmp-arm-tiny.S | 7 +++- >>>> newlib/libc/machine/arm/strcmp-armv7.S | 45 +++++++++++++++++------ >>>> newlib/libc/machine/arm/strcmp-armv7m.S | 36 +++++++++++++++--- >>>> 3 files changed, 71 insertions(+), 17 deletions(-) >>>> diff --git a/newlib/libc/machine/arm/strcmp-arm-tiny.S >>>> b/newlib/libc/machine/arm/strcmp-arm-tiny.S >>>> index 607a41daf..8085eb4df 100644 >>>> --- a/newlib/libc/machine/arm/strcmp-arm-tiny.S >>>> +++ b/newlib/libc/machine/arm/strcmp-arm-tiny.S >>>> @@ -29,10 +29,14 @@ >>>> /* Tiny version of strcmp in ARM state. Used only when optimizing >>>> for size. Also supports Thumb-2. */ >>>> +#include "pacbti.h" >>>> + >>>> .syntax unified >>>> def_fn strcmp >>>> + .fnstart >>>> .cfi_sections .debug_frame >>>> .cfi_startproc >>>> + pacbti_prologue >>> >>> See comment on patch1 about the names of these macros. >>> >>>> 1: >>>> ldrb r2, [r0], #1 >>>> ldrb r3, [r1], #1 >>>> @@ -42,6 +46,7 @@ def_fn strcmp >>>> beq 1b >>>> 2: >>>> subs r0, r2, r3 >>>> - bx lr >>>> + pacbti_epilogue >>>> .cfi_endproc >>>> + .fnend >>>> .size strcmp, . - strcmp >>>> diff --git a/newlib/libc/machine/arm/strcmp-armv7.S b/newlib/libc/machine/arm/strcmp-armv7.S >>>> index 2f93bfb73..584c89f7e 100644 >>>> --- a/newlib/libc/machine/arm/strcmp-armv7.S >>>> +++ b/newlib/libc/machine/arm/strcmp-armv7.S >>>> @@ -45,6 +45,8 @@ >>>> .thumb >>>> .syntax unified >>>> +#include "pacbti.h" >>>> + >>>> /* Parameters and result. */ >>>> #define src1 r0 >>>> #define src2 r1 >>>> @@ -91,8 +93,9 @@ >>>> ldrd r4, r5, [sp], #16 >>>> .cfi_restore 4 >>>> .cfi_restore 5 >>>> + .cfi_adjust_cfa_offset -16 >>> >>> This looks like it's an omission from the original file and thus >>> should be separated out as a separate patch. >>> >>>> sub result, result, r1, lsr #24 >>>> - bx lr >>>> + pacbti_epilogue >>>> #else >>>> /* To use the big-endian trick we'd have to reverse all three words. >>>> that's slower than this approach. */ >>>> @@ -112,22 +115,28 @@ >>>> ldrd r4, r5, [sp], #16 >>>> .cfi_restore 4 >>>> .cfi_restore 5 >>>> + .cfi_adjust_cfa_offset -16 >>>> sub result, result, r1 >>>> - bx lr >>>> + pacbti_epilogue >>>> #endif >>>> .endm >>>> + >>>> .text >>>> .p2align 5 >>>> + .fnstart >>>> + .cfi_sections .debug_frame >>>> + .cfi_startproc >>>> .Lstrcmp_start_addr: >>>> #ifndef STRCMP_NO_PRECHECK >>>> .Lfastpath_exit: >>>> sub r0, r2, r3 >>>> - bx lr >>>> + pacbti_epilogue >>>> nop >>>> #endif >>>> def_fn strcmp >>>> + pacbti_prologue >>>> #ifndef STRCMP_NO_PRECHECK >>>> ldrb r2, [src1] >>>> ldrb r3, [src2] >>>> @@ -136,16 +145,26 @@ def_fn strcmp >>>> cmpcs r2, r3 >>>> bne .Lfastpath_exit >>>> #endif >>>> - .cfi_sections .debug_frame >>>> - .cfi_startproc >>>> strd r4, r5, [sp, #-16]! >>>> - .cfi_def_cfa_offset 16 >>>> + .save {r4, r5} >>> >>> Hmm, I've just remembered that leaf functions cannot throw exceptions >>> (the EHABI only supports synchronous exceptions), so I don't think we >>> need .save directives at all. Instead, such functions should be >>> marked with ".cantunwind". You still want the dwarf unwind >>> information as that's for the debugger, it's just the '.save' >>> directives that aren't needed. >>> >>>> + .cfi_adjust_cfa_offset 16 >>>> +#if __HAVE_PAC_LEAF >>>> + .cfi_offset 4, -20 >>>> + .cfi_offset 5, -16 >>>> +#else >>>> .cfi_offset 4, -16 >>>> .cfi_offset 5, -12 >>>> +#endif /* __HAVE_PAC_LEAF */ >>> >>> Ugh! This is not the right way to do this. Instead (see comments on >>> patch 1) use a macro that defines the additional adjustment to use in >>> various contexts, something like >>> >>> .cfi_offset 4, -(16+PAC_UNALIGNED_CFI_ADJ) >>> >>>> orr tmp1, src1, src2 >>>> strd r6, r7, [sp, #8] >>>> + .save {r6, r7} >>>> +#if __HAVE_PAC_LEAF >>>> + .cfi_offset 6, -12 >>>> + .cfi_offset 7, -8 >>>> +#else >>>> .cfi_offset 6, -8 >>>> .cfi_offset 7, -4 >>>> +#endif /* __HAVE_PAC_LEAF */ >>>> mvn const_m1, #0 >>>> lsl r2, tmp1, #29 >>>> cbz r2, .Lloop_aligned8 >>>> @@ -270,7 +289,6 @@ def_fn strcmp >>>> ldr data1, [src1], #4 >>>> beq .Laligned_m2 >>>> bcs .Laligned_m1 >>>> - >>>> #ifdef STRCMP_NO_PRECHECK >>>> ldrb data2, [src2, #1] >>>> uxtb tmp1, data1, ror #BYTE1_OFFSET >>>> @@ -314,7 +332,8 @@ def_fn strcmp >>>> mov result, tmp1 >>>> ldr r4, [sp], #16 >>>> .cfi_restore 4 >>>> - bx lr >>>> + .cfi_adjust_cfa_offset -16 >>>> + pacbti_epilogue >>>> #ifndef STRCMP_NO_PRECHECK >>>> .Laligned_m1: >>>> @@ -364,8 +383,9 @@ def_fn strcmp >>>> /* R6/7 Not used in this sequence. */ >>>> .cfi_restore 6 >>>> .cfi_restore 7 >>>> + .cfi_adjust_cfa_offset -16 >>>> neg result, result >>>> - bx lr >>>> + pacbti_epilogue >>>> 6: >>>> .cfi_restore_state >>>> @@ -441,7 +461,8 @@ def_fn strcmp >>>> /* R6/7 not used in this sequence. */ >>>> .cfi_restore 6 >>>> .cfi_restore 7 >>>> - bx lr >>>> + .cfi_adjust_cfa_offset -16 >>>> + pacbti_epilogue >>>> .Lstrcmp_tail: >>>> .cfi_restore_state >>>> @@ -463,7 +484,9 @@ def_fn strcmp >>>> /* R6/7 not used in this sequence. */ >>>> .cfi_restore 6 >>>> .cfi_restore 7 >>>> + .cfi_adjust_cfa_offset -16 >>>> sub result, result, data2, lsr #24 >>>> - bx lr >>>> + pacbti_epilogue >>>> .cfi_endproc >>>> + .fnend >>>> .size strcmp, . - .Lstrcmp_start_addr >>>> diff --git a/newlib/libc/machine/arm/strcmp-armv7m.S b/newlib/libc/machine/arm/strcmp-armv7m.S >>>> index cdb4912df..fe1519f4d 100644 >>>> --- a/newlib/libc/machine/arm/strcmp-armv7m.S >>>> +++ b/newlib/libc/machine/arm/strcmp-armv7m.S >>>> @@ -29,6 +29,8 @@ >>>> /* Very similar to the generic code, but uses Thumb2 as implemented >>>> in ARMv7-M. */ >>>> +#include "pacbti.h" >>>> + >>>> /* Parameters and result. */ >>>> #define src1 r0 >>>> #define src2 r1 >>>> @@ -44,8 +46,10 @@ >>>> .thumb >>>> .syntax unified >>>> def_fn strcmp >>>> + .fnstart >>>> .cfi_sections .debug_frame >>>> .cfi_startproc >>>> + pacbti_prologue >>>> eor tmp1, src1, src2 >>>> tst tmp1, #3 >>>> /* Strings not at same byte offset from a word boundary. */ >>>> @@ -106,7 +110,7 @@ def_fn strcmp >>>> lsrs result, result, #24 >>>> subs result, result, data2 >>>> #endif >>>> - bx lr >>>> + pacbti_epilogue >>>> #if 0 >>>> @@ -214,12 +218,18 @@ def_fn strcmp >>>> cmpcs data1, data2 >>>> beq .Lstrcmp_unaligned >>>> sub result, data1, data2 >>>> - bx lr >>>> + pacbti_epilogue >>>> 2: >>>> stmfd sp!, {r5} >>>> - .cfi_def_cfa_offset 4 >>>> + .save {r5} >>>> + .cfi_adjust_cfa_offset 4 >>>> +#if __HAVE_PAC_LEAF >>>> + .cfi_offset 5, -8 /* Account for ip register already on stack. */ >>>> +#else >>>> .cfi_offset 5, -4 >>>> +#endif /* __HAVE_PAC_LEAF */ >>>> + >>>> ldr data1, [src1], #4 >>>> and tmp2, src2, #3 >>>> @@ -353,10 +363,17 @@ def_fn strcmp >>>> .Lstrcmp_done_equal: >>>> mov result, #0 >>>> .cfi_remember_state >>>> +#if __HAVE_PAC_LEAF >>>> + pop {r5, ip} >>>> + .cfi_restore 5 >>>> + .cfi_restore 143 >>>> + aut ip, lr, sp >>>> +#else >>>> ldmfd sp!, {r5} >>>> .cfi_restore 5 >>>> +#endif /* __HAVE_PAC_LEAF */ >>> >>> I think we could define a macro for this as well, something like >>> pop_reg_and_pac r5 >> This sounds good, but a survey through relevant function epilogues >> reveals a series of different `pop' scenarios. On the one hand, we have >> pop {r5, ip}, as we have here but on another we also have, for example, >> pop {r4,r5,r6,r7,ip}. >> Do we wish to provide a short-hand notation for one pop operation >> but >> not the other via macros? My initial understanding is that assembler >> macros don't provide us with the necessary flexibility to handle all >> relevant cases. >> I think the use of a macro here would greatly enhance code >> readability >> and by extension maintainability, but at first sight it feels inelegant >> to provide a solution applicable only to a single case of a more general >> problem. >> Any wisdom here would be appreciated. > > Yes, this is all quite tricky. Fortunately, the vast majority of time > registers saved on the stack frame are consecutively numbered. So I > think it's possible to write some macros to handle this. The example > below is not complete (I'll leave you to flesh out all the different > cases :), but I think it shows that we can achieve what's needed. > > @ Emit .cfi_offset directives for a consecutive sequence of registers > .macro cfisavelist first, last, count > .cfi_offset \last, -4*(\count) > .if \last-\first > cfisavelist \first, \last-1, \count+1 > .endif > .endm > > @ Create a prologue entry sequence handling PAC/BTI, if required and > emitting > @ CFI directives for > .macro prologue first=-1, last=-1, savepac=1 > .if \first != -1 > .if \last != -1 > .if \savepac > push {r\first-r\last, ip} > .cfi_offset 143, -4 > cfisavelist \first, \last, 2 > .else > push {r\first-r\last} > cfisavelist \first, \last, 1 > .endif > .else > push {r\first} > cfisavelist \first, \first, 1 > .endif > .else > ... > .endif > .endm > > .text > .global foo > .type foo, %function > foo: > .cfi_startproc > prologue 4, 7, savepac=0 > .cfi_endproc > > .text > .global bar > .type bar, %function > bar: > .cfi_startproc > prologue 4, 7 > .cfi_endproc > > .text > .global wom > .type wom, %function > wom: > .cfi_startproc > prologue 4, savepac=0 > .cfi_endproc > > .text > .global bat > .type bat, %function > bat: > .cfi_startproc > prologue savepac=0 > .cfi_endproc > > R. Thanks for these, they'll come in extremely handy. Regarding the pop_reg_and_pac macro you suggested, I'd concocted a solution which at first sight seemed to make minimal assumptions about what we're asking it to pop and, looking at initial example disassemblies, seems to behave well. I'll share it with you here in case you come across anything warranting feedback. Furthermore, I will see whether it will be of any use in building upon your example. .macro cfi_restore_list first:req, rest:vararg .cfi_restore \first .ifnb \rest cfi_restore_list \rest .endif .endm .macro pop_reg_and_pac first:req, rest:vararg .ifnb \rest pop {\first, \rest, ip} .else pop {\first, ip} .endif cfi_restore_list \first, \rest .cfi_restore 143 aut ip, lr, sp .endm As always, thanks for your input. V. >> V. >> >>> While you're doing that, please change the single-register ldmfd into 'pop'. >>> >>>> .cfi_def_cfa_offset 0 >>>> - bx lr >>>> + bx lr >>> >>> stray change to the BX instruction. >>> >>>> .Lstrcmp_tail: >>>> .cfi_restore_state >>>> @@ -370,9 +387,18 @@ def_fn strcmp >>>> S2LOEQ data2, data2, #8 >>>> beq .Lstrcmp_tail >>>> sub result, r2, result >>>> +#if __HAVE_PAC_LEAF >>>> + pop {r5, ip} >>>> + .cfi_restore 5 >>>> + .cfi_restore 143 >>>> + .cfi_def_cfa_offset 0 >>>> + aut ip, lr, sp >>>> +#else >>>> ldmfd sp!, {r5} >>>> .cfi_restore 5 >>>> .cfi_def_cfa_offset 0 >>>> - bx lr >>>> +#endif /* __HAVE_PAC_LEAF */ >>> >>> Same as above >>> >>>> + bx lr >>> >>> tab between mnemonic and operands. >>> >>>> .cfi_endproc >>>> + .fnend >>>> .size strcmp, . - strcmp >>> >>> R.