# HG changeset patch # User diego # Date 1191278793 0 # Node ID f5610b14236304a278db311ad07ef3fe1d4c363a # Parent 955f18ee1d8d7c0a68115f1cd52166593d55a736 Detect support of and add necessary CFLAGS to avoid crashes when loading Win32 DLLs on Mac OS X / Intel. based on patch by Ulion, ulion2002 gmail com diff -r 955f18ee1d8d -r f5610b142363 configure --- a/configure Mon Oct 01 21:22:41 2007 +0000 +++ b/configure Mon Oct 01 22:46:33 2007 +0000 @@ -2301,6 +2301,25 @@ echores $_named_asm_args +if darwin && test "$cc_vendor" = "gnu" ; then +echocheck "GCC support of -mstackrealign" +# GCC 4.2 and some earlier Apple versions support this flag on x86. Since +# Mac OS X/Intel has an ABI different from Windows this is needed to avoid +# crashes when loading Win32 DLLs. Unfortunately some gcc versions create +# wrong code with this flag, but this can be worked around by adding +# -fno-unit-at-a-time as described in the blog post at +# http://www.dribin.org/dave/blog/archives/2006/12/05/missing_third_param/ +cat > $TMPC << EOF +__attribute__((noinline)) static int foo3(int i1, int i2, int i3) { return i3; } +int main(void) { return foo3(1,2,3) == 3 ? 0 : 1; } +EOF + cc_check -O4 -mstackrealign && tmp_run && _stackrealign=-mstackrealign + test -z "$_stackrealign" && cc_check -O4 -mstackrealign -fno-unit-at-a-time \ + && tmp_run && _stackrealign="-mstackrealign -fno-unit-at-a-time" + test -n "$_stackrealign" && echores "yes" || echores "no" +fi # if darwin && test "$cc_vendor" = "gnu" ; then + + # Checking for CFLAGS _install_strip="-s" if test "$_profile" != "" || test "$_debug" != "" ; then @@ -7527,6 +7546,7 @@ EXTRAXX_INC = $_inc_extra $_inc_extraxx OPTFLAGS = $CFLAGS \$(EXTRA_INC) CXXFLAGS = $CXXFLAGS \$(EXTRAXX_INC) +CFLAG_STACKREALIGN = $_stackrealign INSTALLSTRIP = $_install_strip CHARSET = $_charset HELP_FILE = $_mp_help diff -r 955f18ee1d8d -r f5610b142363 loader/Makefile --- a/loader/Makefile Mon Oct 01 21:22:41 2007 +0000 +++ b/loader/Makefile Mon Oct 01 22:46:33 2007 +0000 @@ -11,6 +11,8 @@ # QTX emulation is not supported in Darwin ifneq ($(TARGET_OS),Darwin) SRCS_COMMON += wrapper.S +else +win32.o: CFLAGS += $(CFLAG_STACKREALIGN) endif endif