-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
dump program in LLVM IR #575
Comments
Is BAP 0.8 available for download? bap.ece.cmu.edu doesn't seem to have hosted it. I believe it had an LLVM code generator too. Perhaps someone might find that useful until this issue is resolved - for use or even for writing the LLVM IR translator. |
There are quite a few forks of the legacy BAP available around the Hub. You can try to use GitHub's search ability to find them all. The first that comes to my mind is https://github.com/0day1day/bap |
BAP 0.8 may be available someplace. I would warn that LLVM IR translator for binary has been tried by many, and often does not get you what you're looking for. Imagine the LLVM IR with 1 function that is 1 MB using only goto's. The LLVM IR isn't designed for that. You can do per-function, but you still end up with lots of design choices, e.g., representing the stack (and shared stack frame). Just my opinion, so take it for what it's worth, LLVM IR is the wrong thing for binary analysis. It's great for a compiler, but the right data structures for binary analysis (although the result of compilation) is different than for compilation itself. The current BAP is what we think is the best approach. |
ivg set pipeline to Icebox |
Great work! I have a question for the BAP IR. Is it a "high-level" IR or "low-level"? Here, I refer the "high-level" to the original IRs without optimizations, such as no O1~O3. The "low-level" IR is like a direct translator from assembly code to IR. |
It is low level, as it expands instructions up to the CPU microcode, so it's lower than assembly or machine code. |
hello |
This issue is basically saying that dumping BIR into IR is not implemented and suggests anyone, who would like to implement it, a course of actions. Note, that it is not trivial, so do not expect an easy trip. A few of us went down this road with no success :) |
thank you for your answer |
It is not possible in modern BAP, that's why this issue is open. |
ok ,thanks |
Curiously, with the modern move of BAP to the KB and CT, implementing something like this might be easier (might be not, depending on some conversion peculiarities). |
Excuse me, this issue is still open. Does it mean that dumping BIR into IR is not implemented yet? |
Motivation
Dumping project in the LLVM IR will open an opportunity to many interesting projects, e.g., JIT compilation, running LLVM analyses, creating binaries, lifter verification, etc.
This can be a nice toy project, for someone who would like to learn BAP. And it is the best way to learn both LLVM and BAP intermediate representations.
Implementation
Since BAP IR is quite close to the LLVM IR, the direct transformation should be easy. A proper place, to inject it, would be to write a pretty printer for the project data structure. Here comes the skeleton setup.
Initial setup
bir_to_llvm
.bir_to_llvm.ml
with the following initial contents:Building and running
bapbuild bir_to_llvm.plugin
bapbundle install bir_to_llvm.plugin
bap /bin/true -dllvm
or as a one liner:
Testing
The generated code should be acceptable
llc
:The command will spill out
true.s
file with an assembly representation.Alternative implementation
It would be even nicer to use
Term.visitor
to implement the printer, however, it relies on the object system and may raise the bar.The text was updated successfully, but these errors were encountered: