Repository navigation
An async program links without the collector under rc, none and own - #419
Merged
Merged
Conversation
Every program that awaits anything, built ahead of time under rc, none or own, failed to link: TypeScriptAsyncRuntime.lib(AsyncRuntime.obj) : error LNK2019: unresolved external symbol GC_allow_register_threads referenced in function GC_enable_threads (and GC_register_my_thread, GC_unregister_my_thread, GC_get_stack_base) The async runtime registers its pool threads with the collector under gc (AsyncGCThreads.h, from #308). At run time that is inert under the other models - it only switches on through GC_enable_threads, which only the GC pass injects - but it sat in the scheduler's own object file, which every async program links, and only gc programs link gc.lib. `none` linked before #308. GC_enable_threads and the collector calls move to an object file of their own (AsyncGCThreadsCommon.inc, built as AsyncGCThreads.cpp in both TypeScriptAsyncRuntime and TypeScriptRuntime). The scheduler reaches them through two hooks that GC_enable_threads installs, so only the call in a gc program pulls that object in. The scheduler no longer includes gc.h. test-runner links every model with lld and gc.lib itself, which is why the rc and none corpus runs of 00async_await.ts passed. New test-compile-async-without-collector (async-without-collector.cmake) builds 00async_await.ts with `tslang --emit=exe` under rc, none and own, with no GC_LIB_PATH, and runs it. DefaultLib's sleep.ts, which failed the same way under rc, links and runs. 00async_gc_threading.ts under gc (the fault the registration fixed, about 6 runs in 10 at -O0 without it): 0 of 20 failures at -O0 and at -O3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Sep 30, 2026
#419's split of the async runtime applies to the static library on Linux as well, and before it the failure was the same there: checked in WSL at #418, the scheduler's object (AsyncRuntime.cpp.o) referenced GC_allow_register_threads, GC_register_my_thread, GC_unregister_my_thread and GC_get_stack_base, and 00async_await.ts built with `tslang --emit=exe` under rc, none and own failed to link ("undefined reference to `GC_register_my_thread'"). At main only AsyncGCThreads.cpp.o references them, and all four models link and run at -O0 and -O3. The test was registered for Windows only; async-without-collector.cmake passes as is on Linux, so the guard goes. Its comments name both platforms' messages and linkers. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 5, 2026
ASDAlexander77
added a commit
that referenced
this pull request
Oct 7, 2026
Since #419 an async program links without the collector, so the exact-output await_order case now runs under -mm=rc, -mm=none and -mm=own as well as gc. The comments that said rc/none fail to link are updated. 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.
Summary
Built ahead of time under
-mm=rc,noneorown, any program that awaits anything failed to link. The first failure seen was DefaultLib'ssleep.tsunder rc:GC_register_my_thread,GC_unregister_my_threadandGC_get_stack_basewere missing too.Why the collector's functions were in an rc build
gc(AsyncGCThreads.h). Without that, Boehm's allocator runs unlocked across threads, and a long chain of awaits faulted.GC_enable_threads, and only the GC pass injects that call.gcprograms linkgc.lib. So the linker needed the collector's thread functions in programs that don't have a collector.nonelinked before Reference counting memory model (-mm=rc) and related codegen/runtime fixes #308.TypeScriptRuntime.dllhas the collector built in.Fix
GC_enable_threadsand the collector calls move to an object file of their own,AsyncGCThreadsCommon.inc. It's built asAsyncGCThreads.cppin bothTypeScriptAsyncRuntimeandTypeScriptRuntime.GC_enable_threadsinstalls. Only the call in agcprogram pulls the object in.gc.h.The archive now shows the split:
AsyncRuntime.objreferences noGC_*function, and onlyAsyncGCThreads.objdoes.Tests
test-runnerlinks every model withlldandgc.libitself. That's why the rc and none corpus runs of00async_await.tspassed.The new
test-compile-async-without-collector(async-without-collector.cmake, Windows) builds00async_await.tswithtslang --emit=exeunder rc, none and own, withGC_LIB_PATHcleared, and runs it.Results
00async_await.ts,tslang --emit=exe, gc/rc/none/own at -O0 and -O3sleep.ts, rc / none / gc00async_gc_threading.tsunder gc, 20 runs at -O0 and at -O3Not in this PR
weakref_basicunder rc: DefaultLib'sWeakRefcalls Boehm's weak-link API directly, and the test callsGC_gcollect()itself. That's a DefaultLib change, and an rc design question (rc document §9.8).🤖 Generated with Claude Code