From eaabdf5796594be87084758fa524622db1c1dbaa Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 08:59:49 +0000 Subject: fix(driver): bind MinGW JIT runtime dependencies to host symbols Resolve the known weak __cxa_pure_virtual reference through the host ABI instead of JITLink's unsupported absolute-zero fallback. Share the host's initialized stack guard and failure handler, and map write to _write. Co-Authored-By: Claude Opus 5.5 --- tools/driver/EmbeddedRunner.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tools/driver/EmbeddedRunner.cc') diff --git a/tools/driver/EmbeddedRunner.cc b/tools/driver/EmbeddedRunner.cc index 7bfbcf0..28fe2db 100644 --- a/tools/driver/EmbeddedRunner.cc +++ b/tools/driver/EmbeddedRunner.cc @@ -31,6 +31,9 @@ // Parse all LLVM COFF declarations and helpers before introducing those macros. #include #endif +#ifdef __MINGW32__ +#include +#endif namespace { @@ -284,7 +287,7 @@ public: void emit(std::unique_ptr R, std::unique_ptr O) override { - auto Normalized = normalizeMinGWUnwindSections(std::move(O)); + auto Normalized = normalizeMinGWObject(std::move(O)); if (!Normalized) { getExecutionSession().reportError(Normalized.takeError()); R->failMaterialization(); @@ -345,6 +348,12 @@ extern "C" void __cps_jit_noop__main() {} #if defined(__MINGW32__) && defined(__x86_64__) extern "C" void ___chkstk_ms(void); #endif +#ifdef __MINGW32__ +// Use the initialized guard and failure handler from the statically linked +// host runtime rather than loading a second guard and its CRT initializer. +extern "C" uintptr_t __stack_chk_guard; +extern "C" void __stack_chk_fail(void); +#endif static llvm::Error defineRuntimeSymbols(llvm::orc::LLJIT &J) { llvm::orc::SymbolMap Symbols; @@ -370,6 +379,8 @@ static llvm::Error defineRuntimeSymbols(llvm::orc::LLJIT &J) { ExecutorSymbolDef::fromPtr(&__cxxabiv1::__cxa_guard_abort); Symbols[Intern("__cxa_throw")] = ExecutorSymbolDef::fromPtr(&__cxxabiv1::__cxa_throw); + Symbols[Intern("__cxa_pure_virtual")] = + ExecutorSymbolDef::fromPtr(&__cxxabiv1::__cxa_pure_virtual); Symbols[Intern("__cxa_begin_catch")] = ExecutorSymbolDef::fromPtr(&__cxxabiv1::__cxa_begin_catch); Symbols[Intern("__cxa_end_catch")] = @@ -396,6 +407,12 @@ static llvm::Error defineRuntimeSymbols(llvm::orc::LLJIT &J) { ExecutorSymbolDef::fromPtr(&__ms_snprintf); Symbols[Intern("strtoll")] = ExecutorSymbolDef::fromPtr(&std::strtoll); + // msvcrt.dll exports _write; MinGW archive members call its POSIX alias. + Symbols[Intern("write")] = ExecutorSymbolDef::fromPtr(&_write); + Symbols[Intern("__stack_chk_guard")] = + ExecutorSymbolDef::fromPtr(&__stack_chk_guard); + Symbols[Intern("__stack_chk_fail")] = + ExecutorSymbolDef::fromPtr(&__stack_chk_fail); #endif #ifdef _WIN32 // Generated diagnostics write to stderr through __acrt_iob_func(2). The -- cgit v1.3.1-4-g156e