Skip to content

[dotnet/release/10.0] Enable Control Flow Guard for Windows binaries - #367

Merged
akoeplinger merged 1 commit into
dotnet/release/10.0from
akoeplinger/enable-cfg-windows-10.0
Jul 27, 2026
Merged

akoeplinger merged 1 commit into
dotnet/release/10.0from
akoeplinger/enable-cfg-windows-10.0

Conversation

@akoeplinger

Copy link
Copy Markdown
Member

Ports #366 to dotnet/release/10.0, enabling Control Flow Guard (/guard:cf) for the Windows binaries.

Unlike dotnet/main, this could not be a one-line change. This branch is on Node 18.17, which predates upstream's CFG support -- there is no cfg argument in vcbuild.bat, no --control-flow-guard option in configure.py, and no control_flow_guard handling in common.gypi. So the upstream plumbing is backported first, mirroring upstream exactly:

  • vcbuild.bat -- new cfg argument, mapped to configure --control-flow-guard
  • configure.py -- new --control-flow-guard option setting the control_flow_guard GYP variable
  • common.gypi -- applies /guard:cf to both VCCLCompilerTool and VCLinkerTool under control_flow_guard=="true", defaulting to 'false'
  • node.proj -- passes cfg to vcbuild.bat to opt in

The common.gypi change is gated on the new variable which defaults to off, so it is a no-op for anyone not passing the flag. The node.proj change is inside the ReallyBuildWindows target, so the Linux and macOS legs are unaffected.

Verification

A full build was not run, but the entire plumbing chain was verified locally by running configure and the GYP generation step:

python configure.py --control-flow-guard --dest-cpu=x64 --openssl-no-asm --with-intl=small-icu --enable-static
  • INFO: configure completed successfully
  • config.gypi contains 'control_flow_guard': 'true'
  • all 95 generated project files contain /guard:cf
  • in the generated node project the flag lands on both tools, in both the Debug and Release configurations:
    • VCCLCompilerTool: AdditionalOptions="/Zc:__cplusplus -std:c++17 /guard:cf"
    • VCLinkerTool: AdditionalOptions="/guard:cf /WHOLEARCHIVE:libnode.lib ..."

configure.py and common.gypi were also syntax-checked (py_compile / ast.literal_eval).

Compilation and linking themselves are left to CI. Once it produces binaries this can be confirmed with dumpbin /loadconfig node.exe: look for a non-zero Guard CF function count. Note the CF instrumented bit alone is not sufficient evidence -- it appears even without the flag (contributed by the CRT) with an empty function table.

Backport the upstream Control Flow Guard plumbing and enable it, so node.exe
and the other Windows binaries are built with /guard:cf.

This branch is on Node 18.17, which predates upstream's CFG support, so unlike
dotnet/main the plumbing has to be added first:

  * vcbuild.bat gains a "cfg" argument that maps to --control-flow-guard
  * configure.py gains --control-flow-guard, setting the control_flow_guard
    GYP variable
  * common.gypi applies /guard:cf to both VCCLCompilerTool and VCLinkerTool
    when that variable is "true", defaulting to "false"

node.proj then passes "cfg" to vcbuild.bat to turn it on.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: af43f907-f9b9-4b6a-8617-c0036ac8320c
@akoeplinger akoeplinger changed the title Enable Control Flow Guard for Windows binaries [dotnet/release/10.0] Enable Control Flow Guard for Windows binaries Jul 27, 2026
@akoeplinger
akoeplinger enabled auto-merge (squash) July 27, 2026 15:41
@akoeplinger
akoeplinger merged commit f0e23f7 into dotnet/release/10.0 Jul 27, 2026
10 checks passed
@akoeplinger
akoeplinger deleted the akoeplinger/enable-cfg-windows-10.0 branch August 5, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants