Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PC-relative LDRi12 #1157

Merged
merged 1 commit into from
Oct 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion gapii/interceptor-lib/cc/lib/ARM/target_arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static void *calculatePcRelativeAddressArm(void *data, size_t pc_offset,

data_addr += pc_offset; // Add the PC
data_addr += 8; // Add the 8 byte implicit offset
data_addr += offset; // Add the offset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a nasty bug you've fixed. Was nothing passing offset before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only ARM::Bcc seems to have been affected (non-Thumb).
The Thumb calculation is correct.

return reinterpret_cast<void *>(data_addr);
}

Expand Down Expand Up @@ -176,7 +177,6 @@ Error TargetARM::RewriteInstruction(const llvm::MCInst &inst,
case llvm::ARM::LDR_PRE_REG:
case llvm::ARM::LDR_POST_IMM:
case llvm::ARM::LDR_POST_REG:
case llvm::ARM::LDRi12:
case llvm::ARM::LDRH_PRE:
case llvm::ARM::LDRH_POST:
case llvm::ARM::LDRH:
Expand Down Expand Up @@ -278,6 +278,29 @@ Error TargetARM::RewriteInstruction(const llvm::MCInst &inst,
}
break;
}
case llvm::ARM::LDRi12: {
uint32_t Rt = inst.getOperand(0).getReg();
uint32_t Rn = inst.getOperand(1).getReg();
int64_t imm = inst.getOperand(2).getImm();
int64_t p = inst.getOperand(3).getImm();
possible_end_of_function = (Rt == llvm::ARM::PC);

if (Rn == llvm::ARM::PC) {
void *load_source =
calculatePcRelativeAddressArm(data, offset, imm);
uint32_t load_data = 0;
memcpy(&load_data, load_source, sizeof(uint32_t));
codegen.AddInstruction(llvm::MCInstBuilder(llvm::ARM::LDRi12)
.addReg(Rt)
.addExpr(codegen.CreateDataExpr(load_data))
.addImm(0)
.addImm(p)
.addImm(0));
} else {
codegen.AddInstruction(inst);
}
break;
}
case llvm::ARM::tLDRpci:
case llvm::ARM::t2LDRpci: {
uint32_t Rt = inst.getOperand(0).getReg();
Expand Down