I am trying to compile something that uses the llvm memcpy intrinsic. When doing so, the LLJIT can’t find the symbol “_memcpy”.
When I output the compiled code to an object file and link it using ld using the -lSystem flag, the symbol is present.
How can I link the JIT-Session similarly to the -lSystem flag in ld?
Thank you in advance,
Check out “How To Add Process And Library Symbols to JITDylibs” here.
You’ll want to use a generator to reflect the process symbols into the JIT session so that JIT’d code can link against them.
You can do that by explicitly attaching an
ExecutorProcessControl instance to your JIT following step (1) of the
auto EPC = ExitOnErr(SelfExecutorProcessControl::Create());
auto J = ExitOnErr(
Then you can create an
EPCDynamicLibrarySearchGenerator to reflect the symbols:
Now process symbols should appear in your main JITDylib on demand.
Note that if you’re on Linux and want to access symbols in the main executable you’ll also need to build with
-Wl,--export-dynamic to tell the linker to include executable symbols in the dynamic symbol table.