From 64f3476a28802b65ed6edb087f7cc8671197051c Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Tue, 20 Jan 2026 00:50:02 -0500 Subject: [PATCH 1/5] Fix typed pointer gv initialization --- src/jlgen.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jlgen.jl b/src/jlgen.jl index 7c373092..2403cf51 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -855,7 +855,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 From 5246e46f8be3f7feccd193891973d213445abd2f Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Tue, 20 Jan 2026 01:36:52 -0500 Subject: [PATCH 2/5] Also actually do a best effort initialization --- src/jlgen.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/jlgen.jl b/src/jlgen.jl index 2403cf51..a3b70d8f 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -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 From 6c30d7cb4af181dfbb78b47b158f657fd5ac36df Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Tue, 20 Jan 2026 06:41:47 -0600 Subject: [PATCH 3/5] fix --- test/native.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/native.jl b/test/native.jl index a336908a..0449fe0b 100644 --- a/test/native.jl +++ b/test/native.jl @@ -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 From 37b655b2771055de1118b4d3c0ac4e2164bd3baa Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Tue, 20 Jan 2026 06:42:52 -0600 Subject: [PATCH 4/5] fmt --- test/native.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/native.jl b/test/native.jl index 0449fe0b..320bbacf 100644 --- a/test/native.jl +++ b/test/native.jl @@ -59,9 +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 + 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 From 75c5ee3f09ead54a02fe13c5df56a2efd472d5ce Mon Sep 17 00:00:00 2001 From: William Moses Date: Tue, 20 Jan 2026 11:13:27 -0500 Subject: [PATCH 5/5] Change condition to check for LLVM.ConstantInt --- src/jlgen.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jlgen.jl b/src/jlgen.jl index a3b70d8f..ef61dbbd 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -857,7 +857,7 @@ function compile_method_instance(@nospecialize(job::CompilerJob)) end break end - if !isa(val, LLVM.ConstantInt) + if isa(val, LLVM.ConstantInt) gv_to_value[LLVM.name(gv)] = reinterpret(Ptr{Cvoid}, convert(UInt, val)) end end