public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Victor Do Nascimento <victor.donascimento@arm.com>
To: <newlib@sourceware.org>
Subject: [PATCH 4/8] newlib: libc: memchr M-profile PACBTI-enablement
Date: Tue, 5 Jul 2022 14:58:14 +0100	[thread overview]
Message-ID: <20220705135818.50088-5-victor.donascimento@arm.com> (raw)
In-Reply-To: <20220705135818.50088-1-victor.donascimento@arm.com>

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 | 49 ++++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 5 deletions(-)

diff --git a/newlib/libc/machine/arm/memchr.S b/newlib/libc/machine/arm/memchr.S
index 1a4c6512c..644cfda3f 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 "pacbti.h"
 
 @ NOTE: This ifdef MUST match the one in memchr-stub.c
 #if defined (__ARM_NEON__) || defined (__ARM_NEON)
@@ -266,7 +267,9 @@ memchr:
 
 #elif __ARM_ARCH_ISA_THUMB >= 2 && defined (__ARM_FEATURE_DSP)
 
-#if __ARM_ARCH_PROFILE == 'M'
+#if __ARM_ARCH_8M_MAIN__
+    /* keep config inherited from -march= */
+#elif __ARM_ARCH_PROFILE == 'M'
        .arch armv7e-m
 #else
        .arch armv6t2
@@ -287,11 +290,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
+    pacbti_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 +319,19 @@ memchr:
 10:
 	@ We are aligned, we know we have at least 8 bytes to work with
 	push	{r4,r5,r6,r7}
+	.save   {r4-r7}
+	.cfi_adjust_cfa_offset 16
+#ifdef __ARM_FEATURE_PAC_DEFAULT
+	.cfi_offset 4, -20
+	.cfi_offset 5, -16
+	.cfi_offset 6, -12
+	.cfi_offset 7, -8
+#else
+	.cfi_offset 4, -16
+	.cfi_offset 5, -12
+	.cfi_offset 6, -8
+	.cfi_offset 7, -4
+#endif /*  __ARM_FEATURE_PAC_DEFAULT */
 	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 +353,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
@@ -350,11 +374,11 @@ memchr:
 
 40:
 	movs	r0,#0		@ not found
-	bx	lr
+	pacbti_epilogue
 
 50:
 	subs	r0,r0,#1	@ found
-	bx	lr
+	pacbti_epilogue
 
 60:  @ We're here because the fast path found a hit 
      @ now we have to track down exactly which word it was
@@ -378,9 +402,24 @@ memchr:
 	addeq	r0,r0,#1
 
 61:
-	pop	{r4,r5,r6,r7}
 	subs	r0,r0,#1
-	bx	lr
+#if __ARM_FEATURE_PAC_DEFAULT
+	pop	{r4,r5,r6,r7,ip}
+	.cfi_restore 143
+#else
+	pop	{r4,r5,r6,r7}
+#endif /* __ARM_FEATURE_PAC_DEFAULT */
+	.cfi_restore 7
+	.cfi_restore 6
+	.cfi_restore 5
+	.cfi_restore 4
+	.cfi_def_cfa_offset 0
+#if __ARM_FEATURE_PAC_DEFAULT
+	aut ip, lr, sp
+#endif /* __ARM_FEATURE_PAC_DEFAULT */
+	bx lr
+	.cfi_endproc
+	.fnend
 #else
   /* Defined in memchr-stub.c.  */
 #endif
-- 
2.36.1


  parent reply	other threads:[~2022-07-05 13:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-05 13:58 [PATCH 0/8] Implement assembly cortex-M PACBTI functionality Victor Do Nascimento
2022-07-05 13:58 ` [PATCH 1/8] newlib: libc: define M-profile PACBTI-enablement macros Victor Do Nascimento
2022-07-05 13:58 ` [PATCH 2/8] newlib: libc: strcmp M-profile PACBTI-enablement Victor Do Nascimento
2022-07-05 13:58 ` [PATCH 3/8] newlib: libc: strlen " Victor Do Nascimento
2022-07-05 15:39   ` Richard Earnshaw
2022-07-05 16:30     ` Victor L. Do Nascimento
2022-07-06  9:07       ` Richard Earnshaw
2022-07-05 13:58 ` Victor Do Nascimento [this message]
2022-07-05 13:58 ` [PATCH 5/8] newlib: libc: memcpy " Victor Do Nascimento
2022-07-05 13:58 ` [PATCH 6/8] newlib: libc: setjmp/longjmp " Victor Do Nascimento
2022-07-05 13:58 ` [PATCH 7/8] newlib: libc: aeabi_memmove " Victor Do Nascimento
2022-07-05 13:58 ` [PATCH 8/8] newlib: libc: aeabi_memset " Victor Do Nascimento

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220705135818.50088-5-victor.donascimento@arm.com \
    --to=victor.donascimento@arm.com \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).