[compiler-rt] [compiler-rt][ARM] Add missing PACBTI support to assembly aeabi functions (PR #142400)

Victor Campos via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 6 08:52:35 PDT 2025


https://github.com/vhscampos updated https://github.com/llvm/llvm-project/pull/142400

>From 4edb352ec92ad86d0366c5ddd415be64eaf8e8af Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Tue, 6 May 2025 11:18:05 +0100
Subject: [PATCH 1/4] [compiler-rt][ARM] Add missing PACBTI support to assembly
 aeabi functions

Some of the aeabi functions were missing PACBTI support. The lack of it
resulted in exceptions at runtime if the running environment had PAC
and/or BTI enabled.

This patch adds this support.
---
 compiler-rt/lib/builtins/arm/aeabi_cdcmp.S    | 34 ++++++++++++++++--
 compiler-rt/lib/builtins/arm/aeabi_cfcmp.S    | 35 +++++++++++++++++--
 compiler-rt/lib/builtins/arm/aeabi_dcmp.S     | 20 +++++++++--
 compiler-rt/lib/builtins/arm/aeabi_fcmp.S     | 20 +++++++++--
 compiler-rt/lib/builtins/arm/aeabi_idivmod.S  | 10 ++++++
 compiler-rt/lib/builtins/arm/aeabi_ldivmod.S  | 10 ++++++
 compiler-rt/lib/builtins/arm/aeabi_memcpy.S   |  3 ++
 compiler-rt/lib/builtins/arm/aeabi_memmove.S  |  3 ++
 compiler-rt/lib/builtins/arm/aeabi_memset.S   |  6 ++++
 compiler-rt/lib/builtins/arm/aeabi_uidivmod.S | 10 ++++++
 compiler-rt/lib/builtins/arm/aeabi_uldivmod.S | 14 ++++++--
 compiler-rt/lib/builtins/assembly.h           | 11 ++++++
 12 files changed, 163 insertions(+), 13 deletions(-)

diff --git a/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S b/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S
index c7abdb003a68c..8fc53a23297f7 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S
@@ -22,7 +22,12 @@
         .syntax unified
         .p2align 2
 DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)
+        PACBTI_LANDING
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        push {r0-r3, r12, lr}
+#else
         push {r0-r3, lr}
+#endif
         bl __aeabi_cdcmpeq_check_nan
         cmp r0, #1
 #if defined(USE_THUMB_1)
@@ -37,6 +42,12 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)
         movs r0, #0xF
         lsls r0, r0, #31
         pop {r0-r3, pc}
+#else
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        pop {r0-r3, r12, lr}
+        beq 2f
+        aut r12, lr, sp
+        b __aeabi_cdcmple
 #else
         pop {r0-r3, lr}
 
@@ -45,15 +56,21 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)
         // __aeabi_cdcmple is in a different section for some builds.
         IT(ne)
         bne __aeabi_cdcmple
+#endif
 
+2:
 #if defined(USE_THUMB_2)
-        mov ip, #APSR_C
-        msr APSR_nzcvq, ip
+        mov r0, #APSR_C
+        msr APSR_nzcvq, r0
 #else
         msr APSR_nzcvq, #APSR_C
 #endif
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        bxaut r12, lr, sp
+#else
         JMP(lr)
 #endif
+#endif
 END_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)
 
 
@@ -70,9 +87,14 @@ END_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)
         .syntax unified
         .p2align 2
 DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmple)
+        PACBTI_LANDING
         // Per the RTABI, this function must preserve r0-r11.
         // Save lr in the same instruction for compactness
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        push {r0-r3, r12, lr}
+#else
         push {r0-r3, lr}
+#endif
 
         bl __aeabi_dcmplt
         cmp r0, #1
@@ -111,9 +133,14 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmple)
 
 1:
         msr APSR_nzcvq, ip
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        pop {r0-r3, r12, lr}
+        bxaut r12, lr, sp
+#else
         pop {r0-r3}
         POP_PC()
 #endif
