* Christian Ullrich wrote:

Backends (and possibly other processes) crash at the slightest
provocation, such as "SELECT * FROM pg_stat_activity;" or VACUUM. The
log says either "exception 0xC0000005" (segfault) or "exception
0xC000001D" (illegal instruction).

The interesting reason: The old host had a Core-generation CPU, which
does not support the AVX2 instruction set. The new one has a
Haswell-generation one, and this one does. The EDB distribution of 9.4
was built with the Visual Studio 2013 compiler, whose CRT (aka libc) has
a bug where it uses AVX2 instructions if the *CPU* supports them, but
does not care whether the *OS* does, and 2008 doesn't. That support was
added in SP1 for 7/2008R2.

I just tried it, and it appears to work. If there is any interest in
fixing this, I'll be happy to prepare a patch. (Where would be the best
place to put a function call from <math.h> that has to be done during
startup of each server process, on Windows only?)

startup_hacks(), I think. Proposed patch attached.

diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index 19176b1..4be21a0 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -26,6 +26,13 @@
 #include <sys/param.h>
+#ifdef _WIN32
+#if _MSC_VER == 1800
+#include <math.h>
+#include <versionhelpers.h>
 #include "bootstrap/bootstrap.h"
 #include "common/username.h"
 #include "postmaster/postmaster.h"
@@ -263,6 +270,22 @@ startup_hacks(const char *progname)
                /* In case of general protection fault, don't show GUI popup 
box */
+#ifdef _M_AMD64
+#if _MSC_VER == 1800
+               /*
+                * Avoid crashing in certain floating-point operations if
+                * we were compiled for x64 with MS Visual Studio 2013 and
+                * are running on Windows prior to 7/2008R2 SP1 on an 
+                * AVX2-capable CPU.
+                */
+               if (!IsWindows7SP1OrGreater())
+               {
+                       _set_FMA3_enable(0);
+               }
+#endif /* _MSC_VER == 1800 */
+#endif /* _M_AMD64 */
 #endif   /* WIN32 */
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to