Is it possible to translate an assembly language to LLVM IR, optimize it and then recompile it to a different architecture? How would you handle "push"es and "pop"s on the stack in the IR? This is the simplest objection I found, but I'm sure that there're tons like this.
I'm planning to build a dynamic recompiler, and it seems that this would be an excellent solution, since LLVM would automatically optimize my code for the new architecture. Is all this possible with LLVM?
Thanks
This is a similar question: Recompile a x86 code with LLVM to some faster one x86
The answer is that LLVM can't do it directly, but could be used as part of a tool that does.
It is possible.
But you need to develop some code base the LLVM to implement the process translating the assembly language to LLVM IR. Then the LLVM can help you to optimize and generator for new architecture.
So, the point is you need to develop the translator which can translate the assembly language to LLVM IR. I have seen someone already do that, you can search on the website.
You could try to create a symbolic representation of the program you want to optimize and then use a tool such as Arybo in order to convert the symbolic expressions into LLVM IR.
Jonathan Salwan does this in his repo Tigress_Protection where he demonstrates how to deobfuscate virtual machines using symbolic execution and taint analysis using his tool Triton in order to get a symbolic representation of the program and with Arybo, he converts the symbolic expressions into LLVM IR in order to apply some optimizations. I suppose this is one way to do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With