@@ -698,6 +698,26 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
698
698
cache_gbl = nothing
699
699
end
700
700
701
+ if VERSION >= v " 1.13.0-DEV.623"
702
+ # Since Julia 1.13, the caller is responsible for initializing global variables that
703
+ # point to global values or bindings with their address in memory.
704
+ num_gvars = Ref {Csize_t} (0 )
705
+ @ccall jl_get_llvm_gvs (native_code:: Ptr{Cvoid} , num_gvars:: Ptr{Csize_t} ,
706
+ C_NULL :: Ptr{Cvoid} ):: Nothing
707
+ gvs = Vector {Ptr{LLVM.API.LLVMOpaqueValue}} (undef, num_gvars[])
708
+ @ccall jl_get_llvm_gvs (native_code:: Ptr{Cvoid} , num_gvars:: Ptr{Csize_t} ,
709
+ gvs:: Ptr{LLVM.API.LLVMOpaqueValue} ):: Nothing
710
+ inits = Vector {Ptr{Cvoid}} (undef, num_gvars[])
711
+ @ccall jl_get_llvm_gv_inits (native_code:: Ptr{Cvoid} , num_gvars:: Ptr{Csize_t} ,
712
+ inits:: Ptr{Cvoid} ):: Nothing
713
+
714
+ for (gv_ref, init) in zip (gvs, inits)
715
+ gv = GlobalVariable (gv_ref)
716
+ val = const_inttoptr (ConstantInt (Int64 (init)), value_type (gv))
717
+ initializer! (gv, val)
718
+ end
719
+ end
720
+
701
721
if VERSION >= v " 1.12.0-DEV.1703"
702
722
# on sufficiently recent versions of Julia, we can query the MIs compiled.
703
723
# this is required after the move to `invokce(::CodeInstance)`, because our
0 commit comments