Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: armv5 userland broken




On 30/06/2021 07:22, Nick Hudson wrote:
Great work!

On 29/06/2021 08:13, Rin Okuyama wrote:
I've examined assembler codes for userland libraries for arm:
common/lib/libc, csu, libc, compiler_rt, and libm, and found that
some routines in compiler_rt do not align sp correctly:

http://www.netbsd.org/~rin/arm_stack_align_compiler_rt.patch

Also, some routines in libc do not also in Thumb-mode userland:

http://www.netbsd.org/~rin/arm_stack_align_libc_thumb.patch

I think it's better / less ugly to push even numbers of registers rather
than adjusting sp (especially for thumb)
How about this diff? (untested)

I've dropped callee saved registers from the compiler_rt code as (I
think) they're unused.

Nick
? sys/external/bsd/compiler_rt/dist/lib/builtins/arm/.aeabi_cfcmp.S.kate-swp
Index: lib/libc/arch/arm/gen/swapcontext.S
===================================================================
RCS file: /cvsroot/src/lib/libc/arch/arm/gen/swapcontext.S,v
retrieving revision 1.17
diff -u -p -r1.17 swapcontext.S
--- lib/libc/arch/arm/gen/swapcontext.S	30 Jun 2021 00:00:49 -0000	1.17
+++ lib/libc/arch/arm/gen/swapcontext.S	30 Jun 2021 07:37:44 -0000
@@ -84,15 +84,9 @@ ENTRY(swapcontext)
 #if !defined(__thumb__) || defined(_ARM_ARCH_T2)
 	b	PLT_SYM(_C_LABEL(setcontext))
 #else
-	push	{lr}
-	mov	r1, sp
-	subs	r1, #4
-	mov	sp, r1
+	push	{r3, lr}
 	bl	PLT_SYM(_C_LABEL(setcontext))
-	mov	r1, sp
-	adds	r1, #4
-	mov	sp, r1
-	pop	{pc}
+	pop	{r3, pc}
 #endif
 #if defined(__ARM_EABI__) && defined(__UNWIND_TABLES__)
 	.cfi_endproc
Index: lib/libc/arch/arm/sys/__clone.S
===================================================================
RCS file: /cvsroot/src/lib/libc/arch/arm/sys/__clone.S,v
retrieving revision 1.13
diff -u -p -r1.13 __clone.S
--- lib/libc/arch/arm/sys/__clone.S	30 Jun 2021 07:36:05 -0000	1.13
+++ lib/libc/arch/arm/sys/__clone.S	30 Jun 2021 07:37:44 -0000
@@ -117,14 +117,8 @@ ENTRY(__clone)
 	b	CERROR
 #else
 .Lcerror:
-	push	{lr}
-	mov	r1, sp
-	subs	r1, #4
-	mov	sp, r1
+	push	{r3, lr}
 	bl	CERROR
-	mov	r1, sp
-	adds	r1, #4
-	mov	sp, r1
-	pop	{pc}
+	pop	{r3, pc}
 #endif
 END(__clone)
Index: sys/external/bsd/compiler_rt/dist/lib/builtins/arm/aeabi_cfcmp.S
===================================================================
RCS file: /cvsroot/src/sys/external/bsd/compiler_rt/dist/lib/builtins/arm/aeabi_cfcmp.S,v
retrieving revision 1.2
diff -u -p -r1.2 aeabi_cfcmp.S
--- sys/external/bsd/compiler_rt/dist/lib/builtins/arm/aeabi_cfcmp.S	29 Jun 2021 23:26:00 -0000	1.2
+++ sys/external/bsd/compiler_rt/dist/lib/builtins/arm/aeabi_cfcmp.S	30 Jun 2021 07:37:45 -0000
@@ -57,17 +57,15 @@ END_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)
 DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmple)
         // Per the RTABI, this function must preserve r0-r11.
         // Save lr in the same instruction for compactness
