将“-Wa,-mimplicit-it=thumb”添加到 gcc CFLAGS 以避免“thumb 条件指令应该在 IT 块中”错误
--- libffi.orig/src/arm/sysv.S
+++ libffi/src/arm/sysv.S
@@ -91,6 +91,10 @@
# define __ARM_ARCH__ 7
#endif
+#ifdef __ARM_ARCH_7M__ /* cortex-m3 */
+#undef __THUMB_INTERWORK__
+#endif
+
#if __ARM_ARCH__ >= 5
# define call_reg(x) blx x
#elif defined (__ARM_ARCH_4T__)
@@ -121,9 +125,11 @@
#else
ENTRY(\name)
#endif
+#ifndef __ARM_ARCH_7M__ /* not cortex-m3 */
bx pc
nop
.arm
+#endif
UNWIND .fnstart
/* A hook to tell gdb that we've switched to ARM mode. Also used to call
directly from other local arm routines. */
@@ -164,6 +170,10 @@ _L__\name:
#endif
.endm
+#ifdef __ARM_ARCH_7M__ /* cortex-m3 */
+ .syntax unified
+#endif
+
@ r0: ffi_prep_args
@ r1: &ecif
@ r2: cif->bytes
@@ -180,7 +190,11 @@ ARM_FUNC_START ffi_call_SYSV
UNWIND .setfp fp, sp
@ Make room for all of the new args.
+#ifdef __ARM_ARCH_7M__ /* cortex-m3 */
+ sub sp, sp, r2
+#else
sub sp, fp, r2
+#endif
@ Place all of the ffi_prep_args in position
mov r0, sp
@@ -193,7 +207,12 @@ ARM_FUNC_START ffi_call_SYSV
ldmia sp, {r0-r3}
@ and adjust stack
+#ifdef __ARM_ARCH_7M__ /* cortex-m3 */
+ mov lr, sp
+ sub lr, fp, lr @ cif->bytes == fp - sp
+#else
sub lr, fp, sp @ cif->bytes == fp - sp
+#endif
ldr ip, [fp] @ load fn() in advance
cmp lr, #16
movhs lr, #16
@@ -305,7 +324,13 @@ ARM_FUNC_START ffi_closure_SYSV
beq .Lretlonglong
.Lclosure_epilogue:
add sp, sp, #16
+#ifdef __ARM_ARCH_7M__ /* cortex-m3 */
+ ldr ip, [sp, #4]
+ ldr sp, [sp]
+ mov pc, ip
+#else
ldmfd sp, {sp, pc}
+#endif
.Lretint:
ldr r0, [sp]
b .Lclosure_epilogue
@@ -381,7 +406,12 @@ LSYM(Lbase_args):
ldmia sp, {r0-r3}
@ and adjust stack
+#ifdef __ARM_ARCH_7M__ /* cortex-m3 */
+ mov lr, sp
+ sub lr, ip, lr @ cif->bytes == (fp - 64) - sp
+#else
sub lr, ip, sp @ cif->bytes == (fp - 64) - sp
+#endif
ldr ip, [fp] @ load fn() in advance
cmp lr, #16
movhs lr, #16
@@ -469,7 +499,13 @@ ARM_FUNC_START ffi_closure_VFP
.Lclosure_epilogue_vfp:
add sp, sp, #72
+#ifdef __ARM_ARCH_7M__ /* cortex-m3 */
+ ldr ip, [sp, #4]
+ ldr sp, [sp]
+ mov pc, ip
+#else
ldmfd sp, {sp, pc}
+#endif
.Lretfloat_vfp:
flds s0, [sp]