How to force stack alignment for particular target triple in JIT?

I get SEGV in gcc-compiled procedure in Solaris10-i386. This procedure is called from llvm JIT code.
Exact instruction that crashes is this: movdqa %xmm0, 0x10(%esp)
%esp is 8-aligned, and by definition of movdqa it expects 16-aligned stack.
This leads me to believe that llvm uses wrong ABI when calling external procedures and doesn't align stack properly.

llvm module executing in JIT has this target triple: i386-pc-solaris2.10

Isn't target triple supposed to set correct ABI including stack alignment? How to set the correct alignment for this triple?

Yuri

Hi Yuri,

I get SEGV in gcc-compiled procedure in Solaris10-i386. This procedure
is called from llvm JIT code.
Exact instruction that crashes is this: movdqa %xmm0, 0x10(%esp)
%esp is 8-aligned, and by definition of movdqa it expects 16-aligned stack.
This leads me to believe that llvm uses wrong ABI when calling external
procedures and doesn't align stack properly.

llvm module executing in JIT has this target triple: i386-pc-solaris2.10

Isn't target triple supposed to set correct ABI including stack
alignment? How to set the correct alignment for this triple?

it is, however as far as I can see nowhere in LLVM makes any important
decisions based on the triple containing "solaris". I suggest you try
to work out how the stack alignment is set for other operating systems
and send in a patch fixing the solaris case.

Ciao, Duncan.

The attached patch fixes the problem for me. Though further changes will likely be needed for full Solaris ABI compatibility.

Yuri

patch.txt (901 Bytes)

OSX uses 16 Byte. Linux silently changed the SYSV ABI to 16 Byte
alignment as well. The most likely candidate is that all other ELF
platforms simply inherited this change.

Joerg

Hi Yuri,

The attached patch fixes the problem for me. Though further changes will likely
be needed for full Solaris ABI compatibility.

I applied this in commit 126130.

Ciao, Duncan.

It turns out that Solaris (and FreeBSD) is supposed to be SYSV compliant and should have word stack alignment.
gcc probably made a sweeping change once linux decided to change stack alignment.
I filed gcc PR asking gcc to revert their behavior back to prescribed by documentation: 47842 – gcc forces 16-byte stack alignment on Solaris i386, when SYSV requires word alignment

So my previous patch is more for gcc compatibility, rather than a permanent correction.

Yuri