From 3a41f891c1b86bd22e1ded00d96c8889a18c8089 Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Sun, 8 Nov 2026 15:21:56 +0000 Subject: [PATCH] A library tslang built no longer exports the heap entry points 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 --- tslang/lib/ProcessHeapExports.inc | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tslang/lib/ProcessHeapExports.inc b/tslang/lib/ProcessHeapExports.inc index b00f43cdc..5843a0983 100644 --- a/tslang/lib/ProcessHeapExports.inc +++ b/tslang/lib/ProcessHeapExports.inc @@ -5,11 +5,17 @@ // // The program owns the heap. In the program's own module these are the process heap; an executable // that links TypeScriptMimalloc gets that library's definitions instead (mimalloc), and tslang.exe -// gives a program it runs its own (jit.cpp). Every one of them is exported, so a library - a -// module other than the process's executable - looks them up there at its first allocation and -// calls the program's: the library's blocks and the program's come from one heap, whichever it is. -// A program that exports none (a host tslang did not build, or one built before this) leaves a -// library on the process heap, which is what such a program allocates from too. +// gives a program it runs its own (jit.cpp). Those two export theirs, so a library - a module other +// than the process's executable - looks them up there at its first allocation and calls the +// program's: the library's blocks and the program's come from one heap, whichever it is. A program +// that exports none (one on the process heap, a host tslang did not build) leaves a library on the +// process heap, which is what such a program allocates from too. +// +// These are not exported. Only the program's are ever looked up, and these would add nothing there: +// they are the process heap, which a library falls back to anyway. Exported from a library they did +// harm: its import library defines them, and a DLL linking it - the default library's, say - took +// the five from there, then pulled this file in for `__tslang_heap_shared` and had each twice +// (LNK2005). // // `__tslang_heap_shared` says a module does this, so that a program on mimalloc can refuse a library // that would keep a heap of its own (ProcessHeap.h, librarySharesHeap). @@ -116,31 +122,31 @@ void ensureHeap() } // namespace -extern "C" __declspec(dllexport) void *__tslang_heap_malloc(size_t size) +extern "C" void *__tslang_heap_malloc(size_t size) { ensureHeap(); return heapMalloc.load(std::memory_order_relaxed)(size); } -extern "C" __declspec(dllexport) void *__tslang_heap_calloc(size_t count, size_t size) +extern "C" void *__tslang_heap_calloc(size_t count, size_t size) { ensureHeap(); return heapCalloc.load(std::memory_order_relaxed)(count, size); } -extern "C" __declspec(dllexport) void *__tslang_heap_realloc(void *ptr, size_t size) +extern "C" void *__tslang_heap_realloc(void *ptr, size_t size) { ensureHeap(); return heapRealloc.load(std::memory_order_relaxed)(ptr, size); } -extern "C" __declspec(dllexport) void __tslang_heap_free(void *ptr) +extern "C" void __tslang_heap_free(void *ptr) { ensureHeap(); heapFree.load(std::memory_order_relaxed)(ptr); } -extern "C" __declspec(dllexport) void *__tslang_heap_aligned_alloc(size_t alignment, size_t size) +extern "C" void *__tslang_heap_aligned_alloc(size_t alignment, size_t size) { ensureHeap(); return heapAlignedAlloc.load(std::memory_order_relaxed)(alignment, size);