@@ -786,15 +786,17 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
786786 cache_gbl = nothing
787787 end
788788
789+ gv_to_value = Dict{String, Any}()
790+ num_gvars = Ref{Csize_t}(0 )
791+ @ccall jl_get_llvm_gvs(native_code:: Ptr{Cvoid} , num_gvars:: Ptr{Csize_t} ,
792+ C_NULL :: Ptr{Cvoid} ):: Nothing
793+ gvs = Vector{Ptr{LLVM. API. LLVMOpaqueValue}}(undef, num_gvars[])
794+ @ccall jl_get_llvm_gvs(native_code:: Ptr{Cvoid} , num_gvars:: Ptr{Csize_t} ,
795+ gvs:: Ptr{LLVM.API.LLVMOpaqueValue} ):: Nothing
796+
789797 if VERSION >= v" 1.13.0-DEV.623"
790798 # Since Julia 1.13, the caller is responsible for initializing global variables that
791799 # point to global values or bindings with their address in memory.
792- num_gvars = Ref{Csize_t}(0 )
793- @ccall jl_get_llvm_gvs(native_code:: Ptr{Cvoid} , num_gvars:: Ptr{Csize_t} ,
794- C_NULL :: Ptr{Cvoid} ):: Nothing
795- gvs = Vector{Ptr{LLVM. API. LLVMOpaqueValue}}(undef, num_gvars[])
796- @ccall jl_get_llvm_gvs(native_code:: Ptr{Cvoid} , num_gvars:: Ptr{Csize_t} ,
797- gvs:: Ptr{LLVM.API.LLVMOpaqueValue} ):: Nothing
798800 inits = Vector{Ptr{Cvoid}}(undef, num_gvars[])
799801 @ccall jl_get_llvm_gv_inits(native_code:: Ptr{Cvoid} , num_gvars:: Ptr{Csize_t} ,
800802 inits:: Ptr{Cvoid} ):: Nothing
@@ -803,6 +805,16 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
803805 gv = GlobalVariable(gv_ref)
804806 val = const_inttoptr(ConstantInt(Int64(init)), LLVM. PointerType())
805807 initializer!(gv, val)
808+
809+ # TODO : jl_binding_t?
810+ gv_to_value[LLVM. name(gv)] = Base. unsafe_pointer_to_objref(val)
811+ end
812+ else
813+ for gv_ref in gvs
814+ gv = GlobalVariable(gv_ref)
815+ val = reinterpret(Ptr{Cvoid}, initializer(gv))
816+ # TODO : jl_binding_t?
817+ gv_to_value[LLVM. name(gv)] = Base. unsafe_pointer_to_objref(val)
806818 end
807819 end
808820
@@ -874,7 +886,7 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
874886 # ensure that the requested method instance was compiled
875887 @assert haskey(compiled, job. source)
876888
877- return llvm_mod, compiled
889+ return llvm_mod, compiled, gv_to_value
878890end
879891
880892# partially revert JuliaLangjulia#49391
0 commit comments