Skip to content

A library tslang built no longer exports the heap entry points - #784

Merged
ASDAlexander77 merged 1 commit into
mainfrom
dll-heap-exports
Nov 8, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
dll-heap-exports

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Since #779, ProcessHeapExports.inc exported __tslang_heap_malloc, calloc, realloc, free and aligned_alloc from every module that links the async runtime, libraries included. A library's exports end up in its import library, so a DLL that links the default library's DLL (which comes first on the link line) took the five from TypeScriptDefaultLib.lib. It then pulled in ProcessHeap.obj for -include:__tslang_heap_shared and had each one twice:

TypeScriptAsyncRuntime.lib(ProcessHeap.obj) : error LNK2005: __tslang_heap_free already defined in TypeScriptDefaultLib.lib(TypeScriptDefaultLib.dll)

Any --emit=dll build that allocates failed this way once the default library had been rebuilt after #779.

Fix

The five functions are no longer exported; the __tslang_heap_shared marker still is. Nothing depends on the exports:

  • A library only ever looks the heap functions up in the executable (GetProcAddress on the program's module).
  • The two executables that lend their heap define and export their own copies: TypeScriptMimalloc in an executable, and tslang.exe under the JIT.
  • The copies in this file are the Windows process heap, which a library falls back to anyway when the executable exports none.

Testing

  • test-compile-shared-defaultlib-data covers this bug, but only once the default library has been rebuilt after A library tslang built allocates from the program's heap; mimalloc on Linux #779; with an older build it passes without the fix. Against a rebuilt default library it fails with LNK2005 on the old compiler and passes with this change.
  • A one-line rc DLL using new RegExp against the default library now links. The rebuilt default library's DLL exports only __tslang_heap_shared.
  • test-compile-mimalloc-heap and the shared-import, default-library and JIT-native tests pass.
  • Full suite: 6,684 of 6,686 pass. test-own-facts-objects and test-own-keepers-objects failed in the parallel run and passed when rerun alone. They check ownership facts at compile time and don't touch the heap code.

Every default-library build needs a rebuild for its import library to drop the five exports.

🤖 Generated with Claude Code

Since #779 ProcessHeapExports.inc exported __tslang_heap_malloc, calloc,
realloc, free and aligned_alloc from every module that links the async
runtime, libraries included. A library's exports become its import
library's, so a DLL linking the default library's DLL - which comes first
on the link line - took the five from TypeScriptDefaultLib.lib, then
pulled ProcessHeap.obj in for -include:__tslang_heap_shared and had each
twice:

  TypeScriptAsyncRuntime.lib(ProcessHeap.obj) : error LNK2005:
  __tslang_heap_free already defined in
  TypeScriptDefaultLib.lib(TypeScriptDefaultLib.dll)

Any --emit=dll that allocates against a default library rebuilt since
#779 failed this way; test-compile-shared-defaultlib-data shows it once
that library is built.

Only the program's entry points are ever looked up (GetProcAddress on the
executable), and the ones that lend a heap - TypeScriptMimalloc's and
tslang.exe's under the JIT - are defined and exported apart. These are the
process heap, which a library falls back to when the program exports
none, so exporting them added nothing. The marker __tslang_heap_shared
stays exported.

The default library has to be rebuilt for its import library to lose the
five.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit f7a4ea2 into main Nov 8, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the dll-heap-exports branch November 8, 2026 15:49
ASDAlexander77 added a commit that referenced this pull request Nov 8, 2026
…ANG 34-36) (#790)

34: LLVM's UTF-16 to UTF-8 conversion takes a leading U+FEFF for a byte order
mark and skips it (and byte-swaps a string starting with U+FFFE), so a string
literal starting with that character lost it. Literals are converted as they
are.

35 ("\\n" read as a line feed) does not reproduce; the new test covers it.

36: a runtime library older than #784 failed every --emit=dll with a bare
LNK2001 for __tslang_heap_shared. tslang checks TypeScriptAsyncRuntime.lib
first and says the runtime is older than the compiler. -v is an alias for
--verbose, so the linker's "use -v" hint works.

Also records the open -mm=own items 31-33 in TSLANG_ISSUES.md.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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