+#endif
 END_COMPILERRT_FUNCTION(__aeabi_cdcmple)
 
 // int __aeabi_cdrcmple(double a, double b) {
@@ -123,6 +150,9 @@ END_COMPILERRT_FUNCTION(__aeabi_cdcmple)
         .syntax unified
         .p2align 2
 DEFINE_COMPILERRT_FUNCTION(__aeabi_cdrcmple)
+#if defined(__ARM_FEATURE_BTI_DEFAULT)
+        bti
+#endif
         // Swap r0 and r2
         mov ip, r0
         mov r0, r2
diff --git a/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S b/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
index 81c47661c8b5f..adf756c23c789 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
@@ -22,7 +22,12 @@
         .syntax unified
         .p2align 2
 DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)
+        PACBTI_LANDING
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        push {r0-r3, r12, lr}
+#else
         push {r0-r3, lr}
+#endif
         bl __aeabi_cfcmpeq_check_nan
         cmp r0, #1
 #if defined(USE_THUMB_1)
@@ -37,23 +42,34 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)
         movs r0, #0xF
         lsls r0, r0, #31
         pop {r0-r3, pc}
+#else
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        pop {r0-r3, r12, lr}
+        beq 2f
+        aut r12, lr, sp
+        b __aeabi_cfcmple
 #else
         pop {r0-r3, lr}
-
         // NaN has been ruled out, so __aeabi_cfcmple can't trap
         // Use "it ne" + unconditional branch to guarantee a supported relocation if
         // __aeabi_cfcmple is in a different section for some builds.
         IT(ne)
         bne __aeabi_cfcmple
+#endif
 
+2:
 #if defined(USE_THUMB_2)
-        mov ip, #APSR_C
-        msr APSR_nzcvq, ip
+        mov r0, #APSR_C
+        msr APSR_nzcvq, r0
 #else
         msr APSR_nzcvq, #APSR_C
 #endif
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        bxaut r12, lr, sp
+#else
         JMP(lr)
 #endif
+#endif
 END_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)
 
 
@@ -70,9 +86,14 @@ END_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)
         .syntax unified
         .p2align 2
 DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmple)
+        PACBTI_LANDING
         // Per the RTABI, this function must preserve r0-r11.
         // Save lr in the same instruction for compactness
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        push {r0-r3, r12, lr}
+#else
         push {r0-r3, lr}
+#endif
 
         bl __aeabi_fcmplt
         cmp r0, #1
@@ -111,9 +132,14 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmple)
 
 1:
         msr APSR_nzcvq, ip
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        pop {r0-r3, r12, lr}
+        bxaut r12, lr, sp
+#else
         pop {r0-r3}
         POP_PC()
 #endif
+#endif
 END_COMPILERRT_FUNCTION(__aeabi_cfcmple)
 
 // int __aeabi_cfrcmple(float a, float b) {
@@ -123,6 +149,9 @@ END_COMPILERRT_FUNCTION(__aeabi_cfcmple)
         .syntax unified
         .p2align 2
 DEFINE_COMPILERRT_FUNCTION(__aeabi_cfrcmple)
+#if defined(__ARM_FEATURE_BTI_DEFAULT)
+        bti
+#endif
         // Swap r0 and r1
         mov ip, r0
         mov r0, r1
