[LLVMdev] Problem with MachineFunctionPass and JMP
Rinaldini Julien
julien.rinaldini at heig-vd.ch
Tue May 14 04:32:11 PDT 2013
Ok, I found the problem !
You have to add the successor BB before adding the jump:
newEntry->addSuccessor(origBB.at(1));
Cheers
Le 13 mai 2013 à 19:09, Rinaldini Julien <julien.rinaldini at heig-vd.ch<mailto:julien.rinaldini at heig-vd.ch>> a écrit :
Hi !
I'm trying to modify the code in a machine function pass…
I added a new basicblock and I want to add a jump to an another BB from my new BB.
Here is my code :
bool Obfuscation::runOnMachineFunction(MachineFunction &MF) {
MachineBasicBlock *newEntry = MF.CreateMachineBasicBlock();
MF.insert(MF.begin(), newEntry);
std::vector<MachineBasicBlock*> origBB;
for(MachineFunction::iterator i = MF.begin(); i != MF.end(); ++i)
origBB.push_back(i);
for(unsigned int i = 0; i < origBB.size(); ++i)
origBB.at<http://origBB.at>(i)->moveAfter(newEntry);
MCInstrInfo tii = *MF.getTarget().getInstrInfo();
MachineInstr *plop = BuildMI(MF, DebugLoc(),tii.get(X86::JMP_4)).addMBB(origBB.at<http://origBB.at>(1));
newEntry->push_back(plop);
return false;
}
And here is the resulting code (it's a simple program with some 'if'):
(null) BB#4
JMP_4 <BB#0>
if.end BB#3
%RDI<def> = LEA64r %RIP, 1, %noreg, <ga:@.str2>, %noreg
ADJCALLSTACKDOWN64 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use>
%AL<def> = MOV8ri 0
CALL64pcrel32 <ga:@printf>, <regmask>, %RSP<imp-use>, %AL<imp-use,kill>, %RDI<imp-use,kill>, %EAX<imp-def>
ADJCALLSTACKUP64 0, 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use>
%ECX<def> = MOV32ri 25
MOV32mr <fi#8>, 1, %noreg, 0, %noreg, %EAX<kill>; mem:ST4[FixedStack8]
%EAX<def> = COPY %ECX<kill>
RET %EAX<imp-use,kill>
if.else BB#2
%RDI<def> = LEA64r %RIP, 1, %noreg, <ga:@.str1>, %noreg
ADJCALLSTACKDOWN64 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use>
%AL<def> = MOV8ri 0
CALL64pcrel32 <ga:@printf>, <regmask>, %RSP<imp-use>, %AL<imp-use,kill>, %RDI<imp-use,kill>, %EAX<imp-def>
ADJCALLSTACKUP64 0, 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use>
MOV32mr <fi#7>, 1, %noreg, 0, %noreg, %EAX<kill>; mem:ST4[FixedStack7]
if.then BB#1
%RDI<def> = LEA64r %RIP, 1, %noreg, <ga:@.str>, %noreg
ADJCALLSTACKDOWN64 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use>
%AL<def> = MOV8ri 0
CALL64pcrel32 <ga:@printf>, <regmask>, %RSP<imp-use>, %AL<imp-use,kill>, %RDI<imp-use,kill>, %EAX<imp-def>
ADJCALLSTACKUP64 0, 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use>
MOV32mr <fi#6>, 1, %noreg, 0, %noreg, %EAX<kill>; mem:ST4[FixedStack6]
JMP_4 <BB#3>
entry BB#0
MOV32mi <fi#0>, 1, %noreg, 0, %noreg, 0
MOV32mr <fi#1>, 1, %noreg, 0, %noreg, %EDI<kill>
MOV64mr <fi#2>, 1, %noreg, 0, %noreg, %RSI<kill>
MOV32mi <fi#3>, 1, %noreg, 0, %noreg, 0
MOV32mi <fi#4>, 1, %noreg, 0, %noreg, 4
%EDI<def> = MOV32rm <fi#3>, 1, %noreg, 0, %noreg
%EDI<def,tied1> = SUB32rm %EDI<tied0>, <fi#4>, 1, %noreg, 0, %noreg, %EFLAGS<imp-def>
MOV32mr <fi#5>, 1, %noreg, 0, %noreg, %EDI<kill>
%RSI<def> = MOV64rm <fi#2>, 1, %noreg, 0, %noreg
%RDI<def> = MOV64rm %RSI<kill>, 1, %noreg, 8, %noreg
ADJCALLSTACKDOWN64 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use>
CALL64pcrel32 <ga:@atoi>, <regmask>, %RSP<imp-use>, %RDI<imp-use,kill>, %EAX<imp-def>
ADJCALLSTACKUP64 0, 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use>
CMP32ri %EAX<kill>, 5, %EFLAGS<imp-def>
JNE_4 <BB#2>, %EFLAGS<imp-use>
But at the end, I get this error : fatal error: error in backend: unsupported relocation of undefined symbol 'LBB0_0'
Any idea on what can the problem be ?
Thx, cheers
_______________________________________________
LLVM Developers mailing list
LLVMdev at cs.uiuc.edu<mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list