[llvm-dev] How to write LLVM backend pass after every LLVM's internal pass?

Nicholas Krause via llvm-dev llvm-dev at lists.llvm.org
Thu Nov 28 08:17:16 PST 2019



On 11/28/19 2:06 AM, Casper Sun wrote:
> Because I need to use reverse engineering to patched generated binary. But llc deleted some function call I injected, so I couldn’t find these instructions in radare2(reverse engine I used to patch binary).
>
> For example:
> Mov edi, 0x1     mov edi, 0x2
>      |                        |
>      |                        |
>      V                       V
> Call func		 call func
>
> Will be opted into:
>
> Mov edi, 0x1.   Mov edi, 0x2
>      |                        |
>      | <——————
>     V
> Call func
>
> I write my MachineFunctionPass in lib/Targets/X86 directory. Will lib/CodeGen optimize my injected code?
>
If I understand your diagram yes as those are basically the same 
instructions excluding moving
at 0x1 address versus 0x2 address. Combining would be normal here if and 
to my knowledge
x86 can do mov with two addresses.  What you want to figure out is how 
to inject earlier
probably in the middle end and then trace it to see if the instructions 
are similar enough to
be doing this.

Nick
>
>> On Nov 28, 2019, at 2:02 PM, Nicholas Krause <xerofoify at gmail.com> wrote:
>>
>>
>>
>> On 11/28/19 12:16 AM, Casper Sun via llvm-dev wrote:
>>> Currently I’m writing a X86 backend pass for my research project. I inserted a few instructions in MachineBasicBlocks, but then llc optimized my code, and deleted some of it. So how to so backend pass after all machine level optimizations?
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> llvm-dev at lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>> I don't have enough details to really help out here but my first assumption is that costs of selections are being merged in the llc.
>> You should note that's normal and generally a good thing or other forms of combining or merging instructions in the llc.
>>
>> So based on that I'm curious as to why your concerned about the llc deleted parts of it,
>>
>> Nick



More information about the llvm-dev mailing list