Skip to content

Commit f8d91d7

Browse files
committed
1 parent 2052153 commit f8d91d7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/jlgen.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
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+
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

Comments
 (0)