Skip to content

Commit b927ef7

Browse files
author
Colin Robertson
committed
Add linker option, hubpage, TOC
1 parent aeb65ce commit b927ef7

34 files changed

+636
-188
lines changed

docs/_breadcrumb/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
- name: Code analysis
5959
tocHref: /cpp/code-quality/
6060
topicHref: /cpp/code-quality/index
61+
- name: Code sanitizers
62+
tocHref: /cpp/sanitizers/
63+
topicHref: /cpp/sanitizers/index
6164
- name: C++ language
6265
tocHref: /cpp/cpp/
6366
topicHref: /cpp/cpp/index

docs/build/reference/compiler-options-listed-alphabetically.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ This table contains an alphabetical list of compiler options. For a list of comp
4949
| [`/Fp`](fp-name-dot-pch-file.md) | Specifies a precompiled header file name. |
5050
| [`/FR`](fr-fr-create-dot-sbr-file.md)<br /><br /> [`/Fr`](fr-fr-create-dot-sbr-file.md) | Generates browser files. **`/Fr`** is deprecated. |
5151
| [`/FS`](fs-force-synchronous-pdb-writes.md) | Forces serialization of all writes to the program database (PDB) file through MSPDBSRV.EXE. |
52+
| [`/fsanitize`](fsanitize.md.md) | Enables compilation of sanitizer instrumentation such as AddressSanitizer. |
5253
| [`/FU`](fu-name-forced-hash-using-file.md) | Forces the use of a file name as if it had been passed to the [`#using`](../../preprocessor/hash-using-directive-cpp.md) directive. |
5354
| [`/Fx`](fx-merge-injected-code.md) | Merges injected code with source file. |
5455
| [`/GA`](ga-optimize-for-windows-application.md) | Optimizes code for Windows application. |

docs/build/reference/compiler-options-listed-by-category.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ This article contains a categorical list of compiler options. For an alphabetica
155155
| [`/errorReport`](errorreport-report-internal-compiler-errors.md) | Deprecated. Error reporting is controlled by [Windows Error Reporting (WER)](/windows/win32/wer/windows-error-reporting) settings. |
156156
| [`/FC`](fc-full-path-of-source-code-file-in-diagnostics.md) | Displays the full path of source code files passed to *cl.exe* in diagnostic text. |
157157
| [`/FS`](fs-force-synchronous-pdb-writes.md) | Forces writes to the PDB file to be serialized through *MSPDBSRV.EXE*. |
158+
| [`/fsanitize`](fsanitize.md.md) | Enables compilation of sanitizer instrumentation such as AddressSanitizer. |
158159
| [`/H`](h-restrict-length-of-external-names.md) | Deprecated. Restricts the length of external (public) names. |
159160
| [`/HELP`](help-compiler-command-line-help.md) | Lists the compiler options. |
160161
| [`/J`](j-default-char-type-is-unsigned.md) | Changes the default **`char`** type. |

docs/build/reference/fsanitize.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
description: "Learn more about the /fsanitize (enable sanitizers) compiler option"
3-
title: "/fsanitize (enable sanitizers)"
3+
title: "/fsanitize (Enable sanitizers)"
44
ms.date: 02/24/2021
55
f1_keywords: ["/fsanitize", "-fsanitize", "/fsanitize-address-use-after-return", "-fsanitize-address-use-after-return", "/fno-sanitize-address-vcasan-lib", "-fno-sanitize-address-vcasan-lib"]
66
helpviewer_keywords: ["/fsanitize [C++]", "-fsanitize=address [C++]", "address sanitizer [C++]", "/fsanitize-address-use-after-return", "/fno-sanitize-address-vcasan-lib"]
77
---
8-
# `/fsanitize` (enable sanitizers)
8+
# `/fsanitize` (Enable sanitizers)
99