-        push {r0-r3, lr}
-        sub sp, #4
+        // Save ip to ensure stack alignment (could be any register)
+        push {r0-r3, ip, lr}

         bl __aeabi_fcmplt
         cmp r0, #1
         moveq ip, #0
         beq 1f

-        add sp, #4
         ldm sp, {r0-r3}
-        sub sp, #4
         bl __aeabi_fcmpeq
         cmp r0, #1
         moveq ip, #(APSR_C | APSR_Z)
@@ -75,8 +73,7 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmp

 1:
         msr CPSR_f, ip
-        add sp, #4
-        pop {r0-r3}
+        pop {r0-r3, ip}
         POP_PC()
 END_COMPILERRT_FUNCTION(__aeabi_cfcmple)

Index: sys/external/bsd/compiler_rt/dist/lib/builtins/arm/divmodsi4.S
===================================================================
RCS file: /cvsroot/src/sys/external/bsd/compiler_rt/dist/lib/builtins/arm/divmodsi4.S,v
retrieving revision 1.2
diff -u -p -r1.2 divmodsi4.S
--- sys/external/bsd/compiler_rt/dist/lib/builtins/arm/divmodsi4.S	29 Jun 2021 23:26:00 -0000	1.2
+++ sys/external/bsd/compiler_rt/dist/lib/builtins/arm/divmodsi4.S	30 Jun 2021 07:37:45 -0000
@@ -16,12 +16,9 @@
 #include "../assembly.h"

 #define ESTABLISH_FRAME    \
-    push   {r4-r7, lr}   ;\
-    add     r7,     sp, #12   ;\
-    sub     sp,     #4
+    push   {r4-r6, lr}
 #define CLEAR_FRAME_AND_RETURN \
-    add     sp,     #4   ;\
-    pop    {r4-r7, pc}
+    pop    {r4-r6, pc}

 	.syntax unified
 	.text
Index: sys/external/bsd/compiler_rt/dist/lib/builtins/arm/divsi3.S
===================================================================
RCS file: /cvsroot/src/sys/external/bsd/compiler_rt/dist/lib/builtins/arm/divsi3.S,v
retrieving revision 1.2
diff -u -p -r1.2 divsi3.S
--- sys/external/bsd/compiler_rt/dist/lib/builtins/arm/divsi3.S	29 Jun 2021 23:26:00 -0000	1.2
+++ sys/external/bsd/compiler_rt/dist/lib/builtins/arm/divsi3.S	30 Jun 2021 07:37:45 -0000
@@ -15,12 +15,9 @@
 #include "../assembly.h"

 #define ESTABLISH_FRAME \
-    push   {r4, r7, lr}    ;\
-    add     r7,     sp, #4   ;\
-    sub     sp,     #4
+    push   {r4, lr}
 #define CLEAR_FRAME_AND_RETURN \
-    add     sp,     #4   ;\
-    pop    {r4, r7, pc}
+    pop    {r4, pc}

 	.syntax unified
 	.text
Index: sys/external/bsd/compiler_rt/dist/lib/builtins/arm/modsi3.S
===================================================================
RCS file: /cvsroot/src/sys/external/bsd/compiler_rt/dist/lib/builtins/arm/modsi3.S,v
retrieving revision 1.2
diff -u -p -r1.2 modsi3.S
--- sys/external/bsd/compiler_rt/dist/lib/builtins/arm/modsi3.S	29 Jun 2021 23:26:00 -0000	1.2
+++ sys/external/bsd/compiler_rt/dist/lib/builtins/arm/modsi3.S	30 Jun 2021 07:37:45 -0000
@@ -15,12 +15,9 @@
 #include "../assembly.h"

 #define ESTABLISH_FRAME \
-    push   {r4, r7, lr}    ;\
-    add     r7,     sp, #4   ;\
-    sub     sp,     #4
+    push   {r4, lr}
 #define CLEAR_FRAME_AND_RETURN \
-    add     sp,     #4   ;\
-    pop    {r4, r7, pc}
+    pop    {r4, pc}

 	.syntax unified
 	.text


Home | Main Index | Thread Index | Old Index