Skip to content

Linux --emit=exe: read the default library's facts from the archive its ld script names - #748

Merged
ASDAlexander77 merged 1 commit into
mainfrom
linux-own-defaultlib-facts
Oct 30, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
linux-own-defaultlib-facts

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Why

The v0.0-pre-alpha111 release run (40988118886) failed on every Linux job in "Test Default Library". The failures were in DefaultLib's tests under -mm=own, compile pass only: 135/182 compiled, in both release and debug. The JIT pass and Windows passed. The errors came from inside lib.generics.ts, for example:

lib.generics.ts:662:16: error: 'this value' borrows a field but is used here after it may be released or overwritten

Cause

On Linux, libTypeScriptDefaultLib.a is a GNU ld script, INPUT(-lTypeScriptDefaultLibCore -lcurl) (DefaultLib's build.sh). Under --emit=exe, readOwnFacts and readBorrowFacts read the default library's facts from that file. It isn't an archive, so they found no facts. Without facts, own must assume any call into the library can destroy anything. The JIT reads the shared library instead, which is why its pass was clean.

Fix

staticDefaultLibFactsFile (tslang/tslang/borrowfacts.cpp) handles a default library that is not a link input itself. It reads the facts from the archive of the first -l that the script's INPUT(...) names, if that archive sits next to the script. Any other file is read as before. Linking is unchanged: exe.cpp still links the script and searches its folder, so the archive the facts come from is the archive that gets linked.

Testing

  • WSL Ubuntu, same steps as the release job. Built tslang, then DefaultLib's own build (release and debug), then ran tests.sh own. All four passes (release and debug, compiled and JIT) gave 171/182, with the usual 11 not-own skips.
  • WSL A/B. array_class_shared.ts with --emit=exe -mm=own gives 1 error without the fix and 0 with it.
  • Windows. Leaving the own facts out reproduces the same lib.generics.ts:662:16 error. That probe was temporary and has been reverted.
  • Windows ctest (Release). 6420/6420 passed.

🤖 Generated with Claude Code

…ts ld script names

The v0.0-pre-alpha111 release run failed on every Linux job: DefaultLib's tests under -mm=own,
compile pass only (release and debug 135/182; the JIT and Windows passed), with errors inside
lib.generics.ts - "'this value' borrows a field but is used here after it may be released or
overwritten", "'this value' borrows 'this._entries' ...".

On Linux libTypeScriptDefaultLib.a is a GNU ld script, `INPUT(-lTypeScriptDefaultLibCore -lcurl)`
(the default library's build.sh). readOwnFacts and readBorrowFacts read the facts of the static
library an --emit=exe program links from that file: not an archive, so none. Under own every call
into the library could then destroy anything. The JIT reads the shared library, which is why it
passed. Windows reproduces the errors with the own facts left out.

staticDefaultLibFactsFile: for a file that is not a link input, the archive of the first `-l` its
INPUT(...) names that sits beside it; anything else is itself. The link is unchanged - the script,
its folder searched (exe.cpp) - so the archive read is the archive linked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit b657c48 into main Oct 30, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the linux-own-defaultlib-facts branch October 30, 2026 04:25
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