Skip to content

Commit ec1c73b

Browse files
[compiler-rt][ARM] Only use bxaut when the target has pacbti (#146057)
Most pacbti instructions are a nop when the target does not have pacbti, and thus safe to execute, but bxaut is an undefined instruction. When we don't have pacbti (e.g. if we're compiling compiler-rt with -mbranch-protection=standard in order to be forward-compatible with pacbti while still working on targets without it) then we need to use separate aut and bx instructions.
1 parent d8ca77e commit ec1c73b

File tree

9 files changed

+14
-8
lines changed

9 files changed

+14
-8
lines changed

compiler-rt/lib/builtins/arm/aeabi_cdcmp.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmple)
128128
msr APSR_nzcvq, ip
129129
#if defined(__ARM_FEATURE_PAC_DEFAULT)
130130
pop {r0-r3, r12, lr}
131-
bxaut r12, lr, sp
131+
PAC_RETURN
132132
#else
133133
pop {r0-r3}
134134
POP_PC()

compiler-rt/lib/builtins/arm/aeabi_cfcmp.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmple)
128128
msr APSR_nzcvq, ip
129129
#if defined(__ARM_FEATURE_PAC_DEFAULT)
130130
pop {r0-r3, r12, lr}
131-
bxaut r12, lr, sp
131+
PAC_RETURN
132132
#else
133133
pop {r0-r3}
134134
POP_PC()

compiler-rt/lib/builtins/arm/aeabi_dcmp.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# define PROLOGUE PACBTI_LANDING SEPARATOR \
3030
push { r12, lr }
3131
# define EPILOGUE pop { r12, lr } SEPARATOR \
32-
bxaut r12, lr, sp
32+
PAC_RETURN
3333
#elif defined(__ARM_FEATURE_BTI_DEFAULT)
3434
# define PROLOGUE PACBTI_LANDING SEPARATOR \
3535
push { r4, lr }

compiler-rt/lib/builtins/arm/aeabi_fcmp.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# define PROLOGUE PACBTI_LANDING SEPARATOR \
3030
push { r12, lr }
3131
# define EPILOGUE pop { r12, lr } SEPARATOR \
32-
bxaut r12, lr, sp
32+
PAC_RETURN
3333
#elif defined(__ARM_FEATURE_BTI_DEFAULT)
3434
# define PROLOGUE PACBTI_LANDING SEPARATOR \
3535
push { r4, lr }

compiler-rt/lib/builtins/arm/aeabi_idivmod.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_idivmod)
4949
add sp, sp, #4
5050
#if defined(__ARM_FEATURE_PAC_DEFAULT)
5151
pop { r12, lr }
52-
bxaut r12, lr, sp
52+
PAC_RETURN
5353
#else
5454
pop { pc }
5555
#endif

compiler-rt/lib/builtins/arm/aeabi_ldivmod.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_ldivmod)
4545
add sp, sp, #16
4646
#if defined(__ARM_FEATURE_PAC_DEFAULT)
4747
pop {r6, r12, lr}
48-
bxaut r12, lr, sp
48+
PAC_RETURN
4949
#else
5050
pop {r6, pc}
5151
#endif

compiler-rt/lib/builtins/arm/aeabi_uidivmod.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ LOCAL_LABEL(case_denom_larger):
5656
add sp, sp, #4
5757
#if defined(__ARM_FEATURE_PAC_DEFAULT)
5858
pop { r12, lr }
59-
bxaut r12, lr, sp
59+
PAC_RETURN
6060
#else
6161
pop { pc }
6262
#endif

compiler-rt/lib/builtins/arm/aeabi_uldivmod.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_uldivmod)
4545
add sp, sp, #16
4646
#if defined(__ARM_FEATURE_PAC_DEFAULT)
4747
pop {r6, r12, lr}
48-
bxaut r12, lr, sp
48+
PAC_RETURN
4949
#else
5050
pop {r6, pc}
5151
#endif

compiler-rt/lib/builtins/assembly.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@
205205
#define PACBTI_LANDING
206206
#endif
207207

208+
#if defined(__ARM_FEATURE_PAUTH)
209+
#define PAC_RETURN bxaut r12, lr, sp
210+
#else
211+
#define PAC_RETURN aut r12, lr, sp SEPARATOR bx lr
212+
#endif
213+
208214
#else // !defined(__arm)
209215
#define DECLARE_FUNC_ENCODING
210216
#define DEFINE_CODE_STATE

0 commit comments

Comments
 (0)