Repository navigation
Windows: printf and the rest of stdio come from the runtime - #843
Merged
Merged
Conversation
The UCRT has printf, sprintf_s, scanf and the rest of stdio only as inline functions in its headers, which code tslang compiles never sees; a program calling one needed legacy_stdio_definitions.lib in its link line. The runtime every program links (TypeScriptAsyncRuntime) now carries them: StdioDefinitions.cpp takes the address of each, so the compiler emits the header's own definitions there, as the same `selectany` COMDATs a C or C++ caller holds - a program with copies of its own links as it did. legacy_stdio_definitions is gone from exe.cpp and the test runner, and the CMake template and docs samples no longer need it (reverts 5c1b572). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Windows: printf and the rest of stdio come from the runtime
This change was pushed to
x86-stdcall-printfafter #842 had been merged, so it never reachedmain. It is the same commit, cherry-picked ontomain.The UCRT has
printf,sprintf_s,scanfand the rest of stdio only as inline functions in its headers. Code tslang compiles never sees those headers, so a program calling one (a@varargs declare function printf, or thesprintf_sa number's conversion to text uses) neededlegacy_stdio_definitions.libin its link line. On x86 the CRT defines none of them; on x64libucrthappens to defineprintfalone.TypeScriptAsyncRuntime, which every Windows program links, now provides them:lib/TypeScriptAsyncRuntime/StdioDefinitions.cpptakes the address of about 60 functions (the printf and scanf families, narrow and wide, with the_sand_snprintfvariants). The compiler then emits the header's own definitions into the runtime, as the sameselectanyCOMDATs a C or C++ caller gets. A program whose own objects already have copies links as before. On Linux the file compiles to nothing.tslang/runtime, which builds the x86 runtime.legacy_stdio_definitionsis removed fromexe.cppand the test runner's link list.docs/howsamples go back to their original link lists, undoing 5c1b572, which had addedlegacy_stdio_definitionsto them.The definitions are compiled from the UCRT headers when the runtime is built. No MSVC static library is copied into it.
Testing
printf,sprintf_s,scanf,swprintfand the rest.tslang --cmake, unchanged, whose TypeScript callsprintf, links against the new runtime and runs. Against the old runtime it failed withunresolved external symbol printf.printf, and C++ callingsnprintfwhile the runtime's file is pulled in.@cppfailures, nothing new. Linux: the build and the 63 related tests pass.🤖 Generated with Claude Code