Skip to content

gh-150467: Fix linking python3.dll and python3t.dll with ASan on Windows - #160992

Open
ck0i wants to merge 1 commit into
python:mainfrom
ck0i:gh-150467-asan-python3t
Open

ck0i wants to merge 1 commit into
python:mainfrom
ck0i:gh-150467-asan-python3t

Conversation

@ck0i

@ck0i ck0i commented Oct 31, 2026 •

Copy link
Copy Markdown

Fixes gh-150467.

Root cause

python3.dll and python3t.dll only contain /EXPORT forwarders and are linked with /NOENTRY, so the CRT is never pulled in. With ASan enabled, the linker adds clang_rt.asan_dynamic_runtime_thunk, which needs the CRT (_initterm, abort, __vcrt_*, __acrt_*), so the link fails with LNK2001.

python3.dll fails the same way before GH-149218. That change made the problem visible by adding a second forwarder that always gets built.

Fix

  • pyproject.props sets PyUsingAsan when ASan is enabled through EnableASAN=true, /fsanitize=address in _CL_, or /InferASanLibs in _LINK_.
  • python3dll.vcxproj and python3tdll.vcxproj only set NoEntryPoint when PyUsingAsan isn't set, so ASan builds use the default CRT entry point.

Non-ASan builds are unchanged: both DLLs still have no entry point and no imports.

Testing

x64 Release, VS 2026 (MSVC 14.51), ASan enabled with the _CL_/_LINK_ settings from the issue:

  • build.bat -e --no-tkinter -p x64 -M -r: failed before, links now.
  • Same with --disable-gil: failed before, links now.
  • Non-ASan GIL-enabled and free-threaded builds still build, and dumpbin shows the forwarders unchanged.
  • test_sys passes on all four builds, and test_capi passes on the free-threaded builds.

…n 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.
@ck0i
ck0i requested a review from a team as a code owner October 31, 2026 03:32
@python-cla-bot

python-cla-bot Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-31T03:33:16.126766Z
We couldn’t complete this review. Comment @codex review to try again.
0fd9307 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Asan + msvc] Cpython build failed with error LNK2001: unresolved external symbol on windows

1 participant