I want to insert a jump instruction into the target program through the pass of LLVM. I know that branchinst can be used to realize the jump of basic blocks in LLVM. But what I want to achieve is a jump of instructions in the same basic block (assuming I know the destination address of the jump). How do I do that? Iineasm? Can you give me an example?
For example, in C I could implement this:
// before insert jmp
#include <stdio.h>
int main()
{
int a = 0;
int b = 2;
if(a<b)
{
printf("hh\n");
printf("jump hh\n");
}
return 0;
}
result: hh
jump hh
// after insert jmp
#include <stdio.h>
int main()
{
int a = 0;
int b = 2;
if(a<b)
{
asm("jmp main 0x30;");
printf("hh\n");
printf("jump hh\n");
}
return 0;
}
result: jump hh
cmp -0x4(%rbp),