Skip to content

Commit f502918

Browse files
author
Colin Robertson
authored
Address customer comments
Update to distinguish command line and IDE behavior better. Explicitly call for mitigated libraries in command-line builds. Provide some hand-wavy directions on how. Clarify 2015 behavior and instructions.
1 parent bc5500e commit f502918

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

docs/build/reference/qspectre.md

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Learn more about: /Qspectre"
33
title: "/Qspectre"
4-
ms.date: 06/22/2021
4+
ms.date: 07/02/2021
55
f1_keywords: ["VC.Project.VCCLCompilerTool.SpectreMitigation"]
66
helpviewer_keywords: ["/Qspectre"]
77
---
@@ -52,23 +52,45 @@ The effect of **`/Qspectre`** on performance appeared to be negligible in severa
5252

5353
### Required libraries
5454

55-
When you enable the **Configuration Properties** > **C/C++** > **Code Generation** > **Spectre Mitigation** option in the Visual Studio IDE project properties, the following occur:
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.
5656

57-
1. **`/Qspectre`** is thrown to the compiler, ensuring that code compiled in your project has mitigations.
58-
2. The linker [`/LIBPATH`](./libpath-additional-libpath.md) options are changed to the Spectre-mitigation enabled libraries. These libraries are optional components that must be installed by using the Visual Studio Installer:
59-
- MSVC version *version_numbers* Libs for Spectre \[(x86 and x64) | (ARM) | (ARM64)]
60-
- Visual C++ ATL for \[(x86/x64) | ARM | ARM64] with Spectre Mitigations
61-
- Visual C++ MFC for \[x86/x64 | ARM | ARM64] with Spectre Mitigations
57+
::: moniker range=">=msvc-150"
58+
59+
These libraries are optional components that must be installed by using the Visual Studio Installer:
60+
61+
- MSVC version *version_numbers* Libs for Spectre \[(x86 and x64) | (ARM) | (ARM64)]
62+
- Visual C++ ATL for \[(x86/x64) | ARM | ARM64] with Spectre Mitigations
63+
- Visual C++ MFC for \[x86/x64 | ARM | ARM64] with Spectre Mitigations
64+
65+
::: moniker-end
6266

6367
::: moniker range=">=msvc-160"
6468

65-
If Spectre mitigations are enabled 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.
6670

6771
::: moniker-end
6872

69-
::: 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"
7080

71-
If Spectre mitigations are enabled 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).
7294

7395
::: moniker-end
7496

@@ -98,7 +120,11 @@ For an overview of Spectre vulnerabilities addressed by the MSVC mitigations, se
98120

99121
1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
100122

101-
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**.
102128

103129
::: moniker-end
104130

0 commit comments

Comments
 (0)