libjit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libjit] Stack alignment in 32-bit MinGW builds


From: Jakob Löw
Subject: Re: [Libjit] Stack alignment in 32-bit MinGW builds
Date: Tue, 21 Aug 2018 01:20:39 +0200

According to what I found Microsoft's ABI does not specify a stack
alignment on x86[0]. Is there a reason why gcc aligns the stack on a 8
byte boundary? What happens when an emacs object is not 8 byte aligned?
Does it trigger an memory fault? Apart from SSE instructions I don't
know of any intel architecture instructions causing errors when loading
from unaligned memory. Microsoft themselves say they don't but may have
a performance penalty[1].
In my eyes what you want is non standard and should not be implemented
into libjit but rather emacs should make sure to align the lisp objects
(e.g. using gcc's align __attribute__). Currently the x86 backend of
libjit implements no stack alignment[2], but if one wants to implement
it anyways doing something similar as in the x64 backend[3] should
work.

- Jakob

[0] https://en.wikipedia.org/wiki/X86_calling_conventions#List_of_x86_c
alling_conventions
[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/
x86-architecture#span-idalignmentspanspan-idalignmentspanspan-
idalignmentspanalignment
[2] http://git.savannah.gnu.org/cgit/libjit.git/tree/jit/jit-rules-x86.
c#n223
[3] http://git.savannah.gnu.org/cgit/libjit.git/tree/jit/jit-rules-x86-
64.c#n2442

On Mon, 2018-08-20 at 22:19 +0300, Eli Zaretskii wrote:
> While working on integration of libjit with Emacs, I discovered a
> problem with stack alignment in functions invoked from JIT-compiled
> code on x86 (32-bit) Windows systems.  MS-Windows only guarantees
> 4-byte alignment of the stack in 32-bit programs.  While MinGW GCC
> takes care to align the stack on 8-byte boundary at program startup,
> it assumes that this is enough to keep the stack in all the functions
> 8-byte aligned.  JIT-compiled code seems to break that, because when
> it calls back into Emacs functions, the stack is not necessarily
> aligned on a 8-byte boundary.  (Emacs needs that to be able to create
> stack-based Lisp objects, which must be 8-byte aligned.)
> 
> Is it possible to have the JIT code make sure the stack is 8-byte
> aligned, either always or as a special feature (like some special
> call
> in the function's prologue)?  This would allow to arrange for a 8-
> byte
> aligned stack in all Emacs functions when JIT compilation is used.
> 
> Thanks.
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]