Recompile a x86 code with LLVM to some faster one x86

前端 未结 3 1539
渐次进展
渐次进展 2021-02-05 10:18

Is it possible to run LLVM compiler with input of x86 32bit code? There is a huge algorithm which I have no source code and I want to make it run faster on the same hardware. Ca

相关标签:
3条回答
  • 2021-02-05 11:00

    The MAO project seems to do part of what you want (x86->intermediate language).

    edit: @osgx, you'll need to look at the mao website for the project status and details of what programs they can handle. (Self-modifying code might be challenging though.)

    0 讨论(0)
  • 2021-02-05 11:20

    From what I know, disassembling x86 code 100% correctly is impossible. As data and code is intermingled and also due to variable length instructions. The only way to properly disassemble is to interpret it on the fly.

    0 讨论(0)
  • 2021-02-05 11:21

    LLVM can't do this out of the box. You'd have to write an x86 binary to LLVM intermediate representation (IR) converter. That would be a very non-trivial task. If the x86 code was simple enough it might map pretty closely to IR, but some x86 instructions won't map directly, e.g. stack pointer manipulations.

    Edit: You could also consider trying an approach similar to what QEMU does. QEMU translates the binaries on the fly, that it when I run PowerPC code, each basic block is translated into X86 code before it is executed. You could figure out how to break your object file into the basic blocks and generate LLVM IR for each block, discarding stuff (like parameter passing, etc.) and replacing that with straight LLVM IR.

    Still a BIG job, though. Probably easier to rewrite the algorithm from scratch.

    This exact process is described in "Dynamically Translating x86 to LLVM using QEMU"

    0 讨论(0)
提交回复
热议问题