Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,20 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
continue
end
gv_to_value[LLVM.name(gv)] = C_NULL
val = initializer(gv)
if val === nothing
continue
end
while isa(val, LLVM.ConstantExpr)
if in(opcode(val), (LLVM.API.LLVMBitCast, LLVM.API.LLVMPtrToInt, LLVM.API.LLVMAddrSpaceCast, LLVM.API.LLVMIntToPtr))
val = operands(val)[1]
continue
end
break
end
if isa(val, LLVM.ConstantInt)
gv_to_value[LLVM.name(gv)] = reinterpret(Ptr{Cvoid}, convert(UInt, val))
end
end
else
@assert inits !== nothing
Expand All @@ -855,7 +869,7 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
# set the initializer
# TODO(vc): To enable full relocation we should actually strip out the initializers here.
if LLVM.isnull(initializer(gv))
val = const_inttoptr(ConstantInt(Int64(init)), LLVM.PointerType())
val = const_inttoptr(ConstantInt(Int64(init)), value_type(initializer(gv)))
initializer!(gv, val)
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/native.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ end

if VERSION >= v"1.12"
@test length(meta.gv_to_value) == 1
for (k, v) in meta.gv_to_value
@test v != C_NULL
end
end
# TODO: Global values get privatized, so we can't find them by name anymore.
# %.not = icmp eq ptr %"sym::Symbol", inttoptr (i64 140096668482288 to ptr), !dbg !38
Expand Down