Repository navigation
Enable Control Flow Guard for Windows binaries - #231
Merged
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. Co-authored-by: Copilot <[email protected]> Copilot-Session: af43f907-f9b9-4b6a-8617-c0036ac8320c
akoeplinger
enabled auto-merge (squash)
July 27, 2026 13:28
lewing
approved these changes
Jul 27, 2026
akoeplinger
added a commit
that referenced
this pull request
Jul 27, 2026
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
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.
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.Verification
Local build with the flag, checked via binlog and
dumpbin:CL.exe ... /guard:cflink.exe ... /guard:cfdumpbin /loadconfigon the produced binary reportsGuard Flags 00017500->CF instrumented, with a populated Guard CF function table.