From 8186603a1c4588fae3bccba6e0f9382ea5da7be9 Mon Sep 17 00:00:00 2001 From: an7s <an7s@git.zephyr-software.com> Date: Wed, 3 Feb 2016 03:04:49 +0000 Subject: [PATCH] parse ib provenance data from the STARS xref file Former-commit-id: 9f4f704c3c1d759bb3c2cce9a6bee2e477132cc6 --- xform/instruction_descriptor.cpp | 29 +++++++++++++++++++++++++++++ xform/instruction_descriptor.h | 8 ++++++-- xform/rewriter.cpp | 26 +++++++++++++++++++++----- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/xform/instruction_descriptor.cpp b/xform/instruction_descriptor.cpp index 726744172..5d37f63f3 100644 --- a/xform/instruction_descriptor.cpp +++ b/xform/instruction_descriptor.cpp @@ -36,6 +36,7 @@ wahoo::Instruction::Instruction() m_isVisited = false; m_data = NULL; m_ib_complete=false; + m_ib_provenance = IB_PROVENANCE_UNKNOWN; } wahoo::Instruction::Instruction(app_iaddr_t p_address, int p_size, Function* p_func) @@ -50,6 +51,8 @@ wahoo::Instruction::Instruction(app_iaddr_t p_address, int p_size, Function* p_f m_deallocSite = false; m_stackRef = false; m_data = NULL; + m_ib_complete=false; + m_ib_provenance = IB_PROVENANCE_UNKNOWN; } wahoo::Instruction::~Instruction() @@ -84,3 +87,29 @@ void wahoo::Instruction::markVarStackRef() { m_varStackRef = true; } + +void wahoo::Instruction::setIbProvenance(char *p_provenance) +{ + std::string provenance(p_provenance); + + if (provenance == "RETURNTARGET") + { + m_ib_provenance = IB_PROVENANCE_RETURN; + } + else if (provenance == "SWITCHTABLE") + { + m_ib_provenance = IB_PROVENANCE_SWITCH_TABLE; + } + else if (provenance == "INDIRCALL") + { + m_ib_provenance = IB_PROVENANCE_INDIRECT_CALL; + } + else if (provenance == "UNKNOWN") + { + m_ib_provenance = IB_PROVENANCE_UNKNOWN; + } + else + { + m_ib_provenance = IB_PROVENANCE_UNKNOWN; + } +} diff --git a/xform/instruction_descriptor.h b/xform/instruction_descriptor.h index 373788808..c10da9296 100644 --- a/xform/instruction_descriptor.h +++ b/xform/instruction_descriptor.h @@ -13,6 +13,8 @@ namespace wahoo { class Function; +enum IBProvenance { IB_PROVENANCE_UNKNOWN, IB_PROVENANCE_RETURN, IB_PROVENANCE_SWITCH_TABLE, IB_PROVENANCE_INDIRECT_CALL }; + class Instruction { public: Instruction(); @@ -52,6 +54,9 @@ class Instruction { const std::set<Instruction*>& getIBTs() { return ibts; } void markIbComplete(bool complete=true) { m_ib_complete=complete; } bool isIbComplete() { return m_ib_complete; } + void setIbProvenance(char *); + void setIbProvenance(const IBProvenance p_provenance) { m_ib_provenance = p_provenance; } + IBProvenance getIbProvenance() const { return m_ib_provenance; } private: app_iaddr_t m_address; @@ -59,7 +64,6 @@ class Instruction { int m_size; Function* m_function; string m_asm; -// unsigned char m_data[128]; unsigned char* m_data; bool m_allocSite; @@ -71,7 +75,7 @@ class Instruction { std::set<Instruction*> ibts; bool m_ib_complete; - + IBProvenance m_ib_provenance; }; } diff --git a/xform/rewriter.cpp b/xform/rewriter.cpp index dac766a71..043257338 100644 --- a/xform/rewriter.cpp +++ b/xform/rewriter.cpp @@ -669,6 +669,16 @@ void Rewriter::readXrefsFile(char p_filename[]) break; // check for instr xref ibt +/* + 4280c0 1 INSTR XREF IBT FROMIB 426558 RETURNTARGET + 426614 1 INSTR XREF IBT FROMIB 426580 RETURNTARGET + 4280c0 1 INSTR XREF IBT FROMIB 426580 RETURNTARGET + 4269d2 1 INSTR XREF IBT FROMIB 42689c RETURNTARGET + 4432bd 1 INSTR XREF IBT FROMIB 42689c RETURNTARGET + 447d4f 1 INSTR XREF IBT FROMIB 42689c RETURNTARGET + 42689c 1 INSTR XREF FROMIB COMPLETE 3 RETURNTARGET +*/ + if(string("IBT")==string(ibt)) { fscanf(fin, "%s", fromib); @@ -685,9 +695,10 @@ void Rewriter::readXrefsFile(char p_filename[]) instr->setIBTAddress(addr); if(strcmp(fromib,"FROMIB")==0) { + char provenance[200]; // get the from point into memory. app_iaddr_t from_addr = 0; - fscanf(fin, "%p", (void**)&from_addr); + fscanf(fin, "%p %s", (void**)&from_addr, provenance); if(feof(fin)) // deal with blank lines at the EOF break; @@ -697,6 +708,7 @@ void Rewriter::readXrefsFile(char p_filename[]) // record in the IR listing. from_instr->addIBT(instr); + from_instr->setIbProvenance(provenance); } } } @@ -706,17 +718,21 @@ void Rewriter::readXrefsFile(char p_filename[]) // annotations can come in any order so the COMPLETE annotation for IB targets // can come before/after the targets themselves // in this loop, just keep track of instructions w/ complete targets - // 4004b6 1 INSTR XREF FROMIB COMPLETE 1 + // 4004b6 1 INSTR XREF FROMIB COMPLETE 1 <provenance> char complete[200]; fscanf(fin, "%s", complete); + if(feof(fin)) // deal with blank lines at the EOF + break; if(strcmp(complete,"COMPLETE")==0) { + char provenance[200]; + int num_targets; completeIBT.insert(addr); + fscanf(fin, "%d %s", &num_targets, provenance); + if(feof(fin)) // deal with blank lines at the EOF + break; } - - if(feof(fin)) // deal with blank lines at the EOF - break; } char remainder[2000]; -- GitLab