Folks,
I have come up with a better solution for the problem with the Visual Studio 2010 compiler crashes. I found that once configure/os/CONFIG_SITE.Common.windows-x64-static was changed
to enable optimization, the compiler was also crashing on several files in the synApps motor module. Rather than change C/C++ code or the Makefiles there I experimented with changing the compiler optimization flags for windows-x64-static in EPICS base. I found
that removing the -GL option was sufficient to fix the problem, both in EPICS base and in the motor module.
I removed the code from src/libCom/calc/calcPerform.c (in base 3.15.4) and src/ioc/rsrv/online_notify.c (my addition yesterday) that turned off compiler optimization.
I changed configure/os/CONFIG_SITE.Common.windows-x64-static as follows:
# 64-bit Visual Studio 2010 builds fail when built with the -GL optimization
# flag which is set in CONFIG.win32-x86.win32-x86 with these lines:
# OPT_CFLAGS_YES = -Ox -GL -Oy-
# OPT_CXXFLAGS_YES = -Ox -GL -Oy-
# The lines below have the -GL flag removed from OPT_CFLAGS_YES and OPT_CXXFLAGS_YES.
# If you are using a newer version of Visual Studio you can try removing these lines.
OPT_CFLAGS_YES = -Ox -Oy-
OPT_CXXFLAGS_YES = -Ox -Oy-
These changes leave -Ox (full optimization) and -Oy- (disable omission of frame pointers). It removes -GL which is whole program optimization, i.e. optimization across modules.
This seems like a reasonably minor performance penalty, and is much nicer than the previous HOST_OPT=NO solution. It also eliminates these types of warnings:
d:\synapps-testing\vs10\3.15\base-3.15.4\src\libcom\calc\calcperform.c(47) : warning C4748: /GS can not
protect parameters and local variables from local buffer overrun because optimizations are disabled in function
With this change I successfully rebuilt base 3.15.4 (with change to calcPerform.c noted above), EPICS V4 CPP, and all of synApps, including areaDetector with Visual Studio 2010
with windows-x64-static.
Mark
From: Mark Rivers
Sent: Tuesday, September 06, 2016 10:37 PM
To: 'Andrew Johnson'; EPICS core-talk
Subject: Fix for building 3.15.4 on windows-x64-static
Folks,
3.15.4 configure/os/CONFIG_SITE.windows-x64 contains these lines:
# 64-bit Visual Studio 2010 builds fail when built optimized.
# If you are using a newer version you can try removing this:
HOST_OPT = NO
These lines are present because src/ioc/rsrv/online_notify.c crashes the linker when it is compiled with optimization. The problem with setting HOST_OPT=NO is that programs will
then be compiled with the /MTd switch, which causes them to be linked by default with the LIBCMTD library. LIBCMTD is incompatible with the LIBCMT library that the hdf5 library and other “vendor libraries” may use. HOST_OPT=NO also disables optimization when
compiling all files, which is not necessary.
I have fixed the problem by doing the following:
- Comment out the line HOST_OPT = NO in configure/os/CONFIG_SITE.windows-x64
- Make the following patch to src/ioc/rsrv/online_notify.c.
corvette:src/ioc/rsrv>diff -U3 online_notify.c.orig online_notify.c
--- online_notify.c.orig 2016-09-06 17:26:02.828605405 -0500
+++ online_notify.c 2016-09-06 18:16:52.955345453 -0500
@@ -35,6 +35,11 @@
#define epicsExportSharedSymbols
#include "server.h"
+/* Turn off global optimization for 64-bit MSVC builds on Visual Studio 2010 */
+#if defined(_WIN32) && defined(_M_X64) && _MSC_VER==1600 && !defined(_MINGW)
+# pragma optimize("g", off)
+#endif
+
/*
* RSRV_ONLINE_NOTIFY_TASK
*/
Note that this patch is very similar to the code already present in src/libCom/calc/calcPerform.c, except that calcPerform.c does not restrict the optimization suppression to Visual
Studio 2010. I am not certain what versions of Visual Studio cause problems with calcPerform.c.
/* Turn off global optimization for 64-bit MSVC builds */
#if defined(_WIN32) && defined(_M_X64) && !defined(_MINGW)
# pragma optimize("g", off)
#endif
Both of these workarounds could probably be further improved by only disabling optimization for static builds, not for dynamic builds.
These changes allow building base 3.15.4, and all of the required code for ADCore and ADExample for windows-x64-static with no errors.
Mark