Skip to content

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

Open
ck0i wants to merge 2 commits into
python:mainfrom
ck0i:gh-150467-asan-python3t
Open

ck0i wants to merge 2 commits 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 also fails this way at the parent of GH-149218, so the bug is older. That change added python3t.dll, a second forwarder built with the same settings.

Fix

python3dll.vcxproj and python3tdll.vcxproj now set NoEntryPoint only when EnableASAN isn't true, so ASan builds keep the default CRT entry point. ASan turned on only through _CL_/_LINK_ is not detected; use /p:EnableASAN=true.

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

Testing

x64 Release, VS 2026 (MSVC 14.51), building python3dll.vcxproj and python3tdll.vcxproj on their own:

  • /p:EnableASAN=true: both failed with LNK2001 before, and link now. dumpbin shows _DllMainCRTStartup as the entry point and an import of clang_rt.asan_dynamic-x86_64.dll.
  • Without ASan: both still have no entry point and no imports, and export the same 964 forwarders.

…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.

@picnixz picnixz added the AI-needs-explanation AI-assisted work that needs further explanation and follow up from the contributor label Oct 31, 2026
@bedevere-app

bedevere-app Bot commented Oct 31, 2026

Copy link
Copy Markdown

Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate.

Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors.

This contribution appears to have been authored with AI assistance. Please explain your contribution in your own words and describe how you checked its correctness.

Please read our guidelines for using AI tools.

@picnixz
picnixz requested a review from chris-eibl October 31, 2026 14:18
@chris-eibl

Copy link
Copy Markdown
Member

LGTM, but see my earlier #150467 (comment) before we proceed here.

@ck0i

ck0i commented Oct 31, 2026

Copy link
Copy Markdown
Author

Agreed, made some changes regarding the comment you linked. Thanks.

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

Labels

AI-needs-explanation AI-assisted work that needs further explanation and follow up from the contributor awaiting review

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

3 participants