julia
4b90899c - Expose native_code's jl_sysimg_gvars. (#58423)

Commit
226 days ago
Expose native_code's jl_sysimg_gvars. (#58423) https://github.com/JuliaLang/julia/pull/57010 overhauled how global variables are initialized in code, breaking GPUCompiler.jl. After talking to @vtjnash, we are apparently supposed to use `jl_get_llvm_gvs` now to get the Julia memory location of a global variable (for a binding or constant value), however, the elements in there don't exactly correspond to the global variables in the module (not all module globals are "managed" by Julia, and the order is different). To make GPUCompiler.jl work again, here I propose renaming `jl_get_llvm_gvs` to `jl_get_llvm_gv_inits`, and making `jl_get_llvm_gvs` instead return the list of the managed global variables, making it possible to perform the global variable initialization that was done by Julia before using something like: ```julia if VERSION >= v"1.13.0-DEV.533" num_gvars = Ref{Csize_t}(0) @ccall jl_get_llvm_gvs(native_code::Ptr{Cvoid}, num_gvars::Ptr{Csize_t}, C_NULL::Ptr{Cvoid})::Nothing gvs = Vector{Ptr{LLVM.API.LLVMOpaqueValue}}(undef, num_gvars[]) @ccall jl_get_llvm_gvs(native_code::Ptr{Cvoid}, num_gvars::Ptr{Csize_t}, gvs::Ptr{LLVM.API.LLVMOpaqueValue})::Nothing inits = Vector{Ptr{Cvoid}}(undef, num_gvars[]) @ccall jl_get_llvm_gv_inits(native_code::Ptr{Cvoid}, num_gvars::Ptr{Csize_t}, inits::Ptr{Cvoid})::Nothing for (gv_ref, init) in zip(gvs, inits) gv = GlobalVariable(gv_ref) ptr = const_inttoptr(ConstantInt(Int64(init)), value_type(gv)) initializer!(gv, ptr) obj = Base.unsafe_pointer_to_objref(init) @safe_info "Resolved $(name(gv)) to $obj" end end ```
Author
Parents
Loading