From 0f15ebe7ef0c9cb903c78d5fed46712a12e55f4b Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 7 May 2026 22:54:59 +0200 Subject: [PATCH 1/2] Adapt to JuliaLang/julia#60988: add JD parameter to JIT API JLJITGetExternalJITDylib is replaced by JLJITCreateJITDylib (creates a fresh JITDylib linked to GlobalJD/SessionJD), and JLJITLookup is replaced by JLJITJDLookup which takes an explicit JITDylib. The public API is made consistent across Julia versions: lookup always requires a JITDylib argument. On pre-1.13 Julia the JD is accepted but internally ignored (the old symbol-table search is used). On 1.13+ the JD is passed through to the new API. The old no-JD lookup(jljit, name) is deprecated on pre-1.13 Julia and removed on 1.13+. Co-Authored-By: Claude Sonnet 4.6 --- lib/libLLVM_julia.jl | 20 ++++++++++++++++---- src/deprecated.jl | 7 +++++++ src/orc.jl | 28 +++++++++++++++++++++------- test/jljit.jl | 30 ++++++++++++++---------------- 4 files changed, 58 insertions(+), 27 deletions(-) diff --git a/lib/libLLVM_julia.jl b/lib/libLLVM_julia.jl index 8f54e0e5..855a0805 100644 --- a/lib/libLLVM_julia.jl +++ b/lib/libLLVM_julia.jl @@ -91,8 +91,14 @@ function JLJITGetLLVMOrcExecutionSession(JIT) ccall(:JLJITGetLLVMOrcExecutionSession, LLVMOrcExecutionSessionRef, (JuliaOJITRef,), JIT) end -function JLJITGetExternalJITDylib(JIT) - ccall(:JLJITGetExternalJITDylib, LLVMOrcJITDylibRef, (JuliaOJITRef,), JIT) +@static if VERSION >= v"1.13.0-DEV.0" + function JLJITCreateJITDylib(JIT, Name) + ccall(:JLJITCreateJITDylib, LLVMOrcJITDylibRef, (JuliaOJITRef, Cstring), JIT, Name) + end +else + function JLJITGetExternalJITDylib(JIT) + ccall(:JLJITGetExternalJITDylib, LLVMOrcJITDylibRef, (JuliaOJITRef,), JIT) + end end function JLJITAddObjectFile(JIT, JD, ObjBuffer) @@ -103,8 +109,14 @@ function JLJITAddLLVMIRModule(JIT, JD, TSM) ccall(:JLJITAddLLVMIRModule, LLVMErrorRef, (JuliaOJITRef, LLVMOrcJITDylibRef, LLVMOrcThreadSafeModuleRef), JIT, JD, TSM) end -function JLJITLookup(JIT, Result, Name, ExternalJDOnly) - ccall(:JLJITLookup, LLVMErrorRef, (JuliaOJITRef, Ptr{LLVMOrcExecutorAddress}, Cstring, Cint), JIT, Result, Name, ExternalJDOnly) +@static if VERSION >= v"1.13.0-DEV.0" + function JLJITJDLookup(JIT, JD, Result, Name, ExternalJDOnly) + ccall(:JLJITJDLookup, LLVMErrorRef, (JuliaOJITRef, LLVMOrcJITDylibRef, Ptr{LLVMOrcExecutorAddress}, Cstring, Cint), JIT, JD, Result, Name, ExternalJDOnly) + end +else + function JLJITLookup(JIT, Result, Name, ExternalJDOnly) + ccall(:JLJITLookup, LLVMErrorRef, (JuliaOJITRef, Ptr{LLVMOrcExecutorAddress}, Cstring, Cint), JIT, Result, Name, ExternalJDOnly) + end end function JLJITMangleAndIntern(JIT, UnmangledName) diff --git a/src/deprecated.jl b/src/deprecated.jl index 99d19882..44e81d80 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -1,5 +1,12 @@ # deprecated methods +# lookup(jljit, name) without an explicit JD was removed in Julia 1.13 (JuliaLang/julia#60988). +# On older Julia the JD is ignored internally; on 1.13+ users must create a JD explicitly. +@static if VERSION < v"1.13.0-DEV.0" + @deprecate(lookup(jljit::JuliaOJIT, name, external_jd_only=false), + lookup(jljit, JITDylib(jljit), name, external_jd_only), false) +end + @deprecate called_value(inst::CallBase) called_operand(inst) @deprecate has_orc_v1() false false diff --git a/src/orc.jl b/src/orc.jl index 04eb6f31..2a171df5 100644 --- a/src/orc.jl +++ b/src/orc.jl @@ -391,13 +391,23 @@ function mangle(jljit::JuliaOJIT, name) end """ - JITDylib(jljit::JuliaOJIT) + JITDylib(jljit::JuliaOJIT[, name]) -Get the external JITDylib from the Julia JIT +Get or create a JITDylib from the Julia JIT. +On Julia >= 1.13 (JuliaLang/julia#60988), creates a new JITDylib with the given +name prefix, linked to GlobalJD and SessionJD. On older Julia, returns the shared +external JITDylib (name parameter is ignored). """ -function JITDylib(jljit::JuliaOJIT) - ref = API.JLJITGetExternalJITDylib(jljit) - JITDylib(ref) +@static if VERSION >= v"1.13.0-DEV.0" + function JITDylib(jljit::JuliaOJIT, name::String="") + ref = API.JLJITCreateJITDylib(jljit, name) + JITDylib(ref) + end +else + function JITDylib(jljit::JuliaOJIT, name::String="") + ref = API.JLJITGetExternalJITDylib(jljit) + JITDylib(ref) + end end function add!(jljit::JuliaOJIT, jd::JITDylib, obj::MemoryBuffer) @@ -436,9 +446,13 @@ function add!(jljit::JuliaOJIT, jd::JITDylib, tsm::ThreadSafeModule) return end -function lookup(jljit::JuliaOJIT, name, external_jd=true) +function lookup(jljit::JuliaOJIT, jd::JITDylib, name, external_jd_only=false) result = Ref{API.LLVMOrcJITTargetAddress}() - @check API.JLJITLookup(jljit, result, name, external_jd) + @static if VERSION >= v"1.13.0-DEV.0" + @check API.JLJITJDLookup(jljit, jd, result, name, external_jd_only) + else + @check API.JLJITLookup(jljit, result, name, external_jd_only) + end OrcTargetAddress(result[]) end diff --git a/test/jljit.jl b/test/jljit.jl index fdc9a2ec..7eb56df2 100644 --- a/test/jljit.jl +++ b/test/jljit.jl @@ -38,24 +38,25 @@ end @test LLVM.lookup_dylib(es, "my.so") === jd - jd_main = JITDylib(jljit) + jd_main = JITDylib(jljit, "main") prefix = LLVM.get_prefix(jljit) dg = LLVM.CreateDynamicLibrarySearchGeneratorForProcess(prefix) add!(jd_main, dg) - addr = lookup(jljit, "jl_apply_generic") + addr = lookup(jljit, jd_main, "jl_apply_generic") @test pointer(addr) != C_NULL end end @testset "Undefined Symbol" begin @dispose jljit=JuliaOJIT() begin - @test_throws LLVMException lookup(jljit, string(gensym())) + jd = JITDylib(jljit, "test") + @test_throws LLVMException lookup(jljit, jd, string(gensym())) end @dispose ts_ctx=ThreadSafeContext() jljit=JuliaOJIT() begin - jd = JITDylib(jljit) + jd = JITDylib(jljit, "test") ts_mod = ThreadSafeModule("jit") @@ -100,7 +101,7 @@ end @testset "Loading ObjectFile" begin @dispose jljit=JuliaOJIT() begin - jd = JITDylib(jljit) + jd = JITDylib(jljit, "objfile1") sym = "SomeFunction" obj = @dispose ctx=Context() mod=LLVM.Module("jit") begin @@ -120,16 +121,14 @@ end end add!(jljit, jd, MemoryBuffer(obj)) - addr = lookup(jljit, sym) - + addr = lookup(jljit, jd, sym) @test pointer(addr) != C_NULL - empty!(jd) - @test_throws LLVMException lookup(jljit, sym) + @test_throws LLVMException lookup(jljit, jd, sym) end @dispose jljit=JuliaOJIT() begin - jd = JITDylib(jljit) + jd = JITDylib(jljit, "objfile2") sym = "SomeFunction" obj = @dispose ctx=Context() mod=LLVM.Module("jit") begin @@ -167,22 +166,21 @@ end add!(jljit, jd, MemoryBuffer(obj)) - addr = lookup(jljit, sym) + addr = lookup(jljit, jd, sym) @test pointer(addr) != C_NULL - @test ccall(pointer(addr), Int32, ()) == 42 data[] = -1 @test ccall(pointer(addr), Int32, ()) == -1 + empty!(jd) + @test_throws LLVMException lookup(jljit, jd, sym) end - empty!(jd) - @test_throws LLVMException lookup(jljit, sym) end end @testset "Lazy" begin @dispose ts_ctx=ThreadSafeContext() jljit=JuliaOJIT() begin - jd = JITDylib(jljit) + jd = JITDylib(jljit, "lazy") es = ExecutionSession(jljit) lctm = LLVM.LocalLazyCallThroughManager(triple(jljit), es) @@ -202,7 +200,7 @@ end LLVM.define(jd, mu) # 2. Lookup address of entry symbol - addr = lookup(jljit, entry_sym) + addr = lookup(jljit, jd, entry_sym) @test pointer(addr) != C_NULL # 3. add MU that will call back into the compiler From 6a600d89b2ffe473eaf6bd2698baa1123be958ff Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 12 May 2026 13:37:55 +0200 Subject: [PATCH 2/2] Fix version bounds. --- lib/libLLVM_julia.jl | 4 ++-- src/deprecated.jl | 11 +++++------ src/orc.jl | 10 +++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/libLLVM_julia.jl b/lib/libLLVM_julia.jl index 855a0805..20448653 100644 --- a/lib/libLLVM_julia.jl +++ b/lib/libLLVM_julia.jl @@ -91,7 +91,7 @@ function JLJITGetLLVMOrcExecutionSession(JIT) ccall(:JLJITGetLLVMOrcExecutionSession, LLVMOrcExecutionSessionRef, (JuliaOJITRef,), JIT) end -@static if VERSION >= v"1.13.0-DEV.0" +@static if VERSION >= v"1.14.0-DEV.2171" function JLJITCreateJITDylib(JIT, Name) ccall(:JLJITCreateJITDylib, LLVMOrcJITDylibRef, (JuliaOJITRef, Cstring), JIT, Name) end @@ -109,7 +109,7 @@ function JLJITAddLLVMIRModule(JIT, JD, TSM) ccall(:JLJITAddLLVMIRModule, LLVMErrorRef, (JuliaOJITRef, LLVMOrcJITDylibRef, LLVMOrcThreadSafeModuleRef), JIT, JD, TSM) end -@static if VERSION >= v"1.13.0-DEV.0" +@static if VERSION >= v"1.14.0-DEV.2171" function JLJITJDLookup(JIT, JD, Result, Name, ExternalJDOnly) ccall(:JLJITJDLookup, LLVMErrorRef, (JuliaOJITRef, LLVMOrcJITDylibRef, Ptr{LLVMOrcExecutorAddress}, Cstring, Cint), JIT, JD, Result, Name, ExternalJDOnly) end diff --git a/src/deprecated.jl b/src/deprecated.jl index 44e81d80..5d47b151 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -1,11 +1,10 @@ # deprecated methods -# lookup(jljit, name) without an explicit JD was removed in Julia 1.13 (JuliaLang/julia#60988). -# On older Julia the JD is ignored internally; on 1.13+ users must create a JD explicitly. -@static if VERSION < v"1.13.0-DEV.0" - @deprecate(lookup(jljit::JuliaOJIT, name, external_jd_only=false), - lookup(jljit, JITDylib(jljit), name, external_jd_only), false) -end +# lookup(jljit, name) without an explicit JD was removed in Julia 1.14.0-DEV.2171 +# (JuliaLang/julia#60988). On older Julia the JD is ignored internally; on newer +# Julia users must create a JD explicitly. +@deprecate(lookup(jljit::JuliaOJIT, name, external_jd_only=false), + lookup(jljit, JITDylib(jljit), name, external_jd_only), false) @deprecate called_value(inst::CallBase) called_operand(inst) diff --git a/src/orc.jl b/src/orc.jl index 2a171df5..4df50600 100644 --- a/src/orc.jl +++ b/src/orc.jl @@ -394,11 +394,11 @@ end JITDylib(jljit::JuliaOJIT[, name]) Get or create a JITDylib from the Julia JIT. -On Julia >= 1.13 (JuliaLang/julia#60988), creates a new JITDylib with the given -name prefix, linked to GlobalJD and SessionJD. On older Julia, returns the shared -external JITDylib (name parameter is ignored). +On Julia >= 1.14.0-DEV.2171 (JuliaLang/julia#60988), creates a new JITDylib with +the given name prefix, linked to GlobalJD and SessionJD. On older Julia, returns +the shared external JITDylib (name parameter is ignored). """ -@static if VERSION >= v"1.13.0-DEV.0" +@static if VERSION >= v"1.14.0-DEV.2171" function JITDylib(jljit::JuliaOJIT, name::String="") ref = API.JLJITCreateJITDylib(jljit, name) JITDylib(ref) @@ -448,7 +448,7 @@ end function lookup(jljit::JuliaOJIT, jd::JITDylib, name, external_jd_only=false) result = Ref{API.LLVMOrcJITTargetAddress}() - @static if VERSION >= v"1.13.0-DEV.0" + @static if VERSION >= v"1.14.0-DEV.2171" @check API.JLJITJDLookup(jljit, jd, result, name, external_jd_only) else @check API.JLJITLookup(jljit, result, name, external_jd_only)