Skip to content

Commit

Permalink
Merge branch 'master' into att_syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
John Detter committed Dec 20, 2016
2 parents ff02d91 + 348e189 commit 6fac704
Show file tree
Hide file tree
Showing 22 changed files with 207 additions and 119 deletions.
18 changes: 9 additions & 9 deletions cmake/warnings.cmake
@@ -1,12 +1,12 @@
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual -Woverloaded-virtual")
if (CMAKE_C_COMPILER_ID MATCHES GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align -Wno-non-template-friend -Wno-unused-local-typedefs -Wno-deprecated-declarations")
endif (CMAKE_C_COMPILER_ID MATCHES GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual -Woverloaded-virtual")
if (CMAKE_C_COMPILER_ID MATCHES GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align -Wno-non-template-friend -Wno-unused-local-typedefs -Wno-deprecated-declarations")
endif()
elseif (MSVC)
message(STATUS "TODO: Set up custom warning flags for MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4251 /wd4091 /wd4503")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251 /wd4091 /wd4503")
message(STATUS "TODO: Set up custom warning flags for MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4251 /wd4091 /wd4503")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251 /wd4091 /wd4503")
endif()
4 changes: 2 additions & 2 deletions dataflowAPI/h/AbslocInterface.h
Expand Up @@ -51,7 +51,7 @@ namespace Dyninst {

class AbsRegionConverter {
public:
DATAFLOW_EXPORT AbsRegionConverter(bool cache, bool stack = true) :
DATAFLOW_EXPORT AbsRegionConverter(bool cache, bool stack) :
cacheEnabled_(cache), stackAnalysisEnabled_(stack) {};

// Definition: the first AbsRegion represents the expression.
Expand Down Expand Up @@ -122,7 +122,7 @@ class AbsRegionConverter {

class AssignmentConverter {
public:
DATAFLOW_EXPORT AssignmentConverter(bool cache, bool stack = true) : cacheEnabled_(cache), aConverter(false, stack) {};
DATAFLOW_EXPORT AssignmentConverter(bool cache, bool stack) : cacheEnabled_(cache), aConverter(false, stack) {};

DATAFLOW_EXPORT void convert(InstructionAPI::Instruction::Ptr insn,
const Address &addr,
Expand Down
4 changes: 3 additions & 1 deletion dataflowAPI/h/stackanalysis.h
Expand Up @@ -348,7 +348,9 @@ class StackAnalysis {
const std::map<Address, TransferSet> &fs,
const std::set<Address> &toppable = std::set<Address>());

DATAFLOW_EXPORT Height find(ParseAPI::Block *, Address addr, Absloc loc);
DATAFLOW_EXPORT virtual ~StackAnalysis();

DATAFLOW_EXPORT Height find(ParseAPI::Block *, Address addr, Absloc loc);
DATAFLOW_EXPORT Height findSP(ParseAPI::Block *, Address addr);
DATAFLOW_EXPORT Height findFP(ParseAPI::Block *, Address addr);
DATAFLOW_EXPORT void findDefinedHeights(ParseAPI::Block* b, Address addr,
Expand Down
14 changes: 7 additions & 7 deletions dataflowAPI/rose/x86_64InstructionSemantics.h
Expand Up @@ -2259,19 +2259,19 @@ struct X86_64InstructionSemantics {
policy.writeGPR(x86_gpr_sp, newSp);
break;
}
*/
case x86_call: {
ROSE_ASSERT(operands.size() == 1);
ROSE_ASSERT(insn->get_addressSize() == x86_insnsize_32);
ROSE_ASSERT(insn->get_operandSize() == x86_insnsize_32);
Word(32) oldSp = policy.readGPR(x86_gpr_sp);
Word(32) newSp = policy.add(oldSp, number<32>(-4));
ROSE_ASSERT(insn->get_addressSize() == x86_insnsize_64);
ROSE_ASSERT(insn->get_operandSize() == x86_insnsize_64);
Word(64) oldSp = policy.readGPR(x86_gpr_sp);
Word(64) newSp = policy.add(oldSp, number<64>(-4));
policy.writeMemory(x86_segreg_ss, newSp, policy.readIP(), policy.true_());
policy.writeIP(policy.filterCallTarget(read32(operands[0])));
policy.writeIP(policy.filterCallTarget(read64(operands[0])));
policy.writeGPR(x86_gpr_sp, newSp);
break;
}
/*
case x86_ret: {
ROSE_ASSERT(operands.size() <= 1);
ROSE_ASSERT(insn->get_addressSize() == x86_insnsize_32);
Expand Down
4 changes: 4 additions & 0 deletions dataflowAPI/src/AbslocInterface.C
Expand Up @@ -301,6 +301,10 @@ AbsRegion AbsRegionConverter::stack(Address addr,
ParseAPI::Function *func,
ParseAPI::Block *block,
bool push) {
if(!stackAnalysisEnabled_) {
// std::cerr << "Stack analysis disabled, returning Stack absregion" << std::endl;
return AbsRegion(Absloc::Stack);
}
long spHeight = 0;
bool stackExists = getCurrentStackHeight(func,
block,
Expand Down
54 changes: 54 additions & 0 deletions dataflowAPI/src/stackanalysis.C
Expand Up @@ -1254,6 +1254,37 @@ void StackAnalysis::handlePushPop(Instruction::Ptr insn, Block *block,
// Get pushed immediate
long immVal = readExpr->eval().convert<long>();
xferFuncs.push_back(TransferFunc::absFunc(writtenLoc, immVal));
} else if (dynamic_cast<Dereference *>(readExpr.get())) {
// Extract the read address expression
std::vector<Expression::Ptr> addrExpr;
readExpr->getChildren(addrExpr);
assert(addrExpr.size() == 1);

// Try to determine the read memory address
StateEvalVisitor visitor;
if (intervals_ == NULL) {
visitor = StateEvalVisitor(off, insn, NULL);
} else {
visitor = StateEvalVisitor(off, insn,
&(*intervals_)[block][off]);
}
addrExpr[0]->apply(&visitor);
if (visitor.isDefined()) {
Absloc readLoc;
std::pair<Address, bool> resultPair = visitor.getResult();
if (resultPair.second) {
// We have a stack slot
readLoc = Absloc(resultPair.first, 0, NULL);
} else {
// We have a static address
readLoc = Absloc(resultPair.first);
}
xferFuncs.push_back(TransferFunc::copyFunc(readLoc,
writtenLoc));
} else {
// Unknown read address. Assume top.
xferFuncs.push_back(TransferFunc::retopFunc(writtenLoc));
}
} else {
STACKANALYSIS_ASSERT(false);
}
Expand Down Expand Up @@ -3501,3 +3532,26 @@ void StackAnalysis::bottomBaseSubReg(const MachRegister &reg,
}
}
}

StackAnalysis::~StackAnalysis() {
// delete func;

callResolutionMap.clear();
functionSummaries.clear();
toppableFunctions.clear();

// SP effect tracking
// delete blockEffects; // Pointer so we can make it an annotation
// delete insnEffects; // Pointer so we can make it an annotation
// delete callEffects; // Pointer so we can make it an annotation

blockInputs.clear();
blockOutputs.clear();

blockSummaryInputs.clear();
blockSummaryOutputs.clear();

// delete intervals_; // Pointer so we can make it an annotation

funcCleanAmounts.clear();
}
2 changes: 1 addition & 1 deletion dyninstAPI/src/MemoryEmulator/memEmulatorTransformer.h
Expand Up @@ -56,7 +56,7 @@ class MemEmulatorTransformer : public Transformer {
virtual bool process(RelocBlock *, RelocGraph *);

MemEmulatorTransformer() :
aConverter(false) {};
aConverter(false, false) {};

virtual ~MemEmulatorTransformer() {};

Expand Down
9 changes: 8 additions & 1 deletion dyninstAPI/src/Relocation/CFG/RelocGraph.C
Expand Up @@ -40,13 +40,20 @@ RelocGraph::~RelocGraph() {
for (Edges::iterator iter = edges.begin(); iter != edges.end(); ++iter) {
delete *iter;
}

std::set<func_instance*> funcs_to_clean;
RelocBlock *cur = head;
while (cur) {
RelocBlock *next = cur->next();
funcs_to_clean.insert(cur->func());
delete cur;
cur = next;
}
for(auto f = funcs_to_clean.begin();
f != funcs_to_clean.end();
++f)
{
if(*f) (*f)->freeStackMod();
}
}

void RelocGraph::addRelocBlock(RelocBlock *t) {
Expand Down
3 changes: 2 additions & 1 deletion dyninstAPI/src/Relocation/Transformers/Movement-analysis.C
Expand Up @@ -279,6 +279,7 @@ bool PCSensitiveTransformer::isPCSensitive(Instruction::Ptr insn,
const block_instance *block,
AssignList &sensitiveAssignments) {
if (!(insn->getOperation().getID() == e_call)) return false;
if(func->obj()->hybridMode() == BPatch_normalMode) return false;
// FIXME for loopnz instruction
Absloc pc = Absloc::makePC(func->ifunc()->isrc()->getArch());

Expand Down Expand Up @@ -376,7 +377,7 @@ Graph::Ptr PCSensitiveTransformer::forwardSlice(Assignment::Ptr ptr,
parse_block *block,
parse_func *func) {
M_A_Predicates pred;
Slicer slicer(ptr, block, func);
Slicer slicer(ptr, block, func, false, false);

Graph::Ptr g = slicer.forwardSlice(pred);
return g;
Expand Down
2 changes: 1 addition & 1 deletion dyninstAPI/src/Relocation/Transformers/Movement-analysis.h
Expand Up @@ -97,7 +97,7 @@ class PCSensitiveTransformer : public Transformer {
virtual bool process(RelocBlock *, RelocGraph *);

PCSensitiveTransformer(AddressSpace *as, PriorityMap &p)
: aConverter(false), addrSpace(as), priMap(p),
: aConverter(false, false), addrSpace(as), priMap(p),
Sens_(0), extSens_(0), intSens_(0), thunk_(0), overApprox_(0), adhoc(as) {};
virtual ~PCSensitiveTransformer() {};

Expand Down
2 changes: 1 addition & 1 deletion dyninstAPI/src/addressSpace.h
Expand Up @@ -186,7 +186,7 @@ class AddressSpace : public InstructionSource {
virtual void addTrap(Address from, Address to, codeGen &gen) = 0;
virtual void removeTrap(Address from) = 0;

bool getDyninstRTLibName();
virtual bool getDyninstRTLibName();

// InstructionSource
virtual bool isValidAddress(const Address) const;
Expand Down
2 changes: 1 addition & 1 deletion dyninstAPI/src/binaryEdit.h
Expand Up @@ -191,6 +191,7 @@ class BinaryEdit : public AddressSpace {

virtual void addTrap(Address from, Address to, codeGen &gen);
virtual void removeTrap(Address /*from*/) {};
static bool getResolvedLibraryPath(const std::string &filename, std::vector<std::string> &paths);

private:
Address highWaterMark_;
Expand All @@ -200,7 +201,6 @@ class BinaryEdit : public AddressSpace {
static bool getStatFileDescriptor(const std::string &file,
fileDescriptor &desc);

static bool getResolvedLibraryPath(const std::string &filename, std::vector<std::string> &paths);

bool inferiorMallocStatic(unsigned size);

Expand Down
1 change: 1 addition & 0 deletions dyninstAPI/src/dynProcess.h
Expand Up @@ -101,6 +101,7 @@ class PCProcess : public AddressSpace {
~PCProcess();

static std::string createExecPath(const std::string &file, const std::string &dir);
virtual bool getDyninstRTLibName();

bool continueProcess();
bool stopProcess();
Expand Down
2 changes: 1 addition & 1 deletion dyninstAPI/src/hybridOverwrites.C
Expand Up @@ -1343,7 +1343,7 @@ bool HybridAnalysisOW::isRealStore(Address insnAddr, block_instance *block,
Address image_addr = func->lowlevel_func()->addrToOffset(insnAddr);

std::vector<Assignment::Ptr> assignments;
AssignmentConverter aConverter(false);
AssignmentConverter aConverter(false, false);
aConverter.convert(insn, image_addr, imgfunc, block->llb(), assignments);

for (std::vector<Assignment::Ptr>::const_iterator a_iter = assignments.begin();
Expand Down
56 changes: 20 additions & 36 deletions dyninstAPI/src/image.C
Expand Up @@ -463,6 +463,7 @@ class FindMainVisitor : public ASTVisitor

virtual ASTPtr visit(DataflowAPI::VariableAST* v)
{

/* If we visit a variable node, we can't do any analysis */
hardFault = true;
resolved = false;
Expand Down Expand Up @@ -620,7 +621,6 @@ int image::findMain()
// p += (eAddr - eStart);
// }

bool mode_64 = false;
switch(linkedFile->getAddressWidth()) {
case 4:
// 32-bit...
Expand All @@ -629,7 +629,6 @@ int image::findMain()
ia32_set_mode_64(false);
break;
case 8:
mode_64 = true;
startup_printf("%s[%u]: setting 64-bit mode\n",
FILE__,__LINE__);
ia32_set_mode_64(true);
Expand Down Expand Up @@ -698,59 +697,44 @@ int image::findMain()
Block* b = e->src();
assert(b);

/* Get the address of the last instruction in the block (the call) */
Address insn_addr = b->lastInsnAddr();
void* insn_raw = region->getPtrToInstruction(insn_addr);
Block::Insns insns;
b->getInsns(insns);
if (insns.size() < 2) {
startup_printf("%s[%u]: should have at least two instructions\n", FILE__, __LINE__);
return -1;
}

/* Make sure insn_raw is valid */
if(!insn_raw)
{
startup_printf("%s[%u]: Error: no instruction pointer in region.\n",
FILE__, __LINE__);
return -1;
}

/* Needed to get the size of the call instruction */
instruction insn;
insn.setInstruction((const unsigned char*)insn_raw);

/* We also need the instructionAPI representation of the call instruction */
InstructionAPI::InstructionDecoder* decoder = NULL;
if(mode_64)
{
decoder = new InstructionAPI::InstructionDecoder(
insn_raw, insn.size(), Dyninst::Arch_x86_64);
} else {
decoder = new InstructionAPI::InstructionDecoder(
insn_raw, insn.size(), Dyninst::Arch_x86);
}

/* Decode just the call instruction */
InstructionAPI::Instruction::Ptr insn_ptr = decoder->decode(
(const unsigned char*)insn_raw);
// To get the secont to last instruction, which loads the address of main
auto iit = insns.end();
--iit;
--iit;

/* Let's get the assignment for this instruction. */
std::vector<Assignment::Ptr> assignments;
Dyninst::AssignmentConverter assign_convert(true, false);
assign_convert.convert(insn_ptr, insn_addr, func, b, assignments);
assign_convert.convert(iit->second, iit->first, func, b, assignments);
if(assignments.size() >= 1)
{
Assignment::Ptr assignment = *assignments.begin();

std::pair<AST::Ptr, bool> res = DataflowAPI::SymEval::expand(assignment, false);
AST::Ptr ast = res.first;
Assignment::Ptr assignment = assignments[0];
std::pair<AST::Ptr, bool> res = DataflowAPI::SymEval::expand(assignment, false);
AST::Ptr ast = res.first;
if(!ast)
{
/* expand failed */
mainAddress = 0x0;
startup_printf("%s[%u]: cannot expand %s from instruction %s\n", FILE__, __LINE__, assignment->format().c_str(), assignment->insn()->format().c_str());
} else {
startup_printf("%s[%u]: try to visit %s\n", FILE__, __LINE__, ast->format().c_str());
FindMainVisitor fmv;
ast->accept(&fmv);
if(fmv.resolved)
{
mainAddress = fmv.target;
} else {
mainAddress = 0x0;
startup_printf("%s[%u]: FindMainVisitor cannot find main address in %s\n", FILE__, __LINE__, ast->format().c_str());

}
}
}
Expand Down
9 changes: 6 additions & 3 deletions dyninstAPI/src/linux.C
Expand Up @@ -219,12 +219,14 @@ bool BinaryEdit::getResolvedLibraryPath(const string &filename, std::vector<stri
}

// search ld.so.cache
boost::shared_ptr<FILE> ldconfig(popen("/sbin/ldconfig -p", "r"), pclose);
// apparently ubuntu doesn't like pclosing NULL, so a shared pointer custom
// destructor is out. Ugh.
FILE* ldconfig = popen("/sbin/ldconfig -p", "r");
if (ldconfig) {
if(!fgets(buffer, 512, ldconfig.get())) { // ignore first line
if(!fgets(buffer, 512, ldconfig)) { // ignore first line
return false;
}
while (fgets(buffer, 512, ldconfig.get()) != NULL) {
while (fgets(buffer, 512, ldconfig) != NULL) {
pos = buffer;
while (*pos == ' ' || *pos == '\t') pos++;
key = pos;
Expand All @@ -240,6 +242,7 @@ bool BinaryEdit::getResolvedLibraryPath(const string &filename, std::vector<stri
paths.push_back(val);
}
}
pclose(ldconfig);
}

// search hard-coded system paths
Expand Down

0 comments on commit 6fac704

Please sign in to comment.