Skip to content

Commit

Permalink
Fix compilation issue on powerpc
Browse files Browse the repository at this point in the history
  • Loading branch information
mxz297 committed Jul 6, 2018
1 parent 673a947 commit 6c86e9a
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 43 deletions.
3 changes: 3 additions & 0 deletions common/src/arch-aarch64.h
Expand Up @@ -133,6 +133,9 @@ class COMMON_EXPORT instruction {
instruction(const void *ptr) {
insn_ = *((const instructUnion *)ptr);
}
instruction(const void *ptr, bool mode_64) {
insn_ = *((const instructUnion *)ptr);
}

instruction(const instruction &insn) : insn_(insn.insn_) {};
instruction(instructUnion &insn) :
Expand Down
4 changes: 3 additions & 1 deletion common/src/arch-power.h
Expand Up @@ -782,7 +782,9 @@ class COMMON_EXPORT instruction {
instruction(const void *ptr) {
insn_ = *((const instructUnion *)ptr);
}

instruction(const void *ptr, bool mode_64) {
insn_ = *((const instructUnion *)ptr);
}
instruction(const instruction &insn) : insn_(insn.insn_) {};
instruction(instructUnion &insn) :
insn_(insn) {};
Expand Down
18 changes: 9 additions & 9 deletions dyninstAPI/src/BPatch_memoryAccessAdapter.C
Expand Up @@ -178,7 +178,7 @@ BPatch_memoryAccess* BPatch_memoryAccessAdapter::convert(Instruction insn,
#else
(void) is64; //Silence warnings
std::vector<Operand> operands;
insn->getOperands(operands);
insn.getOperands(operands);
for(std::vector<Operand>::iterator op = operands.begin();
op != operands.end();
++op)
Expand All @@ -188,27 +188,27 @@ BPatch_memoryAccess* BPatch_memoryAccessAdapter::convert(Instruction insn,
if(isLoad || isStore)
{
op->getValue()->apply(this);
if(insn->getOperation().getID() == power_op_lmw ||
insn->getOperation().getID() == power_op_stmw)
if(insn.getOperation().getID() == power_op_lmw ||
insn.getOperation().getID() == power_op_stmw)
{
RegisterAST::Ptr byteOverride =
boost::dynamic_pointer_cast<RegisterAST>(insn->getOperand(0).getValue());
boost::dynamic_pointer_cast<RegisterAST>(insn.getOperand(0).getValue());
assert(byteOverride);
MachRegister base = byteOverride->getID().getBaseRegister();
unsigned int converted = base.val() & 0xFFFF;
bytes = (32 - converted) << 2;
}
if(insn->getOperation().getID() == power_op_lswi ||
insn->getOperation().getID() == power_op_stswi)
if(insn.getOperation().getID() == power_op_lswi ||
insn.getOperation().getID() == power_op_stswi)
{
Immediate::Ptr byteOverride =
boost::dynamic_pointer_cast<Immediate>(insn->getOperand(2).getValue());
boost::dynamic_pointer_cast<Immediate>(insn.getOperand(2).getValue());
assert(byteOverride);
bytes = byteOverride->eval().convert<unsigned int>();
if(bytes == 0) bytes = 32;
}
if(insn->getOperation().getID() == power_op_lswx ||
insn->getOperation().getID() == power_op_stswx)
if(insn.getOperation().getID() == power_op_lswx ||
insn.getOperation().getID() == power_op_stswx)
{
return new BPatch_memoryAccess(new internal_instruction(NULL), current, isLoad, isStore, (long)0, ra, rb, (long)0, 9999, -1);
}
Expand Down
10 changes: 5 additions & 5 deletions dyninstAPI/src/Relocation/Widgets/CFWidget-ppc.C
Expand Up @@ -52,12 +52,12 @@ using namespace NS_power;
bool CFWidget::generateIndirect(CodeBuffer &buffer,
Register,
const RelocBlock *trace,
Instruction::Ptr insn) {
Instruction insn) {
// Copying an indirect jump; unlike x86 we don't do
// call -> indirect conversion yet.
// ... though that would be really freaking easy.

NS_power::instruction ugly_insn(insn->ptr());
NS_power::instruction ugly_insn(insn.ptr());
IFORM_LK_SET(ugly_insn, 0);
codeGen gen(4);
insnCodeGen::generate(gen, ugly_insn);
Expand All @@ -72,11 +72,11 @@ bool CFWidget::generateIndirect(CodeBuffer &buffer,

bool CFWidget::generateIndirectCall(CodeBuffer &buffer,
Register /*reg*/,
Instruction::Ptr insn,
Instruction insn,
const RelocBlock *trace,
Address /*origAddr*/)
{
NS_power::instruction ugly_insn(insn->ptr());
NS_power::instruction ugly_insn(insn.ptr());
IFORM_LK_SET(ugly_insn, 1);
codeGen gen(4);
insnCodeGen::generate(gen, ugly_insn);
Expand Down Expand Up @@ -116,7 +116,7 @@ bool CFPatch::apply(codeGen &gen, CodeBuffer *buf) {
relocation_cerr << "\t\t CFPatch::apply, type " << type << ", origAddr " << hex << origAddr_
<< ", and label " << dec << targetLabel << endl;

if (orig_insn) {
if (orig_insn.isValid()) {
relocation_cerr << "\t\t\t Currently at " << hex << gen.currAddr() << " and targeting predicted " << buf->predictedAddr(targetLabel) << dec << endl;
switch(type) {
case CFPatch::Jump: {
Expand Down
4 changes: 2 additions & 2 deletions dyninstAPI/src/Relocation/Widgets/PCWidget.C
Expand Up @@ -98,7 +98,7 @@ bool PCWidget::PCtoReturnAddr(const codeGen &templ, const RelocBlock *t, CodeBuf
if (!point ||
(point->type() != instPoint::PreInsn &&
point->insnAddr() != addr())) {
point = instPoint::preInsn(t->func(), t->block(), addr(), insn(), true);
point = instPoint::preInsn(t->func(), t->block(), addr(), insn_, true);
}
assert(point);

Expand All @@ -108,7 +108,7 @@ bool PCWidget::PCtoReturnAddr(const codeGen &templ, const RelocBlock *t, CodeBuf
pdvector<Register> freeReg;
pdvector<Register> excludeReg;

Address origRet = addr() + insn()->size();
Address origRet = addr() + insn_.size();
Register scratch = gen.rs()->getScratchRegister(gen, true);
if (scratch == REG_NULL) {
stackSize = insnCodeGen::createStackFrame(gen, 1, freeReg, excludeReg);
Expand Down
17 changes: 10 additions & 7 deletions dyninstAPI/src/image.C
Expand Up @@ -309,8 +309,9 @@ namespace {
// looking for the *last* instruction in the block
// that defines GR8

Instruction::Ptr r8_def;
Instruction r8_def;
Address r8_def_addr;
bool find = false;

InstructionDecoder dec(
b->region()->getPtrToInstruction(b->start()),
Expand All @@ -321,22 +322,24 @@ namespace {
RegisterAST::Ptr r8( new RegisterAST(ppc32::r8) );

Address cur_addr = b->start();
while(Instruction::Ptr cur = dec.decode()) {
if(cur->isWritten(r8)) {
while(cur_addr < b->end()) {
Instruction cur = dec.decode();
if(cur.isWritten(r8)) {
find = true;
r8_def = cur;
r8_def_addr = cur_addr;
}
cur_addr += cur->size();
cur_addr += cur.size();
}
if(!r8_def)
if(!find)
return 0;

Address ss_addr = 0;

// Try a TOC-based lookup first
if (r8_def->isRead(r2)) {
if (r8_def.isRead(r2)) {
set<Expression::Ptr> memReads;
r8_def->getMemoryReadOperands(memReads);
r8_def.getMemoryReadOperands(memReads);
Address TOC = f->obj()->cs()->getTOC(r8_def_addr);
if (TOC != 0 && memReads.size() == 1) {
Expression::Ptr expr = *memReads.begin();
Expand Down
6 changes: 3 additions & 3 deletions dyninstAPI/src/inst-power.C
Expand Up @@ -2449,7 +2449,7 @@ void emitStorePreviousStackFrameRegister(Address,
}

using namespace Dyninst::InstructionAPI;
bool AddressSpace::getDynamicCallSiteArgs(InstructionAPI::Instruction::Ptr i,
bool AddressSpace::getDynamicCallSiteArgs(InstructionAPI::Instruction i,
Address addr,
pdvector<AstNodePtr> &args)
{
Expand All @@ -2461,8 +2461,8 @@ bool AddressSpace::getDynamicCallSiteArgs(InstructionAPI::Instruction::Ptr i,

// Is this a branch conditional link register (BCLR)
// BCLR uses the xlform (6,5,5,5,10,1)
for(Instruction::cftConstIter curCFT = i->cft_begin();
curCFT != i->cft_end();
for(Instruction::cftConstIter curCFT = i.cft_begin();
curCFT != i.cft_end();
++curCFT)
{
if(curCFT->target->isUsed(ctr32) ||
Expand Down
35 changes: 20 additions & 15 deletions dyninstAPI/src/parse-power.C
Expand Up @@ -543,10 +543,13 @@ void parse_func::calcUsedRegs()
InstructionDecoder d(getPtrToInstruction((*curBlock)->start()),
(*curBlock)->size(),
isrc()->getArch());
Instruction::Ptr i;
while(i = d.decode())
Instruction i;
int size = 0;
while(size < (*curBlock)->size())
{
i->getWriteSet(writtenRegs);
i = d.decode();
size += i.size();
i.getWriteSet(writtenRegs);
}
}
for(std::set<RegisterAST::Ptr>::const_iterator curReg = writtenRegs.begin();
Expand Down Expand Up @@ -813,16 +816,16 @@ func_instance *mapped_object::findGlobalConstructorFunc(const std::string &ctorH
InstructionDecoder decoder(p, initRegion->getDiskSize(),
parse_img()->codeObject()->cs()->getArch());

Instruction::Ptr curInsn = decoder.decode();
while(numCalls < CTOR_NUM_CALLS && curInsn && curInsn->isValid() &&
Instruction curInsn = decoder.decode();
while(numCalls < CTOR_NUM_CALLS && curInsn.isValid() &&
bytesSeen < initRegion->getDiskSize())
{
InsnCategory category = curInsn->getCategory();
InsnCategory category = curInsn.getCategory();
if( category == c_CallInsn ) {
numCalls++;
}
if( numCalls < CTOR_NUM_CALLS ) {
bytesSeen += curInsn->size();
bytesSeen += curInsn.size();
curInsn = decoder.decode();
}
}
Expand All @@ -837,7 +840,7 @@ func_instance *mapped_object::findGlobalConstructorFunc(const std::string &ctorH
RegisterAST thePC = RegisterAST(
Dyninst::MachRegister::getPC(parse_img()->codeObject()->cs()->getArch()));

Expression::Ptr callTarget = curInsn->getControlFlowTarget();
Expression::Ptr callTarget = curInsn.getControlFlowTarget();
if( !callTarget.get() ) {
logLine("failed to find global constructor function\n");
return NULL;
Expand Down Expand Up @@ -916,23 +919,25 @@ func_instance *mapped_object::findGlobalDestructorFunc(const std::string &dtorHa
InstructionDecoder decoder(p, finiRegion->getDiskSize(),
parse_img()->codeObject()->cs()->getArch());

Instruction::Ptr lastCall;
Instruction::Ptr curInsn = decoder.decode();
Instruction lastCall;
Instruction curInsn = decoder.decode();
bool find = false;

while(curInsn && curInsn->isValid() &&
while(curInsn.isValid() &&
bytesSeen < finiRegion->getDiskSize())
{
InsnCategory category = curInsn->getCategory();
InsnCategory category = curInsn.getCategory();
if( category == c_CallInsn ) {
find = true;
lastCall = curInsn;
break;
}

bytesSeen += curInsn->size();
bytesSeen += curInsn.size();
curInsn = decoder.decode();
}

if( !lastCall.get() || !lastCall->isValid() ) {
if( !find || !lastCall.isValid() ) {
logLine("heuristic for finding global destructor function failed\n");
return NULL;
}
Expand All @@ -942,7 +947,7 @@ func_instance *mapped_object::findGlobalDestructorFunc(const std::string &dtorHa
RegisterAST thePC = RegisterAST(
Dyninst::MachRegister::getPC(parse_img()->codeObject()->cs()->getArch()));

Expression::Ptr callTarget = lastCall->getControlFlowTarget();
Expression::Ptr callTarget = lastCall.getControlFlowTarget();
if( !callTarget.get() ) {
logLine("failed to find global destructor function\n");
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion instructionAPI/src/Operation.C
Expand Up @@ -362,8 +362,8 @@ namespace Dyninst
}
void Operation_impl::SetUpNonOperandData(bool needFlags)
{
#if defined(arch_x86) || defined(arch_x86_64)
std::call_once(data_initialized, [&]() {
#if defined(arch_x86) || defined(arch_x86_64)
if (prefixID == prefix_rep || prefixID == prefix_repnz) {
otherRead.insert(makeRegFromID((archDecodedFrom == Arch_x86) ? x86::df : x86_64::df));
otherRead.insert(makeRegFromID((archDecodedFrom == Arch_x86) ? x86::ecx : x86_64::rcx));
Expand Down

0 comments on commit 6c86e9a

Please sign in to comment.