I aim to change indirect instruction jmp *(eax)
in my code to mov *(eax), ebx; jmp *ebx
for x86 binaries. Before I proceed with this adjustment, I’d like to log messages each time the LLVM compiler identifies a jmp *(eax)
instruction by incorporating some print statements. After that, I’ll tackle the replacement of the indirect jump sequence. Based on my research, it seems possible to achieve this by altering the x86asmprinter component within the LLVM backend. However, I’m uncertain about how to execute this. Any assistance or resources would be greatly appreciated. Note: Although my primary focus is on handling indirect jumps and pops, I prefer to start with this simpler task to enhance my understanding of the backend.
One approach to modify the indirect jumps is to create a custom pass that analyzes the assembly instructions. You can leverage LLVM’s extensive API to identify the specific instructions and insert your logging mechanism. After locating <code>jmp *(eax)</code>
instructions, you can modify them within the pass. Consider using the MachineFunctionPass
for this purpose as it operates on the abstract machine level, which can simplify the task. This method allows you to work directly within the LLVM IR and provides finer control over the instruction manipulation process.
Hey there! why don’t you start with adding debug prints in the x86AsmPrinter
codebase? It would let you see whenever a jmp *(eax)
is encountered. Just a small tip, carefully handle the gs general state changes when inserting MOV
. enjy😉
You could explore tweaking the pass logs in LLVM when running the compiler with certain flags. It might give you insights without altering too much code. Also, don’t forget to test in a controlled environment, preferably with small programs, to see how your changes affect execution.
Interesting project! Hv you considered using LLVM’s IRBuilder
? It might give you a more intuitive way to insert logging mechanisms. Also, how do you plan to verify that your new instructions are working correctly? I’m curious how performance might change with those extra mov
operations.
To tackle the modifications in the LLVM x86 backend, you can employ the LLVM analysis framework, which allows you to inspect and manipulate instructions during the code generation phase. Start by exploring the SelectionDAG
phase, where you can access detailed machine-specific instructions before they get printed to assembly. This will give you the necessary control to detect the jmp *(eax)
pattern. Implement prototype modifications that can be easily reverted so you can iteratively refine your approach while observing the effects on the generated binaries.