Repository navigation
[release/10.0] Enable Control Flow Guard for Windows binaries - #232
Merged
akoeplinger merged 1 commit intoJul 27, 2026
Merged
Conversation
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
lewing
approved these changes
Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of #231 to
dotnet/release/10.0.Passes
/p:EnableControlFlowGuard=Guardto thePCbuild\build.batinvocation incpython.projso the Windows binaries (python.exe,python3xx.dll, extension modules) are built with/guard:cf.CPython's
PCbuild/pyproject.propsalready exposes theEnableControlFlowGuardproperty onClCompile, so no changes to upstream files are needed. MSVC'sMicrosoft.CppCommon.targetsderivesLinkControlFlowGuardfrom that metadata, so both the compiler and linker get/guard:cf.Applies to both the
Windows_x64andWindows_arm64legs. Non-Windows builds are unaffected.Note: this branch's command line does not carry the
/p:IncludeTests=falseargument thatdotnet/mainhas, so the change was applied manually rather than cherry-picked. The resultingEnableControlFlowGuardargument is identical.Verification
Verified on the
dotnet/mainversion of this change (#231) with a full local x64 Release build:CL.exeandlink.exeboth receive/guard:cf.dumpbin /loadconfigon 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.pydlikewise.Guard Flags 00000100with a CF function count of 0, i.e. CFG not enforced -- confirming the flag is what enables it.python.exeruns correctly: all extension modules import, a live TLS 1.3 handshake succeeds, andctypescallbacks 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.