Skip to content

Enable Control Flow Guard for Windows binaries - #231

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

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

Conversation

@akoeplinger

Copy link
Copy Markdown
Member

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.

Verification

Local build with the flag, checked via binlog and dumpbin:

  • CL.exe ... /guard:cf
  • link.exe ... /guard:cf
  • dumpbin /loadconfig on the produced binary reports Guard Flags 00017500 -> CF instrumented, with a populated Guard CF function table.

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
akoeplinger merged commit 33b2c5d into dotnet/main Jul 27, 2026
6 checks passed

@radekdoulik radekdoulik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@akoeplinger
akoeplinger deleted the akoeplinger/enable-cfg-windows branch July 27, 2026 14:16
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
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.

3 participants