Skip to content

Define the stdio family for JIT'd code on Windows - #326

Merged
tamnd merged 1 commit into
mainfrom
coff-jit-stdio
Sep 9, 2026
Merged

tamnd merged 1 commit into
mainfrom
coff-jit-stdio

Conversation

@tamnd

@tamnd tamnd commented Sep 9, 2026

Copy link
Copy Markdown
Owner

Fixes #325.

A Mojo program that formats a float stopped with JIT session error: Symbols not found: [ snprintf ]. There is no snprintf on a Windows machine to find. The UCRT headers declare it inline over __stdio_common_vsprintf, so every program gets its own copy while it is being compiled and ucrtbase.dll exports nothing by that name. JIT'd code never had that moment, so it emits a plain call and there is nothing to bind it to. Nine names in the printf and scanf family are in that state.

Six more do resolve, but through ntdll, which carries its own copies from the old NT C runtime. Those are not the UCRT functions, they differ in floating point conversion, and ntdll's swprintf does not even take a buffer size. That half was the worse one, because nothing about it looked broken.

So this defines all fifteen as absolute symbols in the platform stdlib, pointing at the copies already linked into mojo.exe, which links the UCRT statically. Defining them settles both halves at once, since a generator is only ever asked about a name the dylib does not already have.

The two wide ones need a cast because the UCRT headers give them a C++ template overload that deduces an array size, so the bare name is an overload set rather than one address.

Cross built and run on a Windows host, on a program that exercises List, Dict, string building, range, try and float formatting:

sum of squares: 285
word: alpha bytes: 5
word: beta bytes: 4
word: gamma bytes: 5
dict two: 2
built: 012
boom(2): 4
caught: too big
pow: 1024.0
RUN_RC=0

The last line of that is snprintf doing its job. Before this change the same program did not get past symbol resolution.

Part of #31.

@tamnd tamnd added this to the M6 Tier 2 and native hosting milestone Sep 9, 2026
@tamnd tamnd added area/runtime AsyncRT, allocator, crash handling type/bug Something is broken priority/p1 Important. Needed for the milestone labels Sep 9, 2026
A Mojo program that formats a float failed with "Symbols not found: [ snprintf ]". There is no snprintf on a Windows machine to find. The UCRT headers declare it inline over __stdio_common_vsprintf, so every program gets its own copy while it is being compiled and ucrtbase.dll exports nothing by that name. JIT'd code never had that moment, so it emits a plain call and there is nothing to bind it to. Nine names in the printf and scanf family are like this.

Six more resolve, but through ntdll, which carries its own copies from the old NT C runtime. Those are not the UCRT functions, they differ in floating point conversion, and swprintf does not even take a buffer size there. That half was the worse one, because it went unnoticed.

This defines all fifteen as absolute symbols in the platform stdlib, pointing at the copies already linked into mojo.exe, which links the UCRT statically. Defining them settles both halves at once, since a generator is only ever asked about a name the dylib does not already have.
@tamnd
tamnd merged commit 3d57d3e into main Sep 9, 2026
7 checks passed
@tamnd
tamnd deleted the coff-jit-stdio branch September 9, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/runtime AsyncRT, allocator, crash handling priority/p1 Important. Needed for the milestone type/bug Something is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT'd code cannot find snprintf, and finds the wrong sprintf

1 participant