Commit 4b90899
authored
Expose native_code's jl_sysimg_gvars. (#58423)
#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
```1 parent c940a31 commit 4b90899
File tree
5 files changed
+28
-8
lines changed- src
5 files changed
+28
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
114 | | - | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
124 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
125 | 142 | | |
126 | 143 | | |
127 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
| 517 | + | |
517 | 518 | | |
518 | 519 | | |
519 | 520 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2043 | 2043 | | |
2044 | 2044 | | |
2045 | 2045 | | |
| 2046 | + | |
2046 | 2047 | | |
2047 | | - | |
| 2048 | + | |
2048 | 2049 | | |
2049 | 2050 | | |
2050 | 2051 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3055 | 3055 | | |
3056 | 3056 | | |
3057 | 3057 | | |
3058 | | - | |
| 3058 | + | |
3059 | 3059 | | |
3060 | | - | |
| 3060 | + | |
3061 | 3061 | | |
3062 | 3062 | | |
3063 | 3063 | | |
| |||
0 commit comments