1010
Use the **`/fsanitize`** compiler options to enable sanitizers. As of Visual Studio 2019 16.9, the only supported sanitizer is [AddressSanitizer](../../sanitizers/asan.md).
1111

@@ -14,13 +14,12 @@ Use the **`/fsanitize`** compiler options to enable sanitizers. As of Visual Stu
1414
> **`/fsanitize=address`**\
1515
> **`/fsanitize-address-use-after-return`**\
1616
> **`/fno-sanitize-address-vcasan-lib`**\
17-
> **`/INFERASANLIBS`**\[**`:no`**]
1817
1918
## Remarks
2019

2120
The **`/fsanitize=address`** compiler option enables [AddressSanitizer](../../sanitizers/asan.md), a powerful compiler and runtime technology to light up [hard-to-find bugs](../../sanitizers/asan.md#error-types).
2221

23-
The **`/fsanitize-address-use-after-return`** and **`/fno-sanitize-address-vcasan-lib`** compiler options, and the **`/INFERASANLIBS`** and **`/INFERASANLIBS:no`** linker options offer support for advanced users. See [AddressSanitizer build and language reference](../../sanitizers/asan-building.md) for more details.
22+
The **`/fsanitize-address-use-after-return`** and **`/fno-sanitize-address-vcasan-lib`** compiler options, and the [`/INFERASANLIBS` (Use inferred sanitizer libs)](./inferasanlibs.md) and **`/INFERASANLIBS:NO`** linker options offer support for advanced users. See [AddressSanitizer build and language reference](../../sanitizers/asan-building.md) for more details.
2423

2524
The **`/fsanitize`** options are available beginning in Visual Studio 2019 version 16.9.
2625

@@ -44,9 +43,6 @@ The **`/fsanitize`** options are available beginning in Visual Studio 2019 versi
4443

4544
1. Choose **OK** or **Apply** to save your changes.
4645

47-
, go to the by using the **Additional Options** properties under the respective dropdowns.
48-
Set the advanced compiler and linker options by using the **Additional Options** properties under the respective dropdowns.
49-
5046
### To set this compiler option programmatically
5147

5248
- See <xref:Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool.AdditionalOptions%2A>.
@@ -55,6 +51,7 @@ Set the advanced compiler and linker options by using the **Additional Options**
5551

5652
[MSVC compiler options](compiler-options.md)\
5753
[MSVC compiler command-line syntax](compiler-command-line-syntax.md)\
54+
[`/INFERASANLIBS` (Use inferred sanitizer libs)](./inferasanlibs.md)\
5855
[AddressSanitizer overview](../../sanitizers/asan.md)\
5956
[AddressSanitizer known issues](../../sanitizers/asan-known-issues.md)\
6057
[AddressSanitizer build and language reference](../../sanitizers/asan-building.md)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
description: "Learn more about the /INFERASANLIBS (Use inferred sanitizer libs) linker option"
3+
title: "/INFERASANLIBS (Use inferred sanitizer libs)"
4+
ms.date: 03/01/2021
5+
f1_keywords: ["/INFERASANLIBS", "/INFERASANLIBS:NO"]
6+
helpviewer_keywords: ["/INFERASANLIBS [C++]", "address sanitizer [C++] linker option"]
7+
---
8+
# `/INFERASANLIBS` (Use inferred sanitizer libs)
9+
10+
Use the **`/INFERASANLIBS`** linker option to enable or disable linking to the default sanitizer libraries. As of Visual Studio 2019 16.9, the only supported sanitizer is [AddressSanitizer](../../sanitizers/asan.md).
11+
12+
## Syntax
13+
14+
> **`/INFERASANLIBS`**\[**`:NO`**]
15+
16+
## Remarks
17+
18+
The **`/INFERASANLIBS`** linker option enables the default [AddressSanitizer](../../sanitizers/asan.md) libraries. AddressSanitizer is a powerful compiler and runtime technology to light up [hard-to-find bugs](../../sanitizers/asan.md#error-types).
19+
20+
The **`/INFERASANLIBS`** and **`/INFERASANLIBS:NO`** linker options offer support for advanced users. See [AddressSanitizer build and language reference](../../sanitizers/asan-building.md) for more details.
21+
22+
The **`/INFERASANLIBS`** option is available beginning in Visual Studio 2019 version 16.9.
23+
24+
### To set the **`/INFERASANLIBS`** linker option in the Visual Studio development environment
25+
26+
1. Open your project's **Property Pages** dialog box.
27+
28+
1. Select the **Configuration Properties** > **Linker** > **Command Line** property page.
29+
30+
1. Modify the **Additional Options** property. To enable default libraries, enter **/INFERASANLIBS** in the edit box. To disable default libraries, enter **/INFERASANLIBS:no** instead.
31+
32+
1. Choose **OK** or **Apply** to save your changes.
33+
34+
### To set this linker option programmatically
35+
36+
- See <xref:Microsoft.VisualStudio.VCProjectEngine.VCLinkerTool.AdditionalOptions%2A>.
37+
38+
## See also
39+
40+
[MSVC linker reference](linking.md)\
41+
[MSVC linker options](linker-options.md)\
42+
[`/fsanitize` (Enable sanitizers)](./fsanitize.md)\
43+
[AddressSanitizer overview](../../sanitizers/asan.md)\
44+
[AddressSanitizer known issues](../../sanitizers/asan-known-issues.md)\
45+
[AddressSanitizer build and language reference](../../sanitizers/asan-building.md)

docs/build/reference/linker-options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ You can use the [comment](../../preprocessor/comment-c-cpp.md) pragma to specify
7272
|[/IMPLIB](implib-name-import-library.md)|Overrides the default import library name.|
7373
|[/INCLUDE](include-force-symbol-references.md)|Forces symbol references.|
7474
|[/INCREMENTAL](incremental-link-incrementally.md)|Controls incremental linking.|
75+
|[/INFERASANLIBS](inferasanlibs.md)|Uses inferred sanitizer libraries.|
7576
|[/INTEGRITYCHECK](integritycheck-require-signature-check.md)|Specifies that the module requires a signature check at load time.|
7677
|[/KEYCONTAINER](keycontainer-specify-a-key-container-to-sign-an-assembly.md)|Specifies a key container to sign an assembly.|
7778
|[/KEYFILE](keyfile-specify-key-or-key-pair-to-sign-an-assembly.md)|Specifies a key or key pair to sign an assembly.|

docs/build/toc.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@
337337
href: ../build/configuring-programs-for-windows-xp.md
338338
- name: Code analysis for C/C++
339339
href: ../code-quality/
340+
- name: "Code sanitizers for C/C++"
341+
href: ../sanitizers/
340342
- name: Compiler and build tools reference
341343
expanded: false
342344
items:
@@ -558,6 +560,8 @@
558560
href: ../build/reference/fp-specify-floating-point-behavior.md
559561
- name: /FS (Force synchronous PDB writes)
560562
href: ../build/reference/fs-force-synchronous-pdb-writes.md
563+
- name: /fsanitize (Enable sanitizers)
564+
href: ../build/reference/fsanitize.md
561565
- name: /GA (Optimize for Windows application)
562566
href: ../build/reference/ga-optimize-for-windows-application.md
563567
- name: /Gd, /Gr, /Gv, /Gz (Calling convention)
@@ -935,6 +939,8 @@
935939
href: ../build/reference/ignore-ignore-specific-warnings.md
936940
- name: /IGNOREIDL (Don't process attributes into MIDL)
937941
href: ../build/reference/ignoreidl-don-t-process-attributes-into-midl.md
942+
- name: /INFERASANLIBS (Use inferred sanitizer libs)
943+
href: ../build/reference/inferasanlibs.md
938944
- name: /IMPLIB (Name import library)
939945
href: ../build/reference/implib-name-import-library.md
940946
- name: /INCLUDE (Force symbol references)

docs/sanitizers/asan-building.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ The library chosen depends on the compilation options, and is automatically link
116116
| **`/MTd`** | *`libvcasand.lib`* |
117117
| **`/MDd`** | *`vcasand.lib`* |
118118

119-
However, if you compile using **`/Zl`** (Omit default library name), you'll need to manually specify the library. If you don't, you'll get a link failure; one of:
119+
However, if you compile using **`/Zl`** (Omit default library name), you'll need to manually specify the library. If you don't, you'll get a link failure; here are some typical examples:
120120

121121
```Output
122122
error LNK2001: unresolved external symbol __you_must_link_with_VCAsan_lib
123123
error LNK2001: unresolved external symbol ___you_must_link_with_VCAsan_lib
124+
error LNK2019: unresolved external symbol __asan_report_load4 referenced in function main
125+
error LNK2019: unresolved external symbol __asan_report_load8 referenced in function main
124126
```
125127

126128
The improved debugging can be disabled at compile time using the **`/fno-sanitize-address-vcasan-lib`** option.
@@ -129,14 +131,14 @@ The improved debugging can be disabled at compile time using the **`/fno-sanitiz
129131

130132
The **`/fsanitize=address`** compiler option produces a binary that exposes memory safety bugs at runtime. When the binary is started from the command line, and the runtime reports an error, it prints the error details. It then and exits the process. The `ASAN_VCASAN_DEBUGGING` environment variable can be set to launch the Visual Studio IDE immediately when the runtime reports an error. This compiler option lets you view the error, superimposed over your source code, at the precise line and column that caused the error.
131133

132-
To enable this behavior, run the command `set ASAN_VCASAN_DEBUGGING=1` before you run your application. You can disable the enhanced debugging experience by running `set ASAN_VISAS_DEBUGGING=0`.
134+
To enable this behavior, run the command `set ASAN_VCASAN_DEBUGGING=1` before you run your application. You can disable the enhanced debugging experience by running `set ASAN_VCASAN_DEBUGGING=0`.
133135

134136
## See also
135137

136-
- [AddressSanitizer Overview](./asan.md)
137-
- [AddressSanitizer Known Issues](./asan-known-issues.md)
138-
- [AddressSanitizer Build and Language Reference](./asan-building.md)
139-
- [AddressSanitizer Runtime Reference](./asan-runtime.md)
140-
- [AddressSanitizer Shadow Bytes](./asan-shadowbytes.md)
141-
- [AddressSanitizer Cloud or Distributed Testing](./asan-offline-crash-dumps.md)
142-
- [AddressSanitizer Debugger Integration](./asan-debugger-integration.md)
138+
[AddressSanitizer overview](./asan.md)\
139+
[AddressSanitizer known issues](./asan-known-issues.md)\
140+
[AddressSanitizer runtime reference](./asan-runtime.md)\
141+
[AddressSanitizer shadow bytes](./asan-shadowbytes.md)\
142+
[AddressSanitizer cloud or distributed testing](./asan-offline-crash-dumps.md)\
143+
[AddressSanitizer debugger integration](./asan-debugger-integration.md)\
144+
[AddressSanitizer error examples](./asan-examples.md)

docs/sanitizers/asan-debugger-integration.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ Here's what happens when a dump file is specified for `ASAN_SAVE_DUMPS`: If an e
4040

4141
## See also
4242

43-
- [AddressSanitizer Overview](./asan.md)
44-
- [AddressSanitizer Known Issues](./asan-known-issues.md)
45-
- [AddressSanitizer Build and Language Reference](./asan-building.md)
46-
- [AddressSanitizer Runtime Reference](./asan-runtime.md)
47-
- [AddressSanitizer Shadow Bytes](./asan-shadowbytes.md)
48-
- [AddressSanitizer Cloud or Distributed Testing](./asan-offline-crash-dumps.md)
49-
- [AddressSanitizer Debugger Integration](./asan-debugger-integration.md)
43+
[AddressSanitizer overview](./asan.md)\
44+
[AddressSanitizer known issues](./asan-known-issues.md)\
45+
[AddressSanitizer build and language reference](./asan-building.md)\
46+
[AddressSanitizer runtime reference](./asan-runtime.md)\
47+
[AddressSanitizer shadow bytes](./asan-shadowbytes.md)\
48+
[AddressSanitizer cloud or distributed testing](./asan-offline-crash-dumps.md)\
49+
[AddressSanitizer error examples](./asan-examples.md)

docs/sanitizers/asan-examples.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: "AddressSanitizer error examples"
3+
description: "Top-level description of the AddressSanitizer error examples in Microsoft C/C++."
4+
ms.date: 03/01/2021
5+
helpviewer_keywords: ["ASan Examples", "AddressSanitizer Examples", "Address Sanitizer Examples", "Examples for AddressSanitizer"]
6+
---
7+
# AddressSanitizer error examples
8+
9+
We've ported some examples to help you learn to use the AddressSanitizer features supported by MSVC in your code. These examples are based on sources in the [LLVM compiler-rt test suite](https://github.com/llvm/llvm-project/tree/main/compiler-rt/test/asan/TestCases).
10+
11+
## Build the examples
12+
13+
Each example provides source code and compilation instructions for a command-line build. To build each example, open a developer command prompt. Create a folder for your example project, then make it the current directory. Then copy the example code into a source file with the appropriate name, such as *`example1.cpp`*. Follow the build instructions to generate and run the instrumented code in the debugger.
14+
15+
## Examples
16+
17+
- [`alloc-dealloc-mismatch`](./examples-alloc-dealloc-mismatch.md)
18+
19+
- [`allocation-size-too-big`](./examples-allocation-size-too-big.md)
20+
21+
- [`calloc-overflow`](./examples-calloc-overflow.md)
22+
23+
- [`double-free`](./examples-double-free.md)
24+
25+
- [`dynamic-stack-buffer-overflow`](./examples-dynamic-stack-buffer-overflow.md)
26+
27+
- [`global-overflow`](./examples-global-overflow.md)
28+
29+
- [`heap-buffer-overflow`](./examples-heap-buffer-overflow.md)
30+
31+
- [`heap-use-after-free`](./examples-heap-use-after-free.md)
32+
33+
- [`invalid-aligned-alloc-alignment`](./examples-invalid-aligned-alloc-alignment.md)
34+
35+
- [`memcpy-param-overlap`](./examples-memcpy-param-overlap.md)
36+
37+
- [`new-delete-type-mismatch`](./examples-new-delete-type-mismatch.md)
38+
39+
- [`stack-buffer-overflow`](./examples-stack-buffer-overflow.md)
40+
41+
- [`stack-buffer-underflow`](./examples-stack-buffer-underflow.md)
42+
43+
- [`stack-use-after-return`](./examples-stack-use-after-return.md)
44+
45+
- [`stack-use-after-scope`](./examples-stack-use-after-scope.md)
46+
47+
- [`strcat-param-overlap`](./examples-strcat-param-overlap.md)
48+
49+
- [`use-after-poison`](./examples-use-after-poison.md)
50+
51+
## See also
52+
53+
[AddressSanitizer overview](./asan.md)\
54+
[AddressSanitizer known issues](./asan-known-issues.md)\
55+
[AddressSanitizer build and language reference](./asan-building.md)\
56+
[AddressSanitizer runtime reference](./asan-runtime.md)\
57+
[AddressSanitizer shadow bytes](./asan-shadowbytes.md)\
58+
[AddressSanitizer cloud or distributed testing](./asan-offline-crash-dumps.md)\
59+
[AddressSanitizer debugger integration](./asan-debugger-integration.md)

0 commit comments

Comments
 (0)