diff --git a/compiler-rt/lib/builtins/arm/aeabi_dcmp.S b/compiler-rt/lib/builtins/arm/aeabi_dcmp.S
index bee14b3ff8afe..4d1cc77d9a28b 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_dcmp.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_dcmp.S
@@ -25,20 +25,34 @@
 #  define CONVERT_DCMP_ARGS_TO_DF2_ARGS
 #endif
 
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+#  define PROLOGUE PACBTI_LANDING        SEPARATOR \
+                   push      { r12, lr }
+#  define EPILOGUE pop       { r12, lr } SEPARATOR \
+                   bxaut     r12, lr, sp
+#elif defined(__ARM_FEATURE_BTI_DEFAULT)
+#  define PROLOGUE PACBTI_LANDING        SEPARATOR \
+                   push      { r4, lr }
+#  define EPILOGUE pop       { r4, pc }
+#else
+#  define PROLOGUE push      { r4, lr }
+#  define EPILOGUE pop       { r4, pc }
+#endif
+
 #define DEFINE_AEABI_DCMP(cond)                            \
         .syntax unified                          SEPARATOR \
         .p2align 2                               SEPARATOR \
 DEFINE_COMPILERRT_FUNCTION(__aeabi_dcmp ## cond)           \
-        push      { r4, lr }                     SEPARATOR \
+        PROLOGUE                                 SEPARATOR \
         CONVERT_DCMP_ARGS_TO_DF2_ARGS            SEPARATOR \
         bl        SYMBOL_NAME(__ ## cond ## df2) SEPARATOR \
         cmp       r0, #0                         SEPARATOR \
         b ## cond 1f                             SEPARATOR \
         movs      r0, #0                         SEPARATOR \
-        pop       { r4, pc }                     SEPARATOR \
+        EPILOGUE                                 SEPARATOR \
 1:                                               SEPARATOR \
         movs      r0, #1                         SEPARATOR \
-        pop       { r4, pc }                     SEPARATOR \
+        EPILOGUE                                 SEPARATOR \
 END_COMPILERRT_FUNCTION(__aeabi_dcmp ## cond)
 
 DEFINE_AEABI_DCMP(eq)
diff --git a/compiler-rt/lib/builtins/arm/aeabi_fcmp.S b/compiler-rt/lib/builtins/arm/aeabi_fcmp.S
index cd311b417096a..190a111d3447a 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_fcmp.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_fcmp.S
@@ -25,20 +25,34 @@
 #  define CONVERT_FCMP_ARGS_TO_SF2_ARGS
 #endif
 
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+#  define PROLOGUE PACBTI_LANDING        SEPARATOR \
+                   push      { r12, lr }
+#  define EPILOGUE pop       { r12, lr } SEPARATOR \
+                   bxaut     r12, lr, sp
+#elif defined(__ARM_FEATURE_BTI_DEFAULT)
+#  define PROLOGUE PACBTI_LANDING        SEPARATOR \
+                   push      { r4, lr }
+#  define EPILOGUE pop       { r4, pc }
+#else
+#  define PROLOGUE push      { r4, lr }
+#  define EPILOGUE pop       { r4, pc }
+#endif
+
 #define DEFINE_AEABI_FCMP(cond)                            \
         .syntax unified                          SEPARATOR \
         .p2align 2                               SEPARATOR \
 DEFINE_COMPILERRT_FUNCTION(__aeabi_fcmp ## cond)           \
-        push      { r4, lr }                     SEPARATOR \
+        PROLOGUE                                 SEPARATOR \
         CONVERT_FCMP_ARGS_TO_SF2_ARGS            SEPARATOR \
         bl        SYMBOL_NAME(__ ## cond ## sf2) SEPARATOR \
         cmp       r0, #0                         SEPARATOR \
         b ## cond 1f                             SEPARATOR \
         movs      r0, #0                         SEPARATOR \
-        pop       { r4, pc }                     SEPARATOR \
+        EPILOGUE                                 SEPARATOR \
 1:                                               SEPARATOR \
         movs      r0, #1                         SEPARATOR \
-        pop       { r4, pc }                     SEPARATOR \
+        EPILOGUE                                 SEPARATOR \
 END_COMPILERRT_FUNCTION(__aeabi_fcmp ## cond)
 
 DEFINE_AEABI_FCMP(eq)
diff --git a/compiler-rt/lib/builtins/arm/aeabi_idivmod.S b/compiler-rt/lib/builtins/arm/aeabi_idivmod.S
index bb80e4b96fc1a..4b82c946b1eb7 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_idivmod.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_idivmod.S
@@ -31,7 +31,12 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_idivmod)
         subs    r1, r1, r2
         JMP     (r3)
 #else  // defined(USE_THUMB_1)
+        PACBTI_LANDING
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        push    { r12, lr }
+#else
         push    { lr }
+#endif
         sub     sp, sp, #4
         mov     r2, sp
 #if defined(__MINGW32__)
@@ -42,7 +47,12 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_idivmod)
         bl      SYMBOL_NAME(__divmodsi4)
         ldr     r1, [sp]
         add     sp, sp, #4
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        pop     { r12, lr }
+        bxaut   r12, lr, sp
+#else
         pop     { pc }
+#endif
 #endif //  defined(USE_THUMB_1)
 END_COMPILERRT_FUNCTION(__aeabi_idivmod)
 
diff --git a/compiler-rt/lib/builtins/arm/aeabi_ldivmod.S b/compiler-rt/lib/builtins/arm/aeabi_ldivmod.S
index d0d06be6f3295..c11ead68ff8fb 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_ldivmod.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_ldivmod.S
@@ -22,7 +22,12 @@
         .syntax unified
         .p2align 2
 DEFINE_COMPILERRT_FUNCTION(__aeabi_ldivmod)
+        PACBTI_LANDING
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        push    {r6, r12, lr}
+#else
         push    {r6, lr}
+#endif
         sub     sp, sp, #16
         add     r6, sp, #8
         str     r6, [sp]
@@ -38,7 +43,12 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_ldivmod)
         ldr     r2, [sp, #8]
         ldr     r3, [sp, #12]
         add     sp, sp, #16
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        pop     {r6, r12, lr}
+        bxaut   r12, lr, sp
+#else
         pop     {r6, pc}
+#endif
 END_COMPILERRT_FUNCTION(__aeabi_ldivmod)
 
 NO_EXEC_STACK_DIRECTIVE
diff --git a/compiler-rt/lib/builtins/arm/aeabi_memcpy.S b/compiler-rt/lib/builtins/arm/aeabi_memcpy.S
index 93e1b05d54ce3..fa6a58640179e 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_memcpy.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_memcpy.S
@@ -18,6 +18,9 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_memcpy)
         bl      memcpy
         pop     {r7, pc}
 #else
+#if defined(__ARM_FEATURE_BTI_DEFAULT)
+        bti
+#endif
         b       memcpy
 #endif
 END_COMPILERRT_FUNCTION(__aeabi_memcpy)
diff --git a/compiler-rt/lib/builtins/arm/aeabi_memmove.S b/compiler-rt/lib/builtins/arm/aeabi_memmove.S
index c2f0fa4cd8ff3..a72d52a397b97 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_memmove.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_memmove.S
@@ -17,6 +17,9 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_memmove)
         bl      memmove
         pop     {r7, pc}
 #else
+#if defined(__ARM_FEATURE_BTI_DEFAULT)
+        bti
+#endif
         b       memmove
 #endif
 END_COMPILERRT_FUNCTION(__aeabi_memmove)
diff --git a/compiler-rt/lib/builtins/arm/aeabi_memset.S b/compiler-rt/lib/builtins/arm/aeabi_memset.S
index 2aa8ec0c4679d..950be84c5307d 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_memset.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_memset.S
@@ -14,6 +14,9 @@
         .syntax unified
         .p2align 2
 DEFINE_COMPILERRT_FUNCTION(__aeabi_memset)
+#if defined(__ARM_FEATURE_BTI_DEFAULT)
+        bti
+#endif
         mov     r3, r1
         mov     r1, r2
         mov     r2, r3
@@ -31,6 +34,9 @@ DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memset8, __aeabi_memset)
 
         .p2align 2
 DEFINE_COMPILERRT_FUNCTION(__aeabi_memclr)
+#if defined(__ARM_FEATURE_BTI_DEFAULT)
+        bti
+#endif
         mov     r2, r1
         movs    r1, #0
 #ifdef USE_THUMB_1
diff --git a/compiler-rt/lib/builtins/arm/aeabi_uidivmod.S b/compiler-rt/lib/builtins/arm/aeabi_uidivmod.S
index df030769fd40b..db2eecb3234f7 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_uidivmod.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_uidivmod.S
@@ -38,7 +38,12 @@ LOCAL_LABEL(case_denom_larger):
         movs    r0, #0
         JMP     (lr)
 #else // defined(USE_THUMB_1)
+        PACBTI_LANDING
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        push    { r12, lr }
+#else
         push    { lr }
+#endif
         sub     sp, sp, #4
         mov     r2, sp
 #if defined(__MINGW32__)
@@ -49,8 +54,13 @@ LOCAL_LABEL(case_denom_larger):
         bl      SYMBOL_NAME(__udivmodsi4)
         ldr     r1, [sp]
         add     sp, sp, #4
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        pop     { r12, lr }
+        bxaut   r12, lr, sp
+#else
         pop     { pc }
 #endif
+#endif
 END_COMPILERRT_FUNCTION(__aeabi_uidivmod)
 
 NO_EXEC_STACK_DIRECTIVE
diff --git a/compiler-rt/lib/builtins/arm/aeabi_uldivmod.S b/compiler-rt/lib/builtins/arm/aeabi_uldivmod.S
index 4fc97704d3c57..66da6a39ef5df 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_uldivmod.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_uldivmod.S
@@ -22,7 +22,12 @@
         .syntax unified
         .p2align 2
 DEFINE_COMPILERRT_FUNCTION(__aeabi_uldivmod)
-        push	{r6, lr}
+        PACBTI_LANDING
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        push    {r6, r12, lr}
+#else
+        push    {r6, lr}
+#endif
         sub	sp, sp, #16
         add	r6, sp, #8
         str	r6, [sp]
@@ -38,7 +43,12 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_uldivmod)
         ldr	r2, [sp, #8]
         ldr	r3, [sp, #12]
         add	sp, sp, #16
-        pop	{r6, pc}
+#if defined(__ARM_FEATURE_PAC_DEFAULT)
+        pop     {r6, r12, lr}
+        bxaut   r12, lr, sp
+#else
+        pop     {r6, pc}
+#endif
 END_COMPILERRT_FUNCTION(__aeabi_uldivmod)
 
 NO_EXEC_STACK_DIRECTIVE
diff --git a/compiler-rt/lib/builtins/assembly.h b/compiler-rt/lib/builtins/assembly.h
index 385dc190369d9..714bcd4d5c1f6 100644
--- a/compiler-rt/lib/builtins/assembly.h
+++ b/compiler-rt/lib/builtins/assembly.h
@@ -194,6 +194,17 @@
 #else
 #define WIDE(op) op
 #endif
+
+#if defined(__ARM_FEATURE_PAC_DEFAULT) && defined(__ARM_FEATURE_BTI_DEFAULT)
+#define PACBTI_LANDING pacbti r12, lr, sp
+#elif defined(__ARM_FEATURE_PAC_DEFAULT)
+#define PACBTI_LANDING pac r12, lr, sp
+#elif defined(__ARM_FEATURE_BTI_DEFAULT)
+#define PACBTI_LANDING bti
+#else
+#define PACBTI_LANDING
+#endif
+
 #else // !defined(__arm)
 #define DECLARE_FUNC_ENCODING
 #define DEFINE_CODE_STATE

>From e28353f51ea56ba5c8216d40517b4de3cd56a89c Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Thu, 5 Jun 2025 14:51:33 +0100
Subject: [PATCH 2/4] Change aeabi_c[f|d]cmpeq not to clobber r0

---
 compiler-rt/lib/builtins/arm/aeabi_cdcmp.S | 10 +++-------
 compiler-rt/lib/builtins/arm/aeabi_cfcmp.S | 10 +++-------
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S b/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S
index 8fc53a23297f7..bbabebcbcd316 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S
@@ -45,8 +45,8 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)
 #else
 #if defined(__ARM_FEATURE_PAC_DEFAULT)
         pop {r0-r3, r12, lr}
-        beq 2f
         aut r12, lr, sp
+        beq 2f
         b __aeabi_cdcmple
 #else
         pop {r0-r3, lr}
@@ -60,17 +60,13 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)
 
 2:
 #if defined(USE_THUMB_2)
-        mov r0, #APSR_C
-        msr APSR_nzcvq, r0
+        mov r12, #APSR_C
+        msr APSR_nzcvq, r12
 #else
         msr APSR_nzcvq, #APSR_C
 #endif
-#if defined(__ARM_FEATURE_PAC_DEFAULT)
-        bxaut r12, lr, sp
-#else
         JMP(lr)
 #endif
-#endif
 END_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)
 
 
