MCJIT fully position independent code, and the runtime linker


I wanted to know why is there a need for a runtime linker if LLVM can produce fully relocatable code?

That is, if I ask MCJIT to generate code that uses PC-rel offsets for everything, why would I need a runtime linker at all?

Is it for name resolution or something I don’t get?

To me the JIT seems like an API that can produce assembly that I should be able to load where-ever I feel like. Only think I can think of is that if I encounter a call instruction I better have an address to give it to. But other than that …

What is preventing this from happening? I’m sure it’s my limited understanding of the linker space, but I would love to understand.


Hi Dave,

MCJIT uses the MC layer to produce a relocatable object file for JIT’d LLVM IR. Even if you use PIC and have fully resolved all external references at the IR level this object file may still contain relocations for internal symbols which the runtime linker must resolve.

Some clients also like having the runtime linker resolve external symbols because it allows them to cache JIT’d object files are re-use them in subsequent JIT sessions.