Skip to content

Commit

Permalink
Fix CFG on our static-lib-only DLL projects (microsoft#16056)
Browse files Browse the repository at this point in the history
Control Flow Guard requires both linker and compiler flags.

It turns out that the MSVC build rules determine whether to _link_ with
CFG based on whether it compiled anything with CFG.

It also turns out that when you don't compile anything (such as in our
DLL projects that only consume a static library!), the build rules can't
guess whether to link with CFG.

Whoops.
We need to force it.
  • Loading branch information
DHowett authored Sep 29, 2023
1 parent 4382a17 commit 1b143e3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/common.build.pre.props
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@
<PreferredToolArchitecture>x64</PreferredToolArchitecture>
<EnableHybridCRT Condition="'$(EnableHybridCRT)'=='' and '$(ConfigurationSupportsHybridCRT)'=='true'">true</EnableHybridCRT>
<UseCrtSDKReferenceStaticWarning Condition="'$(EnableHybridCRT)'=='true'">false</UseCrtSDKReferenceStaticWarning>
<!--
We must set this to True for projects that do not contain any ClCompile entries.
The Link task guesses whether to enable CFG based on ClCompile->ControlFlowGuard.
Without any ClCompile entries, there's nothing to guess!
This impacts our dll projects that only link a lib.
-->
<LinkControlFlowGuard>true</LinkControlFlowGuard>
</PropertyGroup>

<ItemDefinitionGroup>
Expand Down

0 comments on commit 1b143e3

Please sign in to comment.