cinvoke-dev
[Top][All Lists]
Advanced

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

[cinvoke-dev] OS X/Intel fixes


From: Mooneer Salem
Subject: [cinvoke-dev] OS X/Intel fixes
Date: Sat, 2 Aug 2008 02:58:18 -0700

Hi again,

I discovered a pretty nasty bug when using C/Invoke on an Intel Mac
running OSX. As it turns out, OSX on 32-bit Intel requires 16-byte
stack alignment, so attempting to use C/Invoke on that platform
results in weird crashes in __dyld_misaligned_stack_error() (64-bit
uses the standard ABI, so it worked correctly without modification
when I built the library and Kite for 64-bit). Below is a patch that
should fix this issue. I just went ahead and enforced 16-byte
alignment regardless of the OS, but this should not change the
behavior outside OSX.

--- cinvoke.old/lib/arch/gcc_x86_unix.h 2008-07-29 00:46:50.000000000 -0700
+++ cinvoke/lib/arch/gcc_x86_unix.h     2008-08-02 01:55:47.000000000 -0700
@@ -86,7 +86,9 @@
                        "m" ((archvalue).ivalhigh) : \
                        "%eax", "%edx");

+/* OSX requires 16-byte alignment on x86-32. Should not hurt on other
x86 OSes. */
 #define ARCH_PUT_STACK_BYTES(bcount) \
+    bcount += ((bcount % 16) ? (16 - (bcount % 16)) : 0); \
        __asm__("subl %0, %%esp" :: "m" (bcount) : "%esp");

 #define ARCH_REMOVE_STACK_BYTES(bcount) \

Let me know if you have any questions.

Thanks,

-Mooneer

P.S.: Kite 1.0b4 was just released today, with the above change. :)




reply via email to

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