Skip to content

Windows arm64 build system support #9116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ php
# Generated by x64 compiler, includes Debug, Debug_TS, Release, Release_TS
/x64/

# Generated by arm64 compiler, includes Debug, Debug_TS, Release, Release_TS
/arm64/

# Miscellaneous files generated by Windows build system
/main/config.w32.h
/win32/build/deplister.exe
Expand Down
133 changes: 133 additions & 0 deletions Zend/asm/jump_arm64_aapcs_pe_armasm.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
; Copyright Edward Nevill + Oliver Kowalke 2015
; Distributed under the Boost Software License, Version 1.0.
; (See accompanying file LICENSE_1_0.txt or copy at
; http://www.boost.org/LICENSE_1_0.txt)

;*******************************************************
;* *
;* ------------------------------------------------- *
;* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
;* ------------------------------------------------- *
;* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
;* ------------------------------------------------- *
;* | d8 | d9 | d10 | d11 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
;* ------------------------------------------------- *
;* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
;* ------------------------------------------------- *
;* | d12 | d13 | d14 | d15 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
;* ------------------------------------------------- *
;* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
;* ------------------------------------------------- *
;* | x19 | x20 | x21 | x22 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
;* ------------------------------------------------- *
;* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
;* ------------------------------------------------- *
;* | x23 | x24 | x25 | x26 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
;* ------------------------------------------------- *
;* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| *
;* ------------------------------------------------- *
;* | x27 | x28 | FP | LR | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
;* ------------------------------------------------- *
;* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| *
;* ------------------------------------------------- *
;* | fiber data| base | limit | dealloc | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 48 | 49 | 50 | 51 | | | *
;* ------------------------------------------------- *
;* | 0xc0| 0xc4| 0xc8| 0xcc| | | *
;* ------------------------------------------------- *
;* | PC | align | | | *
;* ------------------------------------------------- *
;* *
;*******************************************************

AREA |.text|, CODE, READONLY, ALIGN=4, CODEALIGN
EXPORT jump_fcontext

jump_fcontext proc
; prepare stack for GP + FPU
sub sp, sp, #0xd0

; save d8 - d15
stp d8, d9, [sp, #0x00]
stp d10, d11, [sp, #0x10]
stp d12, d13, [sp, #0x20]
stp d14, d15, [sp, #0x30]

; save x19-x30
stp x19, x20, [sp, #0x40]
stp x21, x22, [sp, #0x50]
stp x23, x24, [sp, #0x60]
stp x25, x26, [sp, #0x70]
stp x27, x28, [sp, #0x80]
stp x29, x30, [sp, #0x90]

; save LR as PC
str x30, [sp, #0xc0]

; save current stack base and limit
ldp x5, x6, [x18, #0x08] ; TeStackBase and TeStackLimit at ksarm64.h
stp x5, x6, [sp, #0xa0]
; save current fiber data and deallocation stack
ldr x5, [x18, #0x1478] ; TeDeallocationStack at ksarm64.h
ldr x6, [x18, #0x20] ; TeFiberData at ksarm64.h
stp x5, x6, [sp, #0xb0]

; store RSP (pointing to context-data) in X0
mov x4, sp

; restore RSP (pointing to context-data) from X1
mov sp, x0

; restore stack base and limit
ldp x5, x6, [sp, #0xa0]
stp x5, x6, [x18, #0x08] ; TeStackBase and TeStackLimit at ksarm64.h
; restore fiber data and deallocation stack
ldp x5, x6, [sp, #0xb0]
str x5, [x18, #0x1478] ; TeDeallocationStack at ksarm64.h
str x6, [x18, #0x20] ; TeFiberData at ksarm64.h

; load d8 - d15
ldp d8, d9, [sp, #0x00]
ldp d10, d11, [sp, #0x10]
ldp d12, d13, [sp, #0x20]
ldp d14, d15, [sp, #0x30]

; load x19-x30
ldp x19, x20, [sp, #0x40]
ldp x21, x22, [sp, #0x50]
ldp x23, x24, [sp, #0x60]
ldp x25, x26, [sp, #0x70]
ldp x27, x28, [sp, #0x80]
ldp x29, x30, [sp, #0x90]

; return transfer_t from jump
; pass transfer_t as first arg in context function
; X0 == FCTX, X1 == DATA
mov x0, x4

; load pc
ldr x4, [sp, #0xc0]

; restore stack from GP + FPU
add sp, sp, #0xd0

ret x4
ENDP
END
107 changes: 107 additions & 0 deletions Zend/asm/make_arm64_aapcs_pe_armasm.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
; Copyright Edward Nevill + Oliver Kowalke 2015
; Distributed under the Boost Software License, Version 1.0.
; (See accompanying file LICENSE_1_0.txt or copy at
; http://www.boost.org/LICENSE_1_0.txt)

;*******************************************************
;* *
;* ------------------------------------------------- *
;* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
;* ------------------------------------------------- *
;* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
;* ------------------------------------------------- *
;* | d8 | d9 | d10 | d11 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
;* ------------------------------------------------- *
;* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
;* ------------------------------------------------- *
;* | d12 | d13 | d14 | d15 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
;* ------------------------------------------------- *
;* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
;* ------------------------------------------------- *
;* | x19 | x20 | x21 | x22 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
;* ------------------------------------------------- *
;* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
;* ------------------------------------------------- *
;* | x23 | x24 | x25 | x26 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
;* ------------------------------------------------- *
;* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| *
;* ------------------------------------------------- *
;* | x27 | x28 | FP | LR | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
;* ------------------------------------------------- *
;* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| *
;* ------------------------------------------------- *
;* | base | limit | dealloc | fiber data| *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 48 | 49 | 50 | 51 | | | *
;* ------------------------------------------------- *
;* | 0xc0| 0xc4| 0xc8| 0xcc| | | *
;* ------------------------------------------------- *
;* | PC | align | | | *
;* ------------------------------------------------- *
;* *
;*******************************************************

AREA |.text|, CODE, READONLY, ALIGN=4, CODEALIGN
EXPORT make_fcontext
IMPORT _exit

make_fcontext proc
; save stack top address to x3
mov x3, x0

; shift address in x0 (allocated stack) to lower 16 byte boundary
and x0, x0, ~0xF

; reserve space for context-data on context-stack
sub x0, x0, #0xd0

; save top address of context_stack as 'base'
str x3, [x0, #0xa0]
; save bottom address of context-stack as 'limit' and 'dealloction stack'
sub x3, x3, x1
stp x3, x3, [x0, #0xa8]
; save 0 as 'fiber data'
str xzr, [x0, #0xb8]

; third arg of make_fcontext() == address of context-function
; store address as x19 for trampoline
str x2, [x0, #0x40]
; store trampoline address as pc
adr x2, trampoline
str x2, [x0, #0xc0]

; save address of finish as return-address for context-function
; will be entered after context-function returns (LR register)
adr x1, finish
str x1, [x0, #0x98]

ret x30 ; return pointer to context-data (x0)

trampoline
stp fp, lr, [sp, #-0x10]!
mov fp, sp
blr x19

finish
; exit code is zero
mov x0, #0
; exit application
bl _exit
ENDP
END
2 changes: 1 addition & 1 deletion ext/standard/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ADD_FLAG("LIBS_STANDARD", "iphlpapi.lib");

EXTENSION("standard", "array.c base64.c basic_functions.c browscap.c \
crc32.c crypt.c crypt_freesec.c crypt_blowfish.c crypt_sha256.c \
crypt_sha512.c php_crypt_r.c crc32_x86.c \
crypt_sha512.c php_crypt_r.c " + (TARGET_ARCH != 'arm64'? " crc32_x86.c" : "") + " \
datetime.c dir.c dl.c dns.c dns_win32.c exec.c \
file.c filestat.c formatted_print.c fsock.c head.c html.c image.c \
info.c iptc.c link.c mail.c math.c md5.c metaphone.c microtime.c \
Expand Down
4 changes: 2 additions & 2 deletions win32/build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ $(PHPDLL_RES): win32\build\template.rc
/I$(BUILD_DIR) /d MC_INCLUDE="\"$(MCFILE)\"" \
win32\build\template.rc

$(BUILD_DIR)\$(PHPDLL): generated_files $(PHPDEF) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(PHPDLL_RES) $(MCFILE)
$(BUILD_DIR)\$(PHPDLL): generated_files $(PHPDEF) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(PHPDLL_RES) $(ASM_OBJS) $(MCFILE)
@copy win32\build\default.manifest $(BUILD_DIR)\$(PHPDLL).manifest >nul
# @$(CC) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(STATIC_EXT_LIBS) $(LIBS) $(PHPDLL_RES) /link /out:$(BUILD_DIR)\$(PHPDLL) $(PHP8_PGD_OPTION) $(PHP_LDFLAGS) $(LDFLAGS) $(STATIC_EXT_LDFLAGS)
@"$(LINK)" $(PHP_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(LIBS) $(PHPDLL_RES) /out:$(BUILD_DIR)\$(PHPDLL) $(PHP8_PGD_OPTION) $(PHP_LDFLAGS) $(LDFLAGS) $(STATIC_EXT_LDFLAGS)
@"$(LINK)" $(PHP_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(LIBS) $(ASM_OBJS) $(PHPDLL_RES) /out:$(BUILD_DIR)\$(PHPDLL) $(PHP8_PGD_OPTION) $(PHP_LDFLAGS) $(LDFLAGS) $(STATIC_EXT_LDFLAGS)
-@$(_VC_MANIFEST_EMBED_DLL)

$(BUILD_DIR)\$(PHPLIB): $(BUILD_DIR)\$(PHPDLL)
Expand Down
7 changes: 0 additions & 7 deletions win32/build/Makefile.frag.w32

This file was deleted.

50 changes: 40 additions & 10 deletions win32/build/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ ARG_WITH('cygwin', 'Path to cygwin utilities on your system', '\\cygwin');

toolset_setup_compiler();

// do we use x64 or 80x86 version of compiler?
X64 = toolset_is_64();
HOST_ARCH = toolset_host_arch();
TARGET_ARCH = toolset_target_arch();
// for compatible only
X64 = TARGET_ARCH != 'x86';
toolset_setup_arch();

toolset_setup_linker();
Expand Down Expand Up @@ -212,7 +214,7 @@ if (PHP_ANALYZER == "vs") {
pvscfg.WriteLine("exclude-path = " + PROGRAM_FILES + "\\windows kits\\");
}
pvscfg.WriteLine("vcinstalldir = " + VCINSTALLDIR);
pvscfg.WriteLine("platform = " + (X64 ? 'x64' : 'Win32'));
pvscfg.WriteLine("platform = " + (TARGET_ARCH == 'x86' ? 'Win32' : 'x64'));
pvscfg.WriteLine("preprocessor = visualcpp");
pvscfg.WriteLine("language = C");
pvscfg.WriteLine("skip-cl-exe = no");
Expand Down Expand Up @@ -241,16 +243,44 @@ ADD_SOURCES("Zend", "zend_language_parser.c zend_language_scanner.c \
zend_enum.c zend_fibers.c zend_atomic.c");
ADD_SOURCES("Zend\\Optimizer", "zend_optimizer.c pass1.c pass3.c optimize_func_calls.c block_pass.c optimize_temp_vars_5.c nop_removal.c compact_literals.c zend_cfg.c zend_dfg.c dfa_pass.c zend_ssa.c zend_inference.c zend_func_info.c zend_call_graph.c zend_dump.c escape_analysis.c compact_vars.c dce.c sccp.c scdf.c");

var FIBER_ASSEMBLER = X64 ? PATH_PROG('ML64') : PATH_PROG('ML');
DEFINE('FIBER_ASSEMBLER', FIBER_ASSEMBLER);
var PHP_ASSEMBLER = PATH_PROG({
'x64': 'ML64',
'x86': 'ML',
'arm64': 'armasm64'
}[TARGET_ARCH]);
if (!PHP_ASSEMBLER) {
ERROR("No assembler found, fiber cannot be built");
}
DEFINE('PHP_ASSEMBLER', PHP_ASSEMBLER);
DEFINE('FIBER_ASSEMBLER', PHP_ASSEMBLER);// for compatible

var FIBER_ASM_ARCH = {
'x64': 'x86_64',
'x86': 'i386',
'arm64': 'arm64'
}[TARGET_ARCH];
DEFINE('FIBER_ASM_ARCH', FIBER_ASM_ARCH); // for compatible only

var FIBER_ASM_ABI = {
'x64': 'x86_64_ms_pe_masm',
'x86': 'i386_ms_pe_masm',
'arm64': 'arm64_aapcs_pe_armasm'
}[TARGET_ARCH];
DEFINE('FIBER_ASM_ABI', FIBER_ASM_ABI);

if (TARGET_ARCH == 'arm64') {
DEFINE('FIBER_ASM_FLAGS', '-nologo -machine ARM64 -o');
} else {
DEFINE('FIBER_ASM_FLAGS', '/DBOOST_CONTEXT_EXPORT=EXPORT /nologo /c /Fo');
}

var FIBER_ASM_ARCH = X64 ? 'x86_64' : 'i386';
DEFINE('FIBER_ASM_ARCH', FIBER_ASM_ARCH);
ADD_FLAG('ASM_OBJS', '$(BUILD_DIR)\\Zend\\jump_' + FIBER_ASM_ABI + '.obj $(BUILD_DIR)\\Zend\\make_' + FIBER_ASM_ABI + '.obj');

ADD_FLAG('LDFLAGS', '$(BUILD_DIR)\\Zend\\jump_' + FIBER_ASM_ARCH + '_ms_pe_masm.obj');
ADD_FLAG('LDFLAGS', '$(BUILD_DIR)\\Zend\\make_' + FIBER_ASM_ARCH + '_ms_pe_masm.obj');
MFO.WriteLine('$(BUILD_DIR)\\Zend\\jump_' + FIBER_ASM_ABI + '.obj: Zend\\asm\\jump_' + FIBER_ASM_ABI + '.asm');
MFO.WriteLine('\t$(PHP_ASSEMBLER) $(FIBER_ASM_FLAGS) $(BUILD_DIR)\\Zend\\jump_$(FIBER_ASM_ABI).obj Zend\\asm\\jump_$(FIBER_ASM_ABI).asm');

ADD_MAKEFILE_FRAGMENT('win32/build/Makefile.frag.w32');
MFO.WriteLine('$(BUILD_DIR)\\Zend\\make_' + FIBER_ASM_ABI + '.obj: Zend\\asm\\make_' + FIBER_ASM_ABI + '.asm');
MFO.WriteLine('\t$(PHP_ASSEMBLER) $(FIBER_ASM_FLAGS) $(BUILD_DIR)\\Zend\\make_$(FIBER_ASM_ABI).obj Zend\\asm\\make_$(FIBER_ASM_ABI).asm');

ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
if (VS_TOOLSET && VCVERS >= 1914) {
Expand Down
6 changes: 4 additions & 2 deletions win32/build/config.w32.phpize.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ var PHP_CYGWIN="notset";

toolset_setup_compiler();

// do we use x64 or 80x86 version of compiler?
X64 = toolset_is_64();
HOST_ARCH = toolset_host_arch();
TARGET_ARCH = toolset_target_arch();
// for compatible only
X64 = TARGET_ARCH != 'x86';
toolset_setup_arch();

toolset_setup_linker();
Expand Down
Loading