@@ -698,6 +698,26 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
698698 cache_gbl = nothing
699699 end
700700
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+ locations = Vector {Ptr{Cvoid}} (undef, num_gvars[])
711+ @ccall jl_get_llvm_gv_locations (native_code:: Ptr{Cvoid} , num_gvars:: Ptr{Csize_t} ,
712+ locations:: Ptr{Cvoid} ):: Nothing
713+
714+ for (gv_ref, location) in zip (gvs, locations)
715+ gv = GlobalVariable (gv_ref)
716+ val = const_inttoptr (ConstantInt (Int64 (location)), value_type (gv))
717+ initializer! (gv, val)
718+ end
719+ end
720+
701721 if VERSION >= v " 1.12.0-DEV.1703"
702722 # on sufficiently recent versions of Julia, we can query the MIs compiled.
703723 # this is required after the move to `invokce(::CodeInstance)`, because our
0 commit comments