[x264-devel] [PATCH 3/6] checkasm: arm: preserve the stack alignment in x264_checkasm_checked_call

Martin Storsjö martin at martin.st
Mon Nov 14 22:54:50 CET 2016


From: Janne Grunau <janne-x264 at jannau.net>

The stack used by x264_checkasm_checked_call_neon was a multiple of 4
when the checked function is called. AAPCS requires a double word (8 byte)
aligned stack public interfaces. Since both calls are public interfaces
the stack is misaligned when the checked is called.

This can cause issues if code called within this (which includes
the C implementations) relies on the stack alignment.
---
 tools/checkasm-arm.S | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/checkasm-arm.S b/tools/checkasm-arm.S
index 57b4079..8242a58 100644
--- a/tools/checkasm-arm.S
+++ b/tools/checkasm-arm.S
@@ -47,6 +47,9 @@ error_message:
 
 #define ARG_STACK 4*(MAX_ARGS - 2)
 
+@ align the used stack space to 8 to preserve the stack alignment
+#define ARG_STACK_A (((ARG_STACK + pushed + 7) & ~7) - pushed)
+
 .macro clobbercheck variant
 .equ pushed, 4*10
 function x264_checkasm_call_\variant
@@ -64,10 +67,10 @@ function x264_checkasm_call_\variant
 
     push        {r1}
 
-    sub         sp,  sp,  #ARG_STACK
+    sub         sp,  sp,  #ARG_STACK_A
 .equ pos, 0
 .rept MAX_ARGS-2
-    ldr         r12, [sp, #ARG_STACK + pushed + 8 + pos]
+    ldr         r12, [sp, #ARG_STACK_A + pushed + 8 + pos]
     str         r12, [sp, #pos]
 .equ pos, pos + 4
 .endr
@@ -75,9 +78,9 @@ function x264_checkasm_call_\variant
     mov         r12, r0
     mov         r0,  r2
     mov         r1,  r3
-    ldrd        r2,  r3,  [sp, #ARG_STACK + pushed]
+    ldrd        r2,  r3,  [sp, #ARG_STACK_A + pushed]
     blx         r12
-    add         sp,  sp,  #ARG_STACK
+    add         sp,  sp,  #ARG_STACK_A
     pop         {r2}
 
     push        {r0, r1}
-- 
2.7.4



More information about the x264-devel mailing list