<div dir="ltr">PANDA (if that's what you're talking about) Is really heavy weight and to be honest it's really hard to write optimizations in a reverse engineering context. Optimizations almost always come after the code is fully working, so while it succeeded for what it strove in that respect, dynamically lifting is hard.<div><div><br></div><div>Also, if you're talking about dynamically lifting to IR and emulating over the instruction semantics *just* to provide alternative platform support but want speed, it might be best to consider the idea of using a cross compiler for each target since you have the dosbox code. Emulating is always going to be an order of magnitude slower because you have to work at smaller step semantics. Running Dosbox in QEMU sounds like an option if you want to get off the ground really fast but can't compile & run Dosbox to an alternative target.</div><div><br></div><div>Also, if you didn't know it, LLVM's JIT works at the function level, but the problem in your context is that it does it lazily, which is going to impose latency (understandably) on the first hit, but the JIT can't possibly determine the end of a function because of the undecideability of disassembly. Compilers often place function definitions contiguous to one another and any one function can have multiple returns. The JIT would probably operate over a limited subset of the actual function definition, and forcibly impose multiple reinterpretation.</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 22, 2015 at 9:03 AM, Jacek Wielemborek <span dir="ltr"><<a href="mailto:d33tah@gmail.com" target="_blank">d33tah@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
(First of all, I'd like to point out that I am a newbie in this topic<br>
<span class="">and this is more of a "would it work?" kind of question. I basically<br>
</span>just came up with a difficult problem and decided to research on it.)<br>
<div class="HOEnZb"><div class="h5"><br>
I recently tried to run Elder Scrolls: Daggerfall on an ARM netbook<br>
Toshiba AC100 and failed even after turning on the latest patches for<br>
"dynamic recompilation". I took a look at the code and here's what I found:<br>
<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_wjp_dosbox_blob_idados_src_cpu_core-5Fdynrec_decoder.h-23L34&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=f1niO7ol20SzppTZaiU2b_qqD5nCY4LU6TRcP_U0QUE&s=DcXm_tFzji6h2xivJovkwaJm5aQ4nqYiLzBW9hMjgKo&e=" rel="noreferrer" target="_blank">https://github.com/wjp/dosbox/blob/idados/src/cpu/core_dynrec/decoder.h#L34</a><br>
<br>
The relevant macros and functions are defined there:<br>
<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_wjp_dosbox_blob_idados_src_cpu_core-5Fdynrec_risc-5Farmv4le-2Do3.h&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=f1niO7ol20SzppTZaiU2b_qqD5nCY4LU6TRcP_U0QUE&s=ryqQpvdnDQ9BaHSAH2Q35qRvmbKDZTquyFECPu8fNkM&e=" rel="noreferrer" target="_blank">https://github.com/wjp/dosbox/blob/idados/src/cpu/core_dynrec/risc_armv4le-o3.h</a><br>
<br>
So basically, it looks like there's code that translates instructions<br>
from x86 to a few other platforms in chunks of 32 opcodes. Since this<br>
code was too slow to me, I asked myself the question "how could it speed<br>
up?" and assumed that perhaps LLVM could optimize it on the fly. So,<br>
here's the question - would it be feasible given the assumptions above?<br>
What I am thinking about is a system that would:<br>
<br>
1. Generate LLVM IR code instead of native calls and JIT them on the fly,<br>
2. Apply optimizations that I know from Clang.<br>
<br>
I saw this example on pastebin [1] and generating functions on the fly<br>
looks rather straightforward, but I am not sure if it would be as easy<br>
if I wanted to translate machine code from one platform to another. Does<br>
LLVM have or integrate with any libraries that would make this<br>
practical? What would be the main challenges? Keep in mind that I would<br>
welcome even a partial answer.<br>
<br>
Cheers,<br>
d33tah<br>
<br>
[1] <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__pastebin.com_f2NSGZGR&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=f1niO7ol20SzppTZaiU2b_qqD5nCY4LU6TRcP_U0QUE&s=LVRPRHjvWSmJfLR3L2e1K3wRlQGp6Tp1OIAN1QffFWU&e=" rel="noreferrer" target="_blank">http://pastebin.com/f2NSGZGR</a><br>
<br>
</div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" rel="noreferrer" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>