From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2086.outbound.protection.outlook.com [40.107.22.86]) by sourceware.org (Postfix) with ESMTPS id AF6F43858D1E for ; Wed, 21 Dec 2022 11:24:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AF6F43858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=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=68JqfHxOgv2CgzzzYWHCfgWaHkSIH+g38kJeF+qtC5M=; b=7ylYSgKwOd7JGDOz/ze59yX0JxrF1lQ/3nDv9CioOv1V74rx9ED34tVRVe3d7E9EOTTM9dehZHQW2DXH+f0iVGp0U1zS04A1LVvQJip1StM6l3joHfAJLzQ2HCUjHkoBk+2zN2QukhGPLZ5d9D7FynguBNbb4TqspR5yA7w+rDU= Received: from AS8PR04CA0023.eurprd04.prod.outlook.com (2603:10a6:20b:310::28) by DB5PR08MB10046.eurprd08.prod.outlook.com (2603:10a6:10:48f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.6; Wed, 21 Dec 2022 11:24:13 +0000 Received: from VI1EUR03FT057.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:310:cafe::8f) by AS8PR04CA0023.outlook.office365.com (2603:10a6:20b:310::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.21 via Frontend Transport; Wed, 21 Dec 2022 11:24:13 +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 VI1EUR03FT057.mail.protection.outlook.com (100.127.144.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.10 via Frontend Transport; Wed, 21 Dec 2022 11:24:13 +0000 Received: ("Tessian outbound 0d7b2ab0f13d:v132"); Wed, 21 Dec 2022 11:24:12 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 4f5d4d3e23c6f492 X-CR-MTA-TID: 64aa7808 Received: from e2e228dd20d2.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F7B60BD4-2133-4372-9215-CE0ABC4B5DC7.1; Wed, 21 Dec 2022 11:24:05 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e2e228dd20d2.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 21 Dec 2022 11:24:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E1oZezvoHwS7ofcCpSW3yUkmuffLBUXb95wbEoqTRWK3Gke9d2cIMFj6F3yAQz2gcuo/x1Mmnmaj2KCYLQaQW2vERz0KpyuExc3NV+0eRhmoZ2gASy6bXdw9hxbJOHJdoTqK+DEIiLGwm6STjzN0azkmEvODqCTkqWrEdgQ0LCpM8LRQjIzwsjYC9MK/s0tIT6Ln1UIFTNl5dj1ry0jfZ+d/V3tWQWYu2pwwTJFEzamUOaEBGJ7h+dZr8ErOGeno3Li4OB5OcRGav44W0Re/JnpOeOwh698YIgGv1Z27baw7Eaeh6Z0E+3U+xl5tsV+d4kb0VLMBWfFr8APZ7RYaKQ== 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=68JqfHxOgv2CgzzzYWHCfgWaHkSIH+g38kJeF+qtC5M=; b=gqWVIeFnd0cEEMqkycwqczq/bs9/1tbSZy4Iq2erhWPdFv3KU1vbmx+Vv9BgpvRz6ERV+O+hNYMW4C9xmyrQGbPg+2g2yxfmfQGObOh977cue+oJ6bcdBsR/sJY80qyr5mz3vtXHSaUVNu2c0Oj5VVs5ZBPof5/XWfpJLaDy+g78llusOxNEDq8n8+dPK3gQvfG9XuHY0qiRsfEDT186WDJgDBryJWSuCNyMABJnush5OxnSgQ3wYBA1F/9lT6X/R5wxg/jb9BFJFriK5ChbyAZgOViU64/yOMpceORklhRdRmmJfGtfsY+YVBXEmWodX0BKT2LZufjK5zsrwPSNLg== 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=68JqfHxOgv2CgzzzYWHCfgWaHkSIH+g38kJeF+qtC5M=; b=7ylYSgKwOd7JGDOz/ze59yX0JxrF1lQ/3nDv9CioOv1V74rx9ED34tVRVe3d7E9EOTTM9dehZHQW2DXH+f0iVGp0U1zS04A1LVvQJip1StM6l3joHfAJLzQ2HCUjHkoBk+2zN2QukhGPLZ5d9D7FynguBNbb4TqspR5yA7w+rDU= Received: from DB6PR07CA0159.eurprd07.prod.outlook.com (2603:10a6:6:43::13) by DBAPR08MB5637.eurprd08.prod.outlook.com (2603:10a6:10:1b0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.6; Wed, 21 Dec 2022 11:24:03 +0000 Received: from DBAEUR03FT059.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:43:cafe::d4) by DB6PR07CA0159.outlook.office365.com (2603:10a6:6:43::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.10 via Frontend Transport; Wed, 21 Dec 2022 11:24:03 +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 DBAEUR03FT059.mail.protection.outlook.com (100.127.142.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5944.10 via Frontend Transport; Wed, 21 Dec 2022 11:24:03 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Wed, 21 Dec 2022 11:24:01 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Wed, 21 Dec 2022 11:24:00 +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.16 via Frontend Transport; Wed, 21 Dec 2022 11:24:00 +0000 From: "Victor L. Do Nascimento" To: CC: Richard Earnshaw Subject: [PATCH v5 4/8] newlib: libc: memchr M-profile PACBTI-enablement In-Reply-To: (Victor Do Nascimento's message of "Wed, 21 Dec 2022 11:03:41 +0000") References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Date: Wed, 21 Dec 2022 11:24:00 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DBAEUR03FT059:EE_|DBAPR08MB5637:EE_|VI1EUR03FT057:EE_|DB5PR08MB10046:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b51ca18-e9cc-4855-fd71-08dae345e34e 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: 3TnCUIh6aqYqz30dhlEF4NJ/9MgEvVyb6mzLV8MFn4E6wYecovy7Xb6D76sXyDkCyABi871kZjk/TcZXtICZ5JTE3aGBxPr7Ypj5D7nqgYNasL6JnXR3NSj+NhXiWd1bd3/ulsfVVLQllFrigWON8S+EIgC65qXPAUfTdcP8xTmruhbCx0SpfFZ8G3w9HDOsBbG89Sy2GijFc1Su9jHM/dBYFTKZxr8+sRjX2+WZoy1bt1CdKCA6nn0pRes05BBlcOgGYZrzw3o4l7WR/G/OaJ/3J3B5v9DoUJ54v7ByVVnJgjvg3ItsU7qMoT0E2uD/T0CbXULmbQy2Tdhync3nSy5QvyCCoBs71+BYlqa0UInDjLWC7LjDUFU8eLHJqBtuFGy4l3Oxd70xV8UIPt5QDG1ITtEd0v9NDlFTYgvCcTR55yAL6XzysqmTfNaO9LLXi0P+n/OJAjTgIMagkjgij4fghJD/CSDRkqZMQwo+gdJ2jdeG0404bS/X3iG/fT9BmKE2cuc9cbG05AzO/B+lffzTWkoA69OCSExoVa1/Ba/n/LDbSa5aLORZWyw0LKmhHPWnAYFhUxDaSCpuXr0rqFyNDKYdNEQd92rtTPnTuDWJcNO7Vnybu+RvdUGacLU0AsdBrgJuCXi2RYgJlEixheFEwaPPISg0aO38EW+kqBZ0PscyKuAonctmBqm9LCxiZ2Hwt5TP0TN/RPI9ZLhhwg== 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:(13230022)(4636009)(346002)(136003)(396003)(39860400002)(376002)(451199015)(46966006)(36840700001)(2616005)(356005)(336012)(316002)(82310400005)(6916009)(2906002)(81166007)(478600001)(5660300002)(82740400003)(47076005)(426003)(8676002)(41300700001)(36860700001)(4326008)(86362001)(8936002)(70586007)(186003)(70206006)(83380400001)(36756003)(26005)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5637 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VI1EUR03FT057.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: b7523fe7-0f79-4b59-16c0-08dae345dd69 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vTgq0+70YO8PWo3C4Lsasn07F7qAmXquHe/6RU5XGD+tehy5RpgP81M6hwJnbu3W2W21tOfv1g51CL2V2uKSLZ+HjiLSHvfURQ1YGeEh7y5OYowUpDiJXaPPXBlvHXTslOTEgKaGo1VH5MGIv/App+j9mLkX2tfApQtNST8fNkkv3ZLxuOli1e5KApGOnUfeQ/7OwtgyI2SKB7dHCltvCjOmaGYBNOj0D+/KdNq0hn083C5OGNybRTaFcvToLEv59Lpl3NnkVD2h8zxjhIA+P2BzCefG66658RXyh8fSFUdH9+wqep4x/+9wdZmlhAXYopwlRSVa52ZxSOsrF3Am5d9sSc5kFxDTVnuQ3udZXm+iyBgxnAGCd2kJ8L7WFSNdNdbZThEStHez8ctMQCJ5BcN7HnfPbwKMDFsq6wsQbCRWdLWaJItgIcLgd/HBsd1KAcdnp5czmDw+h4ss9BQbOfjinNBVsDqnlVtNb4PZp8xzizOW9BbLZ7qRLaA5eq06xZt9udtX0iT7lralZWXbqnqMWKIxD5Cm6Rro6IoLHRsBY2oLDSBUEu1b7JhrG9h4ei7qVNVS3YLvdEOTc0rJgnwckolhhJaZR48mGUszVVaLmU1CTW5v2tCBBYi5+AK43REWhiz2C7axa1NNKo/EB+2xAPNKjOCg2HlaUmrqaoNMn6RV4F+FB7qR4SpyU8nUgLNzlYCxQlVlOXCk8AwloQ== 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:(13230022)(4636009)(136003)(346002)(396003)(376002)(39860400002)(451199015)(46966006)(36840700001)(40470700004)(336012)(2616005)(47076005)(426003)(6916009)(40460700003)(186003)(478600001)(26005)(2906002)(316002)(86362001)(82740400003)(36756003)(40480700001)(41300700001)(36860700001)(82310400005)(83380400001)(70206006)(5660300002)(70586007)(4326008)(8936002)(8676002)(81166007);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2022 11:24:13.1106 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5b51ca18-e9cc-4855-fd71-08dae345e34e 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: VI1EUR03FT057.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR08MB10046 X-Spam-Status: No, score=-12.9 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,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 List-Id: Add function prologue/epilogue to conditionally add BTI landing pads and/or PAC code generation & authentication instructions depending on compilation flags. --- newlib/libc/machine/arm/memchr.S | 50 ++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/newlib/libc/machine/arm/memchr.S b/newlib/libc/machine/arm/memchr.S index 1a4c6512c..3c11addad 100644 --- a/newlib/libc/machine/arm/memchr.S +++ b/newlib/libc/machine/arm/memchr.S @@ -76,6 +76,7 @@ .syntax unified #include "acle-compat.h" +#include "arm_asm.h" @ NOTE: This ifdef MUST match the one in memchr-stub.c #if defined (__ARM_NEON__) || defined (__ARM_NEON) @@ -267,10 +268,14 @@ memchr: #elif __ARM_ARCH_ISA_THUMB >= 2 && defined (__ARM_FEATURE_DSP) #if __ARM_ARCH_PROFILE == 'M' - .arch armv7e-m +#if __ARM_ARCH >= 8 + /* keep config inherited from -march=. */ #else - .arch armv6t2 -#endif + .arch armv7e-m +#endif /* __ARM_ARCH >= 8 */ +#else + .arch armv6t2 +#endif /* __ARM_ARCH_PROFILE == 'M' */ @ this lets us check a flag in a 00/ff byte easily in either endianness #ifdef __ARMEB__ @@ -287,11 +292,14 @@ memchr: .p2align 4,,15 .global memchr .type memchr,%function + .fnstart + .cfi_startproc memchr: @ r0 = start of memory to scan @ r1 = character to look for @ r2 = length @ returns r0 = pointer to character or NULL if not found + prologue and r1,r1,#0xff @ Don't trust the caller to pass a char cmp r2,#16 @ If short don't bother with anything clever @@ -313,6 +321,11 @@ memchr: 10: @ We are aligned, we know we have at least 8 bytes to work with push {r4,r5,r6,r7} + .cfi_adjust_cfa_offset 16 + .cfi_rel_offset 4, 0 + .cfi_rel_offset 5, 4 + .cfi_rel_offset 6, 8 + .cfi_rel_offset 7, 12 orr r1, r1, r1, lsl #8 @ expand the match word across all bytes orr r1, r1, r1, lsl #16 bic r4, r2, #7 @ Number of double words to work with * 8 @@ -334,6 +347,11 @@ memchr: bne 15b @ (Flags from the subs above) pop {r4,r5,r6,r7} + .cfi_restore 7 + .cfi_restore 6 + .cfi_restore 5 + .cfi_restore 4 + .cfi_adjust_cfa_offset -16 and r1,r1,#0xff @ r1 back to a single character and r2,r2,#7 @ Leave the count remaining as the number @ after the double words have been done @@ -349,17 +367,29 @@ memchr: bne 21b @ on r2 flags 40: + .cfi_remember_state movs r0,#0 @ not found - bx lr + epilogue 50: + .cfi_restore_state + .cfi_remember_state subs r0,r0,#1 @ found - bx lr + epilogue 60: @ We're here because the fast path found a hit @ now we have to track down exactly which word it was @ r0 points to the start of the double word after the one tested @ r5 has the 00/ff pattern for the first word, r6 has the chained value + @ This point is reached from cbnz midway through label 15 prior to + @ popping r4-r7 off the stack. .cfi_restore_state alone disregards + @ this, so we manually correct this. + .cfi_restore_state @ Standard post-prologue state + .cfi_adjust_cfa_offset 16 + .cfi_rel_offset 4, 0 + .cfi_rel_offset 5, 4 + .cfi_rel_offset 6, 8 + .cfi_rel_offset 7, 12 cmp r5, #0 itte eq moveq r5, r6 @ the end is in the 2nd word @@ -379,8 +409,16 @@ memchr: 61: pop {r4,r5,r6,r7} + .cfi_restore 7 + .cfi_restore 6 + .cfi_restore 5 + .cfi_restore 4 + .cfi_adjust_cfa_offset -16 subs r0,r0,#1 - bx lr + epilogue + .cfi_endproc + .cantunwind + .fnend #else /* Defined in memchr-stub.c. */ #endif -- 2.36.1