Skip to content

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

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

Port of #231 to dotnet/release/10.0.

Passes /p:EnableControlFlowGuard=Guard to the PCbuild\build.bat invocation in cpython.proj so the Windows binaries (python.exe, python3xx.dll, extension modules) are built with /guard:cf.

CPython's PCbuild/pyproject.props already exposes the EnableControlFlowGuard property on ClCompile, so no changes to upstream files are needed. MSVC's Microsoft.CppCommon.targets derives LinkControlFlowGuard from that metadata, so both the compiler and linker get /guard:cf.

Applies to both the Windows_x64 and Windows_arm64 legs. Non-Windows builds are unaffected.

Note: this branch's command line does not carry the /p:IncludeTests=false argument that dotnet/main has, so the change was applied manually rather than cherry-picked. The resulting EnableControlFlowGuard argument is identical.

Verification

Verified on the dotnet/main version of this change (#231) with a full local x64 Release build:

  • CL.exe and link.exe both receive /guard:cf.
  • dumpbin /loadconfig on the output shows a populated Guard CF function table, e.g. python313.dll -> Guard Flags 10017500, 5371 CF functions; python.exe, _ssl.pyd, _ctypes.pyd, _socket.pyd, _decimal.pyd likewise.
  • A control build without the flag yields Guard Flags 00000100 with a CF function count of 0, i.e. CFG not enforced -- confirming the flag is what enables it.
  • The resulting python.exe runs correctly: all extension modules import, a live TLS 1.3 handshake succeeds, and ctypes callbacks work (the main CFG risk area, since libffi closures make indirect calls into dynamically generated code). asyncio, threading, multiprocessing, subprocess, sqlite3 and exception unwinding all behave normally.

Pass /p:EnableControlFlowGuard=Guard to the PCbuild MSBuild invocation so
python.exe, python3xx.dll and the extension modules are built with /guard:cf.

CPython's PCbuild/pyproject.props already exposes the EnableControlFlowGuard
property, and MSVC derives the matching linker /guard:cf from the ClCompile
setting, so both the compiler and linker flags are applied.

Port of #231 to release/10.0.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: af43f907-f9b9-4b6a-8617-c0036ac8320c
@akoeplinger
akoeplinger enabled auto-merge (squash) July 27, 2026 14:15
@akoeplinger
akoeplinger merged commit b97a67d into dotnet/release/10.0 Jul 27, 2026
6 checks passed
@akoeplinger
akoeplinger deleted the akoeplinger/enable-cfg-windows-10.0 branch August 5, 2026 17:25
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