Hi there,
I am testing my luck to port julia to riscv64. I know this is not a supported platform, but I can almost get a sysimage with a bit dirty hacks, except that I get stuck in bootstrapping SuiteSparse/src/cholmod.jl with the following awkward relocation range issue.
...
LinearAlgebra ──── 99.693033 seconds
Markdown ───────── 11.953065 seconds
Printf ─────────── 1.165579 seconds
Random ─────────── 5.017103 seconds Tar ────────────── 2.277063 seconds
Dates ──────────── 24.510604 seconds
Distributed ────── 9.259273 seconds
Future ─────────── 0.034906 seconds
InteractiveUtils ─ 5.119594 seconds
LibGit2 ────────── 11.526592 seconds
Profile ────────── 3.791027 seconds SparseArrays ───── 23.531039 seconds
UUIDs ──────────── 0.101738 seconds
REPL ───────────── 38.194260 seconds
SharedArrays ───── 4.289493 seconds
Statistics ─────── 1.150079 seconds
JIT session error: In graph globals-jitted-objectbuffer, section .text: relocation target "jl_RTLD_DEFAULT_handle" at
address 0x4001bfa918 is out of range of R_RISCV_PCREL_HI20 fixup at 0x423718e03c (jlplt_ijl_alloc_array_1d_16507, 0x
423718e000 + 0x3c)
Failure value returned from cantFail wrapped call
Failed to materialize symbols: { (JuliaOJIT, { ccall_ijl_alloc_array_1d_16506, jlplt_ijl_alloc_array_1d_16507_got, jl
plt_ijl_alloc_array_1d_16507 }) }
UNREACHABLE executed at /usr/lib/llvm/14/include/llvm/Support/Error.h:786!
As this arch is relatively new, the old llvm RuntimeDylib api doesn’t support it and there is currently no large codemodel in riscv spec. Good thing is JITLink has full support for riscv so I switched to JITLink with CodeModel=Medium (same as small codemodel in arm64).
Similar to arm64, riscv is a RISC machine with fixed 4 byte sized instruction (ignore c extension). The R_RISCV_PCREL_HI20
and R_RISCV_PCREL_LO12
relocation pair enables the machine to load a symbol with ±2GB offset relative to current PC and usually used in auipc + ld/addi instruction. This should be analogous to adrp + ldr in arm64, which I recall has ±4GB range (I might be wrong, not an arm expert).
Now, looking at the JIT error, the offset is 423718e000-0x4001bfa918=0x2355936E8
, which is well beyond the valid range for riscv and arm64 as well. I wonder does similar issue happen in arm64 previously and Is there possible way to get around with this? I also noticed only on macOS ARM64, jitlink with small codemodel (medium/medany in riscv sense) is used.
I am still a beginner exploring the llvm and julia world. Hope I can get some hints and insights from experts here.