Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to translate an assembly language to LLVM IR, optimize it and then recompile it to a different architecture?

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

like image 510
Francesco Boffa Avatar asked Nov 27 '11 19:11

Francesco Boffa


3 Answers

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.

like image 182
Richard Pennington Avatar answered Oct 01 '22 20:10

Richard Pennington


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.

like image 26
shining Avatar answered Oct 01 '22 19:10

shining


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.

like image 37
op325 Avatar answered Oct 01 '22 19:10

op325