Skip to content

Commit 0fd9307

Browse files
committed
gh-150467: Fix linking python3.dll and python3t.dll with ASan on Windows
The stable ABI forwarder DLLs are linked with /NOENTRY, so nothing pulls in the CRT. With AddressSanitizer enabled, the linker adds the ASan runtime thunk library, which needs the CRT, and the link fails with unresolved symbols. Keep the default CRT entry point for these DLLs when building with ASan.
1 parent 4a9b981 commit 0fd9307

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix linking ``python3.dll`` and ``python3t.dll`` on Windows when building with
2+
AddressSanitizer.

‎PCbuild/pyproject.props‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
<SupportSigning Condition="'$(Configuration)' == 'Debug'">false</SupportSigning>
2626
<SupportSigning Condition="'$(ConfigurationType)' == 'StaticLibrary'">false</SupportSigning>
2727
<LinkIncremental Condition="$(Configuration) != 'Debug'">false</LinkIncremental>
28+
29+
<!--
30+
AddressSanitizer may be enabled with the EnableASAN property or through the
31+
_CL_ and _LINK_ environment variables, so check all of them.
32+
-->
33+
<PyUsingAsan Condition="'$(PyUsingAsan)' == '' and '$(EnableASAN)' == 'true'">true</PyUsingAsan>
34+
<PyUsingAsan Condition="'$(PyUsingAsan)' == '' and $(_CL_.ToLowerInvariant().Contains('fsanitize=address'))">true</PyUsingAsan>
35+
<PyUsingAsan Condition="'$(PyUsingAsan)' == '' and $(_LINK_.ToLowerInvariant().Contains('inferasanlibs'))">true</PyUsingAsan>
2836
</PropertyGroup>
2937

3038
<PropertyGroup Condition="$(TargetExt) != ''">

‎PCbuild/python3dll.vcxproj‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@
9595
<BufferSecurityCheck>false</BufferSecurityCheck>
9696
</ClCompile>
9797
<Link>
98-
<NoEntryPoint>true</NoEntryPoint>
98+
<!--
99+
The ASan runtime thunks need the CRT to be initialized, so keep the
100+
default entry point when building with AddressSanitizer.
101+
-->
102+
<NoEntryPoint Condition="$(PyUsingAsan) != 'true'">true</NoEntryPoint>
99103
</Link>
100104
</ItemDefinitionGroup>
101105
<ItemGroup>

‎PCbuild/python3tdll.vcxproj‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@
9595
<BufferSecurityCheck>false</BufferSecurityCheck>
9696
</ClCompile>
9797
<Link>
98-
<NoEntryPoint>true</NoEntryPoint>
98+
<!--
99+
The ASan runtime thunks need the CRT to be initialized, so keep the
100+
default entry point when building with AddressSanitizer.
101+
-->
102+
<NoEntryPoint Condition="$(PyUsingAsan) != 'true'">true</NoEntryPoint>
99103
</Link>
100104
</ItemDefinitionGroup>
101105
<ItemGroup>

0 commit comments

Comments
 (0)