Skip to content

Commit 29e082c

Browse files
maleadtclaude
andcommitted
Resolve CPU references lazily.
Since JuliaLang/julia#61527 (1.14.0-DEV.2614), the LowerPTLS pass may emit calls to `jl_get_pgcstack_resolved`, a symbol that only exists within the JIT and cannot be looked up using `jl_cglobal`, causing the ResolveCPUReferences pass to error on such modules (as seen on Windows CI, where the TLS getter cannot be lowered to a TP access). As this pass only rewrites loads from `jl_` bindings, and such JIT-only symbols are only ever called, resolve binding addresses lazily, i.e., only when actually replacing a load. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent a17a5b3 commit 29e082c

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/mcgen.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ function (self::ResolveCPUReferences)(mod::LLVM.Module)
3535
for f in functions(mod)
3636
fn = LLVM.name(f)
3737
if isdeclaration(f) && !LLVM.isintrinsic(f) && startswith(fn, "jl_")
38-
# eagerly resolve the address of the binding
39-
address = ccall(:jl_cglobal, Any, (Any, Any), fn, UInt)
40-
dereferenced = unsafe_load(address)
41-
dereferenced = LLVM.ConstantInt(dereferenced)
38+
# lazily resolve the address of the binding; some symbols only exist
39+
# within the JIT (e.g. `jl_get_pgcstack_resolved`) and cannot be looked up,
40+
# but such symbols are only ever called, not loaded from.
41+
dereferenced = nothing
42+
function resolve_binding()
43+
if dereferenced === nothing
44+
address = ccall(:jl_cglobal, Any, (Any, Any), fn, UInt)
45+
dereferenced = LLVM.ConstantInt(unsafe_load(address))
46+
end
47+
dereferenced
48+
end
4249

4350
function replace_bindings!(value)
4451
changed = false
@@ -49,7 +56,7 @@ function (self::ResolveCPUReferences)(mod::LLVM.Module)
4956
changed |= replace_bindings!(val)
5057
elseif isa(val, LLVM.LoadInst)
5158
# resolve
52-
replace_uses!(val, dereferenced)
59+
replace_uses!(val, resolve_binding())
5360
erase!(val)
5461
# FIXME: iterator invalidation?
5562
changed = true

0 commit comments

Comments
 (0)