diff --git a/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S b/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
index adf756c23c789..ebee80d21877c 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
@@ -45,8 +45,8 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)
 #else
 #if defined(__ARM_FEATURE_PAC_DEFAULT)
         pop {r0-r3, r12, lr}
-        beq 2f
         aut r12, lr, sp
+        beq 2f
         b __aeabi_cfcmple
 #else
         pop {r0-r3, lr}
@@ -59,17 +59,13 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)
 
 2:
 #if defined(USE_THUMB_2)
-        mov r0, #APSR_C
-        msr APSR_nzcvq, r0
+        mov r12, #APSR_C
+        msr APSR_nzcvq, r12
 #else
         msr APSR_nzcvq, #APSR_C
 #endif
-#if defined(__ARM_FEATURE_PAC_DEFAULT)
-        bxaut r12, lr, sp
-#else
         JMP(lr)
 #endif
-#endif
 END_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)
 
 

>From eaaa920f0a341b14cb4840095d2bfa98c73f761b Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Fri, 6 Jun 2025 14:28:31 +0100
Subject: [PATCH 3/4] Blank line previously removed is added back

---
 compiler-rt/lib/builtins/arm/aeabi_cfcmp.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S b/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
index ebee80d21877c..aa1294d71e28c 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
@@ -50,6 +50,7 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)
         b __aeabi_cfcmple
 #else
         pop {r0-r3, lr}
