Closed pclayton closed 5 months ago
I am able to work around this issue by specifying -march=i686
(in addition to -m32
) when building Z3.
I'll take a look at it. It may be easy to fix, since I believe that we already require 16-byte alignment for 32-bit macOS (see base/compiler/TopLevel/backend/x86-ccall.sml
).
Fixed in 110.99.5.
Version
110.99.4 (Latest)
Operating System
OS Version
Linux fedora 6.2.15-100.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 11 16:51:53 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Processor
System Component
Foreign-Function Interface (FFI)
Severity
Major
Description
Using 32-bit SML/NJ, which is required for the FFI, we have found that a foreign function called from SML/NJ gives a segmentation fault but works fine when called otherwise, e.g. via the MLton FFI.
Transcript
Expected Behavior
No segmentation fault should occur.
Steps to Reproduce
Briefly, as I have already investigated this:
Z3_mk_config
.Additional Information
The segmentation fault occurs when the following MOVAPS instruction (indicated by
=>
) is executed:This MOVAPS copies %xmm0 to an address on the stack given by
-0x68(%ebp)
and requires the address to be aligned on a 16-byte boundary. However we havewhich means that
-0x68(%ebp)
is not aligned on a 16-byte boundary. The next instruction causes the processor to generate a general-protection exception (#GP), which the OS traps:-0x68(%ebp)
is misaligned here becauseesp
on entry to the functionZ3_mk_config
from SML/NJ is not aligned to a 16-byte boundary. Restarting and breaking just insideZ3_mk_config
we have:The value of
esp
beforepush %edi
is0xffffa9d0
(equal to the value ofebp
);push %ebp
is0xffffa9d4
;eip
) is therefore0xffffa9d8
.So it appears that SML/NJ is calling
Z3_mk_config
withesp
equal to0xffffa9d8
which is not aligned on a 16-byte boundary. This is misaligned by 8 bytes, the same amount that-0x68(%ebp)
was misaligned in the MOVAPS instruction.GCC introduced a 16-byte alignment requirement for the x86 ABI some years ago presumably to allow faster SSE instructions that require alignment to a 16-byte boundary. See this useful summary for more background on this requirement.
Email address
phil.clayton@veonix.com