FIX: Programs that are built in Visual C++ 2013 crash with "Illegal Instruction" exception
When you build a program by using Microsoft Visual C++ 2013, the program crashes and you receive an "Illegal Instruction" exception. This occurs because some floating-point math library functions in the Visual C++ 2013 x64 C Runtime (CRT) do not correctly check whether certain AVX and FMA3 instructions are available before the functions try to use them. If the instructions are not available for use, calls to these functions cause an illegal instruction exception (0xc000001d). Affected functions include log, log10, and pow, and others.
This problem is most likely to occur in the following scenarios:
- On an old version of the Windows operating system that does not support AVX state saving (for example, Windows Vista) if it's used on a computer that supports the AVX instruction set
- If AVX state saving is explicitly disabled in the operating system boot configuration
- In the Windows Preinstall Environment (Windows PE)
Note Windows PE does not support AVX state saving.
This problem has been reported on Microsoft Connect:
This issue occurs because the Visual C++ 2013 x64 C Runtime does not check whether the operating system supports AVX state saving before it tries to run AVX or FMA3 instructions.
If all affected C++ binaries that are built by using Visual C++ 2013 use the C Runtime DLL (msvcr120.dll), install the updated Microsoft Visual C++ 2013 Redistributable – 12.0.40660.0 or a later version.
If your affected C++ binaries statically link the Visual C++ 2013 C Runtime, you must update your installation of Visual Studio 2013 by installing the 3174417 hotfix and rebuilding and redeploying the affected binaries.
Note This problem does not affect older versions of the Visual C++ C Runtime (Visual C++ 2012 and earlier versions). The problem was fixed before the initial release of the Universal CRT that is used by Visual C++ 2015.
Microsoft Download CenterTo update the statically linked Visual C++ 2013 C Runtime, the 3174417 hotfix is released as a download-only update and isn't distributed through Windows Update. It is available at the Microsoft Download Center website:
Download the package now.
To update the dynamically linked Visual C++ 2013 C Runtime DLLs, an updated redistributable is available. For more information, see the following Microsoft Knowledge Base article:
To work around this problem, disable FMA3 in the math library if you are affected by this problem. You can query whether the system supports AVX instructions by calling GetEnabledXStateFeatures and disabling AVX in the CRT explicitly by calling _set_FMA3_enable(0).
For more information, see Working with XState Context on the MSDN website.
The function _set_FMA3_enable(0) is declared in <math.h>, and it's available only when you build for x64. (This problem affects only the x64 libraries.) This causes the math library to revert to using the non-FMA3 implementations.
Article ID: 3174417 - Last Review: 07/28/2016 08:18:00 - Revision: 1.0
Visual Studio 2013 Community Edition
- kbfix kbqfe atdownload kbexpertiseadvanced kbsurveynew KB3174417