+
         // NaN has been ruled out, so __aeabi_cfcmple can't trap
         // Use "it ne" + unconditional branch to guarantee a supported relocation if
         // __aeabi_cfcmple is in a different section for some builds.

>From 880ede960ec46199bf6ca304a3d315a58de485da Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Fri, 6 Jun 2025 15:18:47 +0100
Subject: [PATCH 4/4] Simplify control flow

---
 compiler-rt/lib/builtins/arm/aeabi_cdcmp.S | 5 +----
 compiler-rt/lib/builtins/arm/aeabi_cfcmp.S | 5 +----
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S b/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S
index bbabebcbcd316..19311396b2015 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S
@@ -46,19 +46,16 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)
 #if defined(__ARM_FEATURE_PAC_DEFAULT)
         pop {r0-r3, r12, lr}
         aut r12, lr, sp
-        beq 2f
-        b __aeabi_cdcmple
 #else
         pop {r0-r3, lr}
+#endif
 
         // NaN has been ruled out, so __aeabi_cdcmple can't trap
         // Use "it ne" + unconditional branch to guarantee a supported relocation if
         // __aeabi_cdcmple is in a different section for some builds.
         IT(ne)
         bne __aeabi_cdcmple
-#endif
 
-2:
 #if defined(USE_THUMB_2)
         mov r12, #APSR_C
         msr APSR_nzcvq, r12
diff --git a/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S b/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
index aa1294d71e28c..ca382968cf5d9 100644
--- a/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
+++ b/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
@@ -46,19 +46,16 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)
 #if defined(__ARM_FEATURE_PAC_DEFAULT)
         pop {r0-r3, r12, lr}
         aut r12, lr, sp
-        beq 2f
-        b __aeabi_cfcmple
 #else
         pop {r0-r3, lr}
+#endif
 
         // NaN has been ruled out, so __aeabi_cfcmple can't trap
         // Use "it ne" + unconditional branch to guarantee a supported relocation if
         // __aeabi_cfcmple is in a different section for some builds.
         IT(ne)
         bne __aeabi_cfcmple
-#endif
 
-2:
 #if defined(USE_THUMB_2)
         mov r12, #APSR_C
         msr APSR_nzcvq, r12



More information about the llvm-commits mailing list