[JITLink] How to allocate correct target memory in small code model

Hi All,
In RISCV64, if the compiler compile with small code model (mcmodel=medlow)(https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#code-models), the symbol address need to at the lower 2GiB of the RISCV64 address space. However, when the jitlink allocate target memory, it will allocate to a address out of range of the lower 2GiB of the RISCV64 address space. How can I solve this problem ?

Regards,
Stephen.

Hi Stephen,

You’ll need to write a custom JITLinkMemoryManager that allocates memory in the low 2GiB for this to work.

See e.g.
https://github.com/llvm/llvm-project/blob/68d6278a6e9879794850e879a036774544b49e99/llvm/tools/llvm-jitlink/llvm-jitlink.cpp#L358
or
https://github.com/llvm/llvm-project/blob/bf281f364757d6af8d9d8456f26d334d1eeaf575/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp#L20

While it’s desirable to support all code models, it sounds like medium and compact would be more generally useful. Do you know what the default code model is for RISCV64?

– Lang.