Skip to content

Latest commit

 

History

History
62 lines (40 loc) · 3.58 KB

msvc_compilation.md

File metadata and controls

62 lines (40 loc) · 3.58 KB

Microsoft Visual Studio (2019)

As I am not running Windows, this section is less precise. But recent versions of Visual Studio support using Clang as a compiler, so all the Clang options apply.

Note about the GUI

The flags described here are those you can set on the command line. Some options can be changed directly in the GUI. Check the following documentation pages for reference:

Warnings

All warnings can be enabled by using the /Wall option, as documented .

Note: The /W4 option does not enable all "level 4" warnings: /W4 displays level 1, level 2, and level 3 warnings, and all level 4 (informational) warnings that aren't off by default.. So, you have to use /Wall and disable the ones that are not relevant.

As with GCC and Clang, MSVC supports disabling warnings for "external" headers, by using the /external option, documented here. For example: /external:anglebrackets /external:W3 will lower warnings to W3 for headers included through <>.

Compilation flags

  • /GS: Checks buffer security doc (on by default).
  • /sdl: enables "Strict mode" for /GS and additional checks. doc
  • /DYNAMICBASE: Generate PIE code for ASLR (default on for recent).
  • /HIGHENTROPYVA: High entropy ASLR for 64 bits targets (default on).
  • /SAFESEH: Safe Structured Exception Handlers (x86 only) doc
  • /guard:cf
  • /guard:ehcont
  • /CETCOMPAT: Mark the binary as compatible with Intel CET. doc.
  • /QSpectre and /Qspectre-load can be used to produce code which mitigates the Spectre vulnerabilities on Intel and AMD. Read the doc before enabling.

Code analysis

Recent versions of Visual Studio support "Code Analysis", as documented here: https://docs.microsoft.com/en-us/cpp/code-quality/code-analysis-for-c-cpp-overview?view=msvc-160

/analyze

Sanitizers

Visual Studio 2019 introduced support for ASan, documented here: https://docs.microsoft.com/en-us/cpp/sanitizers/?view=msvc-160

The /fsanitize command line option is documented here: https://docs.microsoft.com/en-us/cpp/build/reference/fsanitize?view=msvc-160

Runtime checks (for debug builds): https://docs.microsoft.com/en-us/cpp/build/reference/rtc-run-time-error-checks?view=msvc-160

References