From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1035) id F219138582A4; Tue, 10 Jan 2023 16:49:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F219138582A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673369374; bh=EpQgA04mVmVDRr+kxI+0greVYqb5UgJDGlCvLBURXjQ=; h=From:To:Subject:Date:From; b=pua1zOVzsENYefcsAAAOi+QcrSZazoC26t6o61E9/Z0yEcL5eQWnX/TQL6EjPGqYi mHKHaN6YrjssxYDoDDzzGguVrwJns2cmcdovK4hPG7aQpR/+BLzwfsKN/Y4rzaw/Ez oODod3zsXDnya8xt3nFYXN39WQxna5cHuL3CItPY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Richard Earnshaw To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] newlib: libc: memchr M-profile PACBTI-enablement X-Act-Checkin: newlib-cygwin X-Git-Author: Victor L. Do Nascimento X-Git-Refname: refs/heads/master X-Git-Oldrev: 55825368961f3a9424f91406f8989d04f1df3b59 X-Git-Newrev: db30cbee419b6c4d05da8072dc1e869697b93ff1 Message-Id: <20230110164934.F219138582A4@sourceware.org> Date: Tue, 10 Jan 2023 16:49:34 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Ddb30cbee419= b6c4d05da8072dc1e869697b93ff1 commit db30cbee419b6c4d05da8072dc1e869697b93ff1 Author: Victor L. Do Nascimento Date: Wed Dec 21 11:24:00 2022 +0000 newlib: libc: memchr M-profile PACBTI-enablement =20 Add function prologue/epilogue to conditionally add BTI landing pads and/or PAC code generation & authentication instructions depending on compilation flags. Diff: --- 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/mem= chr.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 =20 #include "acle-compat.h" +#include "arm_asm.h" =20 @ 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 >=3D 2 && defined (__ARM_FEATURE_DSP) =20 #if __ARM_ARCH_PROFILE =3D=3D 'M' - .arch armv7e-m +#if __ARM_ARCH >=3D 8 + /* keep config inherited from -march=3D. */ #else - .arch armv6t2 -#endif + .arch armv7e-m +#endif /* __ARM_ARCH >=3D 8 */ +#else + .arch armv6t2 +#endif /* __ARM_ARCH_PROFILE =3D=3D 'M' */ =20 @ 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 =3D start of memory to scan @ r1 =3D character to look for @ r2 =3D length @ returns r0 =3D pointer to character or NULL if not found + prologue and r1,r1,#0xff @ Don't trust the caller to pass a char =20 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) =20 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 =20 40: + .cfi_remember_state movs r0,#0 @ not found - bx lr + epilogue =20 50: + .cfi_restore_state + .cfi_remember_state subs r0,r0,#1 @ found - bx lr + epilogue =20 60: @ We're here because the fast path found a hit=20 @ 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: =20 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