]> wimlib.net Git - wimlib/blobdiff - include/wimlib.h
Align stack when entering wimlib on 32-bit x86
[wimlib] / include / wimlib.h
index 6c68865f1a7e7e8b54b8e42812aa21ca0ebac6f9..ef08e96e5ac1952e5ad6fce0f53973bce7362bf0 100644 (file)
 #include <time.h>
 
 #ifdef BUILDING_WIMLIB
+  /*
+   * On i386, gcc assumes that the stack is 16-byte aligned at function entry.
+   * However, some compilers (e.g. MSVC) and programming languages (e.g. Delphi)
+   * only guarantee 4-byte alignment when calling functions.  This is mainly an
+   * issue on Windows, but it can occur on Linux too.  Work around this ABI
+   * incompatibility by realigning the stack pointer when entering the library.
+   * This prevents crashes in SSE/AVX code.
+   */
+#  if defined(__GNUC__) && defined(__i386__)
+#    define WIMLIB_ALIGN_STACK  __attribute__((force_align_arg_pointer))
+#  else
+#    define WIMLIB_ALIGN_STACK
+#  endif
 #  ifdef _WIN32
-#    define WIMLIBAPI __declspec(dllexport)
+#    define WIMLIBAPI __declspec(dllexport) WIMLIB_ALIGN_STACK
 #  else
-#    define WIMLIBAPI __attribute__((visibility("default")))
+#    define WIMLIBAPI __attribute__((visibility("default"))) WIMLIB_ALIGN_STACK
 #  endif
 #else
 #  define WIMLIBAPI