From 2880d21de02ec1666a6df71f637e7c60d6c72d47 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 19 May 2026 19:55:52 +0200 Subject: [PATCH] Register deferred_codegen in GlobalJD on Julia 1.14+. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JuliaLang/julia#60988 changed `JITDylib(jljit)` to return a fresh private dylib that's only searched outward (to GlobalJD/SessionJD), so defining "deferred_codegen" there is invisible to JIT-compiled user code in JD. Use `LLVM.lookup_dylib(es, "JuliaGlobals")` to grab the existing GlobalJD — which JD links to with `MatchExportedSymbolsOnly` — and define the absolute symbol there. JD's lookup chain then resolves "deferred_codegen" through GlobalJD. The pre-1.14 branch is unchanged. --- src/driver.jl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/driver.jl b/src/driver.jl index 2bdd0f57..1d68af36 100644 --- a/src/driver.jl +++ b/src/driver.jl @@ -150,12 +150,21 @@ end end end -# Register deferred_codegen as a global function so that it can be called with `ccall("extern deferred_codegen"` -# Called from __init__ -# On 1.11+ this is needed due to a Julia bug that drops the pointer when code-coverage is enabled. +# Register deferred_codegen as a global function so that it can be called with +# `ccall("extern deferred_codegen", ...)`. Called from __init__. +# +# On 1.11+ this is needed due to a Julia bug that drops the pointer when code-coverage is +# enabled. On 1.14+ (JuliaLang/julia#60988), `JITDylib(jljit)` returns a fresh private +# dylib that JD does not search; instead, register the symbol in the `JuliaGlobals` JD, +# which JD links to with `MatchExportedSymbolsOnly`. function register_deferred_codegen() @dispose jljit=JuliaOJIT() begin - jd = JITDylib(jljit) + jd = @static if VERSION >= v"1.14.0-DEV.2171" + es = ExecutionSession(jljit) + something(LLVM.lookup_dylib(es, "JuliaGlobals")) + else + JITDylib(jljit) + end address = LLVM.API.LLVMOrcJITTargetAddress( reinterpret(UInt, @cfunction(deferred_codegen, Ptr{Cvoid}, (Ptr{Cvoid},))))