Skip to content

Enable Control Flow Guard for Windows binaries - #366

Merged
akoeplinger merged 1 commit into
dotnet/mainfrom
akoeplinger/enable-cfg-windows
Jul 28, 2026
Merged

akoeplinger merged 1 commit into
dotnet/mainfrom
akoeplinger/enable-cfg-windows

Conversation

@akoeplinger

Copy link
Copy Markdown
Member

Passes the cfg argument to vcbuild.bat in node.proj so node.exe and the other Windows binaries are built with Control Flow Guard (/guard:cf).

Upstream Node already has the full plumbing for this, so no changes to upstream files are needed:

  • vcbuild.bat maps cfg -> configure --control-flow-guard
  • configure.py sets the control_flow_guard GYP variable from it
  • common.gypi applies /guard:cf under control_flow_guard=="true" to both VCCLCompilerTool and VCLinkerTool

so the compiler and linker flags are both covered. The variable defaults to 'false' in common.gypi, which is why it needs to be opted into explicitly.

The change is inside the ReallyBuildWindows target, so the Linux and macOS legs are unaffected. Applies to both the Windows x64 and arm64 legs.

Verification

Not built locally -- deferring to CI, which builds all legs.

Once CI produces binaries this can be confirmed with dumpbin /loadconfig node.exe: look for a non-zero Guard CF function count. Note that the CF instrumented bit alone is not sufficient evidence -- it shows up even without the flag (contributed by the CRT) with an empty function table. On the equivalent change in dotnet/cpython, a control build without the flag gave Guard Flags 00000100 with a CF function count of 0, versus 10017500 and thousands of entries with it.

Pass the "cfg" argument to vcbuild.bat so node.exe and the other Windows
binaries are built with Control Flow Guard (/guard:cf) enabled.

vcbuild.bat translates this to configure's --control-flow-guard, which sets
the control_flow_guard GYP variable. common.gypi already applies /guard:cf to
both VCCLCompilerTool and VCLinkerTool when that variable is "true", so both
the compiler and linker flags are covered.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: af43f907-f9b9-4b6a-8617-c0036ac8320c
@akoeplinger
akoeplinger disabled auto-merge July 27, 2026 22:03
@akoeplinger
akoeplinger enabled auto-merge (squash) July 27, 2026 22:04
@akoeplinger
akoeplinger merged commit 08bb19f into dotnet/main Jul 28, 2026
10 checks passed
@akoeplinger
akoeplinger deleted the akoeplinger/enable-cfg-windows 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