When building with LTO, MCJIT is not linked in + segfault
Describe the Bug
When building a project using inkwell with LTO, the rust compiler seems to optimize the JIT out and attempt to use JIT fails with error message "JIT has not been linked in".
This seems to happen because rustc is able to guarantee that LLVMLinkInMCJIT is never called and does not link the whole MCJIT library due to it not being used. Due to this a global constructor registering jit as an execution engine does not run and JIT stops being available.
This is easily fixed by adding a call to inkwell::execution_engine::ExecutionEngine::link_in_mc_jit, which prevents the omission of the MCJIT library
Another unfortunate thing is that panic due to a missing JIT seems to lead to a segfault somewhere in destructors, preventing the aforementioned message from being printed. Didn't investigate any further though
To Reproduce
You can use this repo
git clone https://github.com/DCNick3/inkwell-repro
cd inkwell-repro
cargo r --release
Expected Behavior JIT is linked in and usable
Also, would be nice if the sefault didn't happen
LLVM Version (please complete the following information):
- LLVM Version: 13.0.0
- Inkwell Branch Used: master (currently at commit bff378bee02bcbb5bed35f47e9ed69e6642e9188)
Desktop (please complete the following information):
- OS: Arch Linux rolling release
Hmm yeah maybe the EE constructor would be a good place to call it?
Yeah, probably the best place. Seems that there is link_in_interpreter which has similar purpose, but for interpreter.