[PATCH 7/8] newlib: libc: aeabi_memmove M-profile PACBTI-enablement

Victor Do Nascimento <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Add function prologue/epilogue to conditionally add BTI landing pads
and/or PAC code generation & authentication instructions depending on
compilation flags.
---
 .../libc/machine/arm/aeabi_memmove-thumb2.S   | 42 +++++++++++++++++--
 1 file changed, 38 insertions(+), 4 deletions(-)

diff --git a/newlib/libc/machine/arm/aeabi_memmove-thumb2.S b/newlib/libc/machine/arm/aeabi_memmove-thumb2.S
index e9504437b..237e63cc0 100644
--- a/newlib/libc/machine/arm/aeabi_memmove-thumb2.S
+++ b/newlib/libc/machine/arm/aeabi_memmove-thumb2.S
@@ -26,6 +26,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+	#include "pacbti.h"
+
 	.thumb
 	.syntax unified
 	.global __aeabi_memmove
@@ -33,8 +35,18 @@
 	ASM_ALIAS __aeabi_memmove4 __aeabi_memmove
 	ASM_ALIAS __aeabi_memmove8 __aeabi_memmove
 __aeabi_memmove:
+	.fnstart
+	.cfi_startproc
+	pacbti_prologue
 	cmp	r0, r1
 	push	{r4}
+	.save   {r4}
+	.cfi_adjust_cfa_offset 4
+#if __ARM_FEATURE_PAC_DEFAULT
+	.cfi_offset 4, -8
+#else
+	.cfi_offset 4, -4
+#endif /* __ARM_FEATURE_PAC_DEFAULT */
 	bls	3f
 	adds	r3, r1, r2
 	cmp	r0, r3
@@ -48,8 +60,18 @@ __aeabi_memmove:
 	strb	r4, [r1, #-1]!
 	bne	1b
 2:
-	pop	{r4}
-	bx	lr
+#if __ARM_FEATURE_PAC_DEFAULT
+	pop {r4, ip}
+	.cfi_restore 4
+	.cfi_restore 143
+	.cfi_def_cfa_offset 0
+	aut ip, lr, sp
+#else
+	pop {r4}
+	.cfi_restore 4
+	.cfi_def_cfa_offset 0
+#endif /* __ARM_FEATURE_PAC_DEFAULT */
+	bx lr
 3:
 	cmp	r2, #0
 	beq	2b
@@ -60,6 +82,18 @@ __aeabi_memmove:
 	cmp	r2, r1
 	strb	r4, [r3, #1]!
 	bne	4b
-	pop	{r4}
-	bx	lr
+#if __ARM_FEATURE_PAC_DEFAULT
+	pop {r4, ip}
+	.cfi_restore 4
+	.cfi_restore 143
+	.cfi_def_cfa_offset 0
+	aut ip, lr, sp
+#else
+	pop {r4}
+	.cfi_restore 4
+	.cfi_def_cfa_offset 0
+#endif /* __ARM_FEATURE_PAC_DEFAULT */
+	bx lr
+	.cfi_endproc
+	.fnend
 	.size __aeabi_memmove, . - __aeabi_memmove
-- 
2.36.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.