Skip to content

--jit-native: say why it still links the static default library - #631

Merged
ASDAlexander77 merged 1 commit into
mainfrom
jit-native-shared-defaultlib
Oct 20, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
jit-native-shared-defaultlib

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

What

This changes a comment and a doc only, with no code change. The request.staticDefaultLib = true comment in tslang/tslang/jitnative.cpp and the "As built" section of tslang/docs/jit-native-dll-debugging-design.md said --jit-native links the static default library because of "the same failure as --emit=dll", and called that a separate bug. #630 fixed that --emit=dll failure, so this PR states the actual reason the static default library is still needed.

Why the #630 fix doesn't apply to --jit-native

The --jit-native DLL links the JIT cache's objects, and those objects are compiled with the JIT's target machine. JITTargetMachineBuilder::detectHost leaves the code model at its default. On x86-64 that default is the large code model with a static relocation model. Under that combination X86Subtarget::classifyGlobalReference returns MO_NO_FLAG before it ever looks at dllimport, so a dllimport global gets no __imp_ reference.

I checked this on main with the Map / Math.PI / Number.EPSILON / instanceof RangeError repro:

  • Without staticDefaultLib: the DLL link fails with LNK2019 on PrimeHelpers.hashCollisionThreshold, Math.PI, Number.EPSILON and RangeError..rtti.
  • Also marking the default library's data import for JIT objects (A shared library reads the default library's data through its DLL #630's gate widened to isJit): ExportFixPass does set those globals to dllimport (section=import, MSVC triple). The in-memory JIT still runs correctly. But the cached object still has U Math.PI and no __imp_ symbols, and the link fails the same way.

So linking the static default library is still the right choice for --jit-native. Making the DLL import its data would need the JIT objects compiled with a different code model, which also changes the in-memory JIT.

🤖 Generated with Claude Code

#630 made --emit=dll read the default library's data through `__imp_`,
but that does not carry over to --jit-native. Its DLL links the JIT
cache's objects, which are compiled for the JIT's static large code model,
and x86 codegen gives a dllimport global no `__imp_` reference under that
model (X86Subtarget::classifyGlobalReference). Checked: with the data
marked dllimport for JIT objects too, the in-memory JIT still runs, but
the objects keep plain `Math.PI` references and the DLL link fails without
the static default library. The comment and the design doc said this was
the same bug as --emit=dll; they now give the actual reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 3a89f7e into main Oct 20, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the jit-native-shared-defaultlib branch October 20, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant