Skip to content

Commit adb9c7f

Browse files
TylerMSFTTylerMSFT
andauthored
New /QSpectre flag (#5115)
* new topic for /Qspectr-jmp * add links * acrolinx * remove IDE portion since not implemented yet --------- Co-authored-by: TylerMSFT <[email protected]>
1 parent 12f4cd6 commit adb9c7f

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

docs/build/reference/qspectre-jmp.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: "/Qspectre-jmp"
3+
description: "Describes the Microsoft C/C++ compiler (MSVC) /Qspectre-jmp option."
4+
ms.date: 11/30/2023
5+
helpviewer_keywords: ["/Qspectre-jmp"]
6+
---
7+
# `/Qspectre-jmp`
8+
9+
Causes the compiler to generate an `int3` instruction (software interrupt) after unconditional direct branches. This option extends the [`/Qspectre`](qspectre.md) flag and mitigates speculative execution side-channel attacks on unconditional direct branches.
10+
11+
## Syntax
12+
13+
> **/Qspectre-jmp**
14+
15+
## Remarks
16+
17+
**`/Qspectre-jmp`** causes the compiler to detect executable instructions following unconditional direct branches. An `int3` is inserted following unconditional direct branches to ensure that no instructions are speculatively executed beyond the branch. For example, the compiler mitigates `jmp addr` by adding an `int3` instruction following the `jmp` instruction as shown here:
18+
19+
```asm
20+
jmp addr
21+
int3
22+
```
23+
24+
`/Qspectre-jmp` is off by default. It's supported for all optimization levels.
25+
26+
### Set this compiler option programmatically
27+
28+
To set this option programmatically, see [VCCLCompilerTool.AdditionalOptions property](/dotnet/api/microsoft.visualstudio.vcprojectengine.vcclcompilertool.additionaloptions).
29+
30+
## See also
31+
32+
[`/Qspectre`](qspectre.md)\
33+
[`/Qspectre-jmp`](qspectre-jmp.md)\
34+
[`/Qspectre-load`](qspectre-load.md)\
35+
[`/Qspectre-load-cf`](qspectre-load-cf.md)\
36+
[/Q options (Low-Level Operations)](q-options-low-level-operations.md)\
37+
[MSVC compiler options](compiler-options.md)\
38+
[MSVC compiler command-line syntax](compiler-command-line-syntax.md)

docs/build/reference/qspectre-load-cf.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Specifies compiler generation of serializing instructions for every control-flow
1515
1616
## Remarks
1717

18-
**/Qspectre-load-cf** causes the compiler to detect `JMP`, `RET`, and `CALL` control-flow instructions that load from memory, and to insert serializing instructions after the load. Where possible, these instructions are split into a load and a control flow transfer. The load is followed by an `LFENCE` to ensure the load is protected. There are cases where the compiler can't split instructions, such as the `JMP` instruction, so it uses an alternate mitigation technique. For example, the compiler mitigates `jmp [rax]` by adding instructions to load the target non-destructively before inserting an LFENCE, as shown here:
18+
**/Qspectre-load-cf** causes the compiler to detect `JMP`, `RET`, and `CALL` control-flow instructions that load from memory, and to insert serializing instructions after the load. Where possible, these instructions are split into a load and a control flow transfer. The load is followed by an `LFENCE` to ensure the load is protected. There are cases where the compiler can't split instructions, such as the `JMP` instruction, so it uses an alternate mitigation technique. For example, the compiler mitigates `jmp [rax]` by adding instructions to load the target nondestructively before inserting an LFENCE, as shown here:
1919

2020
```asm
2121
xor rbx, [rax]
@@ -44,6 +44,9 @@ The **/Qspectre-load-cf** option is available in Visual Studio 2019 version 16.5
4444

4545
## See also
4646

47+
[`/Qspectre`](qspectre.md)\
48+
[`/Qspectre-jmp`](qspectre-jmp.md)\
49+
[`/Qspectre-load`](qspectre-load.md)\
4750
[/Q options (Low-level operations)](q-options-low-level-operations.md)\
4851
[MSVC compiler options](compiler-options.md)\
4952
[MSVC compiler command-line syntax](compiler-command-line-syntax.md)

docs/build/reference/qspectre-load.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Specifies compiler generation of serializing instructions for every load instruc
1414
1515
## Remarks
1616

17-
**/Qspectre-load** causes the compiler to detect loads from memory, and insert serializing instructions after them. Control flow instructions that load memory, including `RET` and `CALL`, are split into a load and a control flow transfer. The load is followed by an `LFENCE` to ensure the load is protected. There are cases where the compiler can't split control flow instructions, such as the `jmp` instruction, so it uses an alternate mitigation technique. For example, the compiler mitigates `jmp [rax]` by adding instructions to load the target non-destructively before inserting an LFENCE, as shown here:
17+
**/Qspectre-load** causes the compiler to detect loads from memory, and insert serializing instructions after them. Control flow instructions that load memory, including `RET` and `CALL`, are split into a load and a control flow transfer. The load is followed by an `LFENCE` to ensure the load is protected. There are cases where the compiler can't split control flow instructions, such as the `jmp` instruction, so it uses an alternate mitigation technique. For example, the compiler mitigates `jmp [rax]` by adding instructions to load the target nondestructively before inserting an LFENCE, as shown here:
1818

1919
```asm
2020
xor rbx, [rax]
@@ -43,6 +43,9 @@ The **/Qspectre-load** option is available in Visual Studio 2019 version 16.5 an
4343

4444
## See also
4545

46+
[`/Qspectre`](qspectre.md)\
47+
[`/Qspectre-jmp`](qspectre-jmp.md)\
48+
[`/Qspectre-load-cf`](qspectre-load-cf.md)\
4649
[/Q options (Low-Level Operations)](q-options-low-level-operations.md)\
4750
[MSVC compiler options](compiler-options.md)\
4851
[MSVC compiler command-line syntax](compiler-command-line-syntax.md)

docs/build/reference/qspectre.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The **`/Qspectre`** option is off by default.
2323

2424
In its initial release, the **`/Qspectre`** option only worked on optimized code. Starting in Visual Studio 2017 version 15.7, the **`/Qspectre`** option is supported at all optimization levels.
2525

26-
Several Microsoft C++ libraries are also available in versions with Spectre mitigation. The Spectre-mitigated libraries for Visual Studio can be downloaded in the Visual Studio Installer. They're found in the **Individual Components** tab under **Compilers, build tools, and runtimes**, and have "Libs for Spectre" in the name. Both DLL and static runtime libraries with mitigation enabled are available for a subset of the Visual C++ runtimes: VC++ start-up code, vcruntime140, msvcp140, concrt140, and vcamp140. The DLLs are supported for application-local deployment only. The contents of the Visual C++ Runtime Libraries Redistributable haven't been modified.
26+
Several Microsoft C++ libraries are also available in versions with Spectre mitigation. The Spectre-mitigated libraries for Visual Studio can be downloaded in the Visual Studio Installer. They're found in the **Individual Components** tab under **Compilers, build tools, and runtimes**, and have "Libs for Spectre" in the name. Both DLL and static runtime libraries with mitigation enabled are available for a subset of the Visual C++ runtimes: VC++ start-up code, vcruntime140, msvcp140, concrt140, and vcamp140. The DLLs are supported for application-local deployment only. The contents of the Visual C++ Runtime Libraries Redistributable are unmodified.
2727

2828
You can also install Spectre-mitigated libraries for MFC and ATL. They're found in the **Individual Components** tab under **SDKs, libraries, and frameworks**.
2929

@@ -72,7 +72,7 @@ The default MSBuild-based project system in the Visual Studio IDE lets you speci
7272

7373
::: moniker range="msvc-150"
7474

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.
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.
7676

7777
::: moniker-end
7878

@@ -134,6 +134,9 @@ For an overview of Spectre vulnerabilities addressed by the MSVC mitigations, se
134134

135135
## See also
136136

137+
[`/Qspectre-jmp`](qspectre-jmp.md)\
138+
[`/Qspectre-load`](qspectre-load.md)\
139+
[`/Qspectre-load-cf`](qspectre-load-cf.md)\
137140
[`/Q` options (Low-level operations)](q-options-low-level-operations.md)\
138141
[MSVC compiler options](compiler-options.md)\
139142
[MSVC compiler command-line syntax](compiler-command-line-syntax.md)

docs/build/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ items:
700700
href: ../build/reference/qsafe-fp-loads.md
701701
- name: /Qspectre
702702
href: ../build/reference/qspectre.md
703+
- name: /Qspectre-jmp
704+
href: ../build/reference/qspectre-jmp.md
703705
- name: /Qspectre-load
704706
href: ../build/reference/qspectre-load.md
705707
- name: /Qspectre-load-cf

0 commit comments

Comments
 (0)