|
1 | 1 | ---
|
2 | 2 | description: "Learn more about: /Qspectre"
|
3 | 3 | title: "/Qspectre"
|
4 |
| -ms.date: 06/22/2021 |
| 4 | +ms.date: 07/02/2021 |
5 | 5 | f1_keywords: ["VC.Project.VCCLCompilerTool.SpectreMitigation"]
|
6 | 6 | helpviewer_keywords: ["/Qspectre"]
|
7 | 7 | ---
|
@@ -52,21 +52,45 @@ The effect of **`/Qspectre`** on performance appeared to be negligible in severa
|
52 | 52 |
|
53 | 53 | ### Required libraries
|
54 | 54 |
|
55 |
| -The **`/Qspectre`** compiler option generates code that implicitly links versions of the runtime libraries built to provide Spectre mitigations. These libraries are optional components that must be installed by using the Visual Studio Installer: |
| 55 | +The **`/Qspectre`** compiler option mitigates issues in your own code. For greater protection, we strongly recommend you also use libraries built to provide Spectre mitigations. Several of the Microsoft runtime libraries are available with Spectre mitigations. |
| 56 | + |
| 57 | +::: moniker range=">=msvc-150" |
| 58 | + |
| 59 | +These libraries are optional components that must be installed by using the Visual Studio Installer: |
56 | 60 |
|
57 | 61 | - MSVC version *version_numbers* Libs for Spectre \[(x86 and x64) | (ARM) | (ARM64)]
|
58 | 62 | - Visual C++ ATL for \[(x86/x64) | ARM | ARM64] with Spectre Mitigations
|
59 | 63 | - Visual C++ MFC for \[x86/x64 | ARM | ARM64] with Spectre Mitigations
|
60 | 64 |
|
| 65 | +::: moniker-end |
| 66 | + |
61 | 67 | ::: moniker range=">=msvc-160"
|
62 | 68 |
|
63 |
| -If you build your code by using **`/Qspectre`** and these libraries aren't installed, the build system reports warning [MSB8040](/visualstudio/msbuild/errors/msb8040). If your MFC or ATL code fails to build, and the linker reports an error such as "fatal error LNK1104: cannot open file 'oldnames.lib'", these missing libraries may be the cause. |
| 69 | +The default MSBuild-based project system in the Visual Studio IDE lets you specify a [Spectre Mitigation](./c-cpp-prop-page.md#spectre-mitigation) property for your projects. This property sets the **`/Qspectre`** compiler option and changes the library paths to link the Spectre-mitigated runtime libraries. If these libraries aren't installed when you build your code, the build system reports warning [MSB8040](/visualstudio/msbuild/errors/msb8040). If your MFC or ATL code fails to build, and the linker reports an error such as "fatal error LNK1104: cannot open file 'oldnames.lib'", these missing libraries may be the cause. |
64 | 70 |
|
65 | 71 | ::: moniker-end
|
66 | 72 |
|
67 |
| -::: moniker range="<=msvc-150" |
| 73 | +::: moniker range="msvc-150" |
| 74 | + |
| 75 | +The default MSBuild-based project system in the Visual Studio IDE lets you specify a [Spectre Mitigation](./c-cpp-prop-page.md#spectre-mitigation) property for your projects. This property sets the **`/Qspectre`** compiler option and changes the library paths to link the Spectre-mitigated runtime libraries. If these libraries aren't installed when you build your code, the build system reports warning MSB8038: "Spectre mitigation is enabled but Spectre mitigated libraries are not found". If your MFC or ATL code fails to build, and the linker reports an error such as "fatal error LNK1104: cannot open file 'oldnames.lib'", these missing libraries may be the cause. |
| 76 | + |
| 77 | +::: moniker-end |
| 78 | + |
| 79 | +::: moniker range=">=msvc-150" |
68 | 80 |
|
69 |
| -If you build your code by using **`/Qspectre`** and these libraries aren't installed, the build system reports warning MSB8038: "Spectre mitigation is enabled but Spectre mitigated libraries are not found". If your MFC or ATL code fails to build, and the linker reports an error such as "fatal error LNK1104: cannot open file 'oldnames.lib'", these missing libraries may be the cause. |
| 81 | +There are several ways to specify the Spectre-mitigated libraries to the build command line. You can specify the path to the Spectre-mitigated libraries by using the [`/LIBPATH`](./libpath-additional-libpath.md) linker option to make them the default libraries. You can use the [`/NODEFAULTLIB`](./nodefaultlib-ignore-libraries.md) linker option and explicitly link the Spectre-mitigated libraries. Or, you can set the `LIBPATH` environment variable to include the path to the Spectre-mitigated libraries for your target platform. One way to set this path in the environment is to use a developer command prompt set up by using the `spectre_mode` option. For more information, see [Use the developer tools in an existing command window](../building-on-the-command-line.md#use-the-developer-tools-in-an-existing-command-window). |
| 82 | + |
| 83 | +::: moniker-end |
| 84 | + |
| 85 | +::: moniker range="msvc-140" |
| 86 | + |
| 87 | +Spectre-mitigated runtime libraries for x86, x64 and ARM platforms are available as part of the patch available through [KB 4338871](https://support.microsoft.com/help/4338871). By default, these libraries are installed in the following directories: |
| 88 | + |
| 89 | +- x86: *`C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\spectre`* |
| 90 | +- x64: *`C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\spectre\amd64`* |
| 91 | +- ARM: *`C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\spectre\arm`* |
| 92 | + |
| 93 | +There are several ways to specify the Spectre-mitigated libraries to the build command line. You can specify the path to the Spectre-mitigated libraries by using the [`/LIBPATH`](./libpath-additional-libpath.md) linker option to make them the default libraries. You can use the [`/NODEFAULTLIB`](./nodefaultlib-ignore-libraries.md) linker option and explicitly link the Spectre-mitigated libraries. Or, you can set the `LIBPATH` environment variable to include the path to the Spectre-mitigated libraries for your target architecture. For more information, see [Use the Microsoft C++ toolset from the command line](../building-on-the-command-line.md). |
70 | 94 |
|
71 | 95 | ::: moniker-end
|
72 | 96 |
|
@@ -96,7 +120,11 @@ For an overview of Spectre vulnerabilities addressed by the MSVC mitigations, se
|
96 | 120 |
|
97 | 121 | 1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
|
98 | 122 |
|
99 |
| -1. Enter the *`/Qspectre`* compiler option in the **Additional Options** box. Choose **OK** to apply the change. |
| 123 | +1. Enter the *`/Qspectre`* compiler option in the **Additional Options** box. Choose **Apply** to apply the change. |
| 124 | + |
| 125 | +1. Select the **Configuration Properties** > **Linker** > **General** property page. |
| 126 | + |
| 127 | +1. For each Platform in your project properties, edit the **Additional Library Directories** property. Set the path to the Spectre-mitigated runtime library directory for the target platform, and then choose **Apply** to apply the change. When done, choose **OK**. |
100 | 128 |
|
101 | 129 | ::: moniker-end
|
102 | 130 |
|
|
0 commit comments