Sampsa Lehtonen
2008-Jul-09 20:48 UTC
[LLVMdev] Generating machine code directly to memory
Hello, Is it possible to produce machine code directly to memory buffer so that it could be called immediately? What I would like to do is something like this: Compiler: Scripting language (Antlr) -> LLVM IR -> (Optimization) -> Raw Machine code -> (Transport media) -> Execution The idea is that I could compile my scripts directly to asm without any extra steps and in run-time. Then those asm pieces could be loaded back later without need to use Antrl/LLVM at all. I've already been able to turn script into asm files using antlr/llvm but there's an extra step to compile the asm... Is it possible to emit code directly to memory and then execute it somehow? LLVM BC with JIT is just fine, but I really would like to release my soft without LLVM at all. Thanks! - Sampsa
On Wed, 9 Jul 2008, Sampsa Lehtonen wrote:> LLVM BC with JIT is just fine, but I really would like to release my > soft without LLVM at all.It seems that this is off topic for this list then... no? -Chris -- http://nondot.org/sabre/ http://llvm.org/
On Jul 9, 2008, at 1:48 PM, Sampsa Lehtonen wrote:> Hello, > > Is it possible to produce machine code directly to memory buffer so > that > it could be called immediately? >Sampsa, The problem is that statically compiled programs (other than code that runs directly on the hardware, like firmware code) are not just a blob on binary instructions. They are wrapped in complicated linker formats (ELF, Mach-O, PE, etc.) containing metadata, dynamic linker instructions, and lots of other stuff. Hence the problem is a lot more complicated than just dumping out, say, the hex output of the JIT. --Owen
On Jul 9, 2008, at 1:48 PM, Sampsa Lehtonen wrote:> Is it possibleYes, just compile to a .s file normally, then assemble that, then you can use ld and objcopy (binutils) to convert to something approaching raw machine code.