3 ms·
> This seems like a related question: what is the high-level process for building a JIT compiler? Specifically, where does the output of the compiler actually g
by woodruffw 5y ago
> This seems like a related question: what is the high-level process for building a JIT compiler? Specifically, where does the output of the compiler actually get stored, how does it get marked as executable, and how does it get "fed" into program execution?
There are a whole bunch of ways to do this, but a common one is to map a region as writable, build your JITted machine code into it, flip write and execute, and point your program counter at it. Typically the part that does the last part also sets up the return handling for when the JITted segment is finished.
If you're JITting entire functions at a time, you could instead use the dynamic symbol functionality that most OSes provide: build up your machine code (or other representation), convert it into an object file, load it in, and grab the function by its name.