[PATCH v2 7/8] newlib: libc: aeabi_memmove M-profile PACBTI-enablement
Victor Do Nascimento
victor.donascimento@arm.com
Wed Aug 3 15:35:23 GMT 2022
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 | 54 +++++++++++++++++--
1 file changed, 49 insertions(+), 5 deletions(-)
diff --git a/newlib/libc/machine/arm/aeabi_memmove-thumb2.S b/newlib/libc/machine/arm/aeabi_memmove-thumb2.S
index e9504437b..34054d96c 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,28 @@
ASM_ALIAS __aeabi_memmove4 __aeabi_memmove
ASM_ALIAS __aeabi_memmove8 __aeabi_memmove
__aeabi_memmove:
- cmp r0, r1
+ .fnstart
+ .cfi_startproc
+#if __HAVE_PAC_LEAF
+#if __ARM_FEATURE_BTI_DEFAULT
+ pacbti ip, lr, sp
+#else
+ pac ip, lr, sp
+#endif /* __ARM_FEATURE_BTI_DEFAULT */
+ .cfi_register 143, 12
+ push {r4, ip}
+ .save {r4, ra_auth_code}
+ .cfi_def_cfa_offset 8
+ .cfi_offset 4, -8
+ .cfi_offset 143, -4
+#elif __ARM_FEATURE_BTI_DEFAULT
+ bti
push {r4}
+ .save {r4}
+ .cfi_def_cfa_offset 4
+ .cfi_offset 4, -4
+#endif /* __HAVE_PAC_LEAF */
+ cmp r0, r1
bls 3f
adds r3, r1, r2
cmp r0, r3
@@ -48,8 +70,18 @@ __aeabi_memmove:
strb r4, [r1, #-1]!
bne 1b
2:
- pop {r4}
- bx lr
+#if __HAVE_PAC_LEAF
+ 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 /* __HAVE_PAC_LEAF */
+ bx lr
3:
cmp r2, #0
beq 2b
@@ -60,6 +92,18 @@ __aeabi_memmove:
cmp r2, r1
strb r4, [r3, #1]!
bne 4b
- pop {r4}
- bx lr
+#if __HAVE_PAC_LEAF
+ 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 /* __HAVE_PAC_LEAF */
+ bx lr
+ .cfi_endproc
+ .fnend
.size __aeabi_memmove, . - __aeabi_memmove
--
2.36.1
More information about the Newlib
mailing list