diff --git a/src/asmjit/base/runtime.cpp b/src/asmjit/base/runtime.cpp index 9d48417..5f5e60f 100644 --- a/src/asmjit/base/runtime.cpp +++ b/src/asmjit/base/runtime.cpp @@ -53,7 +53,7 @@ uint32_t HostRuntime::getStackAlignment() { // not sure about all other UNIX operating systems, because 16-byte alignment // is addition to an older specification. #if (ASMJIT_ARCH_X64) || \ - (ASMJIT_ARCH_X86 && (ASMJIT_OS_LINUX || ASMJIT_OS_BSD || ASMJIT_OS_MAC)) + (ASMJIT_ARCH_X86 && (ASMJIT_OS_LINUX || ASMJIT_OS_BSD || ASMJIT_OS_MAC || ASMJIT_OS_ANDROID)) alignment = 16; #endif diff --git a/src/asmjit/x86/x86compilercontext.cpp b/src/asmjit/x86/x86compilercontext.cpp index d4fe39a..4faa506 100644 --- a/src/asmjit/x86/x86compilercontext.cpp +++ b/src/asmjit/x86/x86compilercontext.cpp @@ -4856,6 +4856,7 @@ static Error X86Context_initFunc(X86Context* self, X86FuncNode* func) { // Adjust stack pointer if function is caller. if (func->isCaller()) { func->addFuncFlags(kFuncFlagIsStackAdjusted); + func->_callStackSize = Utils::alignTo(func->getCallStackSize(), func->getRequiredStackAlignment()); } // Adjust stack pointer if manual stack alignment is needed. @@ -4962,13 +4963,19 @@ static Error X86Context_initFunc(X86Context* self, X86FuncNode* func) { // Count push/pop sequence. v += func->getPushPopStackSize(); + // Count save/restore sequence for XMM registers (should be already aligned). + v += func->getMoveStackSize(); + + // Maximum memory required to call all functions within this function. + v += func->getCallStackSize(); + // Calculate the final offset to keep stack alignment. func->_alignStackSize = Utils::alignDiff(v, func->getRequiredStackAlignment()); } // Memory stack size. func->_memStackSize = self->_memAllTotal; - func->_alignedMemStackSize = Utils::alignTo(func->_memStackSize, func->_requiredStackAlignment); + func->_alignedMemStackSize = Utils::alignTo(func->_memStackSize, func->getRequiredStackAlignment()); if (func->isNaked()) { self->_argBaseReg = kX86RegIndexSp;