Skip to content

Commit 3ce26d8

Browse files
authored
JIT/AArch64: [macos] Fix arguments to variadic function (#7023)
zend_throw_error() and zend_error() are variadic functions. In Linux, arguments are passed in registers, whereas they must be put on stack in Macos [1][2]. In this patch: 1. preprocessor macro "__APPLE__" is used to distinguish the OS. 2. the third argument "CARG3" is the only variadic argument and put on stack. 3. the invocation of zend_error() is converted back to regular call in zend_jit_undefined_offset_stub() and zend_jit_undefined_index_stub(). With this patch, all ~4k test cases can pass for "nonZTS+CALL" functional/tracing JIT with Macos Apple Silicion. [1] https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Overview [2] https://github.com/below/HelloSilicon#listing-9-1 Change-Id: I49bc3233fc253ad3e77e8664464ff3e830dcd183
1 parent b849aa6 commit 3ce26d8

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,10 @@ static int zend_jit_undefined_offset_ex_stub(dasm_State **Dst)
19811981
static int zend_jit_undefined_offset_stub(dasm_State **Dst)
19821982
{
19831983
|->undefined_offset:
1984+
#ifdef __APPLE__
1985+
| stp x29, x30, [sp, # -16]!
1986+
| mov x29, sp
1987+
#endif
19841988
| //sub r4, 8
19851989
| ldr REG0, EX->opline
19861990
| ldr REG1w, OP:REG0->result.var
@@ -1999,9 +2003,17 @@ static int zend_jit_undefined_offset_stub(dasm_State **Dst)
19992003
| mov CARG1, #E_WARNING
20002004
| LOAD_ADDR CARG2, "Undefined array key " ZEND_LONG_FMT
20012005
| ldr CARG3, [REG0]
2006+
#ifdef __APPLE__
2007+
| str CARG3, [sp, #-16]!
2008+
| EXT_CALL zend_error, REG0
2009+
| add sp, sp, #16
2010+
| ldp x29, x30, [sp], #16
2011+
| ret
2012+
#else
20022013
| EXT_JMP zend_error, REG0 // tail call
20032014
| //add r4, 8 // stack alignment
20042015
| //ret
2016+
#endif
20052017

20062018
return 1;
20072019
}
@@ -2018,6 +2030,10 @@ static int zend_jit_undefined_index_ex_stub(dasm_State **Dst)
20182030
static int zend_jit_undefined_index_stub(dasm_State **Dst)
20192031
{
20202032
|->undefined_index:
2033+
#ifdef __APPLE__
2034+
| stp x29, x30, [sp, # -16]!
2035+
| mov x29, sp
2036+
#endif
20212037
| //sub r4, 8
20222038
| ldr REG0, EX->opline
20232039
| ldr REG1w, OP:REG0->result.var
@@ -2037,9 +2053,17 @@ static int zend_jit_undefined_index_stub(dasm_State **Dst)
20372053
| LOAD_ADDR CARG2, "Undefined array key \"%s\""
20382054
| ldr CARG3, [REG0]
20392055
| add CARG3, CARG3, #offsetof(zend_string, val)
2040-
| EXT_JMP zend_error,REG0 // tail call
2056+
#ifdef __APPLE__
2057+
| str CARG3, [sp, #-16]!
2058+
| EXT_CALL zend_error, REG0
2059+
| add sp, sp, #16
2060+
| ldp x29, x30, [sp], #16
2061+
| ret
2062+
#else
2063+
| EXT_JMP zend_error, REG0 // tail call
20412064
| //add r4, 8
20422065
| //ret
2066+
#endif
20432067

20442068
return 1;
20452069
}
@@ -2083,7 +2107,13 @@ static int zend_jit_undefined_function_stub(dasm_State **Dst)
20832107
| ldrsw CARG3, [REG0, #offsetof(zend_op, op2.constant)]
20842108
| ldr CARG3, [REG0, CARG3]
20852109
| add CARG3, CARG3, #offsetof(zend_string, val)
2110+
#ifdef __APPLE__
2111+
| str CARG3, [sp, #-16]!
2112+
#endif
20862113
| EXT_CALL zend_throw_error, REG0
2114+
#ifdef __APPLE__
2115+
| add sp, sp, #16
2116+
#endif
20872117
| b ->exception_handler
20882118
return 1;
20892119
}

0 commit comments

Comments
 (0)