greenboxal
greenboxal

Reputation: 469

Generating pure machine code with LLVM

Is there a way to generate "pure" machine code from a Module with LLVM?

I mean, I have a Module and want to get only the x86 opcodes without any MachO or Darwin object headers, just the opcodes(and if possible, get them relocated to a certain base address).

Upvotes: 3

Views: 410

Answers (2)

A. K.
A. K.

Reputation: 38270

I think you are looking for objdump. use objdump -d your_executable > dump_file

Upvotes: 1

servn
servn

Reputation: 3069

The "standard" way to do something like that is to build an executable, and then extract out the raw bits as appropriate. Something like http://www.bravegnu.org/gnu-eprog/hello-arm.html .

An alternative is to use the LLVM JIT APIs; I don't there's any good documentation or example code which shows how to use LLVM this way, though. Maybe take a look at how ClangExpressionParser::PrepareForExecution in lldb works ( http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?revision=161559&view=markup ).

Upvotes: 0

Related Questions