construct::native::NativeCompiler
Compiles C++ source or LLVM IR to native code in-process, with the vendored LLVM.
| Declared in | src/libs/libnative/native/NativeCompiler.hpp |
| Group | native |
Detailed description
libeval's native lane, the construct editor, libfixo and libfirmware all compile through it. compile() builds C++ source into a shared library with in-process Clang and lld. compileLlvmIr() does the same for textual LLVM IR. jitLlvmIr() links LLVM IR into the running process with ORC and returns a callable entry point, with no file on disk.
It needs nothing installed. The only toolchain is the LLVM vendored into the build. A build without it gets stub methods that fail with a message, and isAvailable() returns false, so a caller can hide the feature instead of offering it.
Built libraries are cached by their source. A caller makes a NativeCompiler where it needs one; the result of jitLlvmIr() owns the linked code, and the entry point is valid only while that result lives.
See also LLVMShadeRunTask.
Member function documentation
jitLlvmIr
construct::native::JitLlvmResult NativeCompiler::jitLlvmIr(const QString &irText, const QString &symbol)
`SUP-4` — ORC links the emitted code in this process.
Parses and verifies the LLVM IR in irText, links it in memory, and looks up symbol in it. On success the result holds the address of symbol and the owner that keeps the code alive.
No object file, no `.so`, no `dlopen`. The IR is parsed and verified exactly as compileLlvmIr() does — the emitter gets the same two independent checks either way — and then handed to `LLJIT`, which compiles and links it into executable memory.
**Why in memory, stated where it will be read**: Android tightened W^X, and a JIT that must write an executable file is one tightening away from not working. `SUR-7` is the finding; this is the mechanism that answers it.
**The process symbol generator is not optional.** The emitted code calls `tanf`, `atan2f` and friends, and without a generator resolving against the host process those come back as "Symbols not found" — a message that reads like a defect in the emitter rather than a missing search path.