diff --git a/include/base/SMPFunction.h b/include/base/SMPFunction.h index f3df1f039639e7e4244c95014103a7bbcae6e1b5..1167a64e1260ce756924b8ebd2a20afce68072f2 100644 --- a/include/base/SMPFunction.h +++ b/include/base/SMPFunction.h @@ -364,7 +364,7 @@ public: void ResetProcessedBlocks(void); // Set Processed flag to false in all blocks void ResetSCCPVisitedBlocks(void); // Set SCCPVisited flag to false in all blocks void RPONumberBlocks(void); // Number basic blocks in reverse post-order and place pointers in RPOBlocks. - void RemoveBlock(SMPBasicBlock *CurrBlock, std::list<SMPBasicBlock *>::iterator &BlockIter); // Remove a basic block and its instructions. + void RemoveBlock(SMPBasicBlock *CurrBlock, std::list<SMPBasicBlock *>::iterator &BlockIter, bool IBTarget = false); // Remove a basic block and its instructions. void RemoveCallingBlocks(void) const; // Func is empty, so add all blocks that call it to Program->BlocksPendingRemoval. void ComputeGlobalSets(void); // compute LiveOut, Kill sets for function void AnalyzeFunc(void); // Analyze all instructions in function diff --git a/include/interfaces/abstract/STARSProgram.h b/include/interfaces/abstract/STARSProgram.h index d13481e4a2cc3b3e2ee162d9718cbc041a1a1ac7..afc7de018037894057402c3731ada93264febd6e 100644 --- a/include/interfaces/abstract/STARSProgram.h +++ b/include/interfaces/abstract/STARSProgram.h @@ -81,6 +81,7 @@ class STARS_Program_t // Utility functions to print code xrefs to STARS_XrefsFile void PrintCodeToCodeXref(STARS_ea_t FromAddr, STARS_ea_t ToAddr, std::size_t InstrSize); void PrintDataToCodeXref(STARS_ea_t FromDataAddr, STARS_ea_t ToCodeAddr, std::size_t InstrSize); + void PrintUnknownCodeXref(STARS_ea_t ToAddr, std::size_t InstrSize); virtual void PrintAllCodeToCodeXrefs(STARS_ea_t InstAddr, std::size_t InstSize) = 0; // Analysis methods diff --git a/src/base/SMPFunction.cpp b/src/base/SMPFunction.cpp index 4efccb4562971960d9f0ad211feb8009c896d4d1..425370ef0755a798c02246f44c43dcecee8a6e64 100644 --- a/src/base/SMPFunction.cpp +++ b/src/base/SMPFunction.cpp @@ -5698,7 +5698,24 @@ bool SMPFunction::FindChainAliasHelper(list<SMPBasicBlock *>::iterator BlockIter } // end of SMPFunction::FindChainAliasHelper() // Remove a basic block and its instructions. -void SMPFunction::RemoveBlock(SMPBasicBlock *CurrBlock, list<SMPBasicBlock *>::iterator &BlockIter) { +void SMPFunction::RemoveBlock(SMPBasicBlock *CurrBlock, list<SMPBasicBlock *>::iterator &BlockIter, bool IBTarget) { + if (IBTarget) { + // Block could be IBTarget and thus actually be reachable. Cover our bases by emitting an IBT annotation. + SMPInstr *FirstInst = (*(CurrBlock->GetFirstInst())); + global_STARS_program->PrintUnknownCodeXref(CurrBlock->GetFirstAddr(), FirstInst->GetSize()); + + // It cannot hurt to add INSTR BELONGTO annotations to the main annotations file. + STARS_ea_t FuncAddr = this->GetFirstFuncAddr(); + FILE *AnnotFile = global_STARS_program->GetAnnotFile(); + assert(NULL != AnnotFile); + for (vector<SMPInstr *>::iterator InstIter = CurrBlock->GetFirstInst(); InstIter != CurrBlock->GetLastInst(); ++InstIter) { + SMPInstr *CurrInst = (*InstIter); + STARS_ea_t InstAddr = CurrInst->GetAddr(); + SMP_fprintf(AnnotFile, "%18llx %6zu INSTR BELONGTO %llx \n", + (unsigned long long) InstAddr, CurrInst->GetSize(), (unsigned long long) FuncAddr); + } + } + // Remove this block from the predecessors list of its successors. list<SMPBasicBlock *>::iterator SuccIter; STARS_ea_t TempAddr = CurrBlock->GetFirstAddr(); @@ -5714,6 +5731,7 @@ void SMPFunction::RemoveBlock(SMPBasicBlock *CurrBlock, list<SMPBasicBlock *>::i // Transfer the unreachable block to the program-wide container of unreachable code. this->GetProg()->AddUnreachableBlock(CurrBlock); + // Remove the unreachable instructions from the function inst list. vector<SMPInstr *>::iterator InstIter = CurrBlock->GetFirstInst(); STARS_ea_t FirstBadAddr = (*InstIter)->GetAddr(); @@ -5881,7 +5899,8 @@ void SMPFunction::SetLinks(void) { SMP_msg("INFO: Function is Removing unreachable block at %llx\n", (unsigned long long) CurrBlock->GetFirstAddr()); } - this->RemoveBlock(CurrBlock, BlockIter); + bool MightBeIndirectTarget = true; + this->RemoveBlock(CurrBlock, BlockIter, MightBeIndirectTarget); #if 0 // Exception handling code requires something more delicate than this. Later checks for stack adjustment etc. can look at these blocks. // Finally, call destructors on the block and insts removed. @@ -5897,9 +5916,8 @@ void SMPFunction::SetLinks(void) { else { // HellNodeCase // Block must be reachable only through an unresolved indirect branch. // Make each unresolved indirect branch link to the block so it is reachable. - list<SMPBasicBlock *>::iterator WorkIter; AddedMissingLinks = true; - for (WorkIter = UnresolvedBranchWorkList.begin(); WorkIter != UnresolvedBranchWorkList.end(); ++ WorkIter) { + for (list<SMPBasicBlock *>::iterator WorkIter = UnresolvedBranchWorkList.begin(); WorkIter != UnresolvedBranchWorkList.end(); ++WorkIter) { SMPBasicBlock *WorkBlock = (*WorkIter); WorkBlock->LinkToSucc(CurrBlock); } diff --git a/src/interfaces/abstract/STARSProgram.cpp b/src/interfaces/abstract/STARSProgram.cpp index 30452f39aaeea8d38041316888b685aaaab79057..82d46cfeab3abacf935428d9e6284fdf84c43f28 100644 --- a/src/interfaces/abstract/STARSProgram.cpp +++ b/src/interfaces/abstract/STARSProgram.cpp @@ -197,6 +197,7 @@ void STARS_Program_t::InitData(void) { ConstantDEFCount = 0; AlwaysTakenBranchCount = 0; NeverTakenBranchCount = 0; + LoopInvariantDEFCount = 0; SubwordRegCount = 0; SubwordMemCount = 0; SubwordAddressRegCount = 0; @@ -388,6 +389,12 @@ void STARS_Program_t::PrintDataToCodeXref(STARS_ea_t FromDataAddr, STARS_ea_t To return; } +void STARS_Program_t::PrintUnknownCodeXref(STARS_ea_t ToAddr, std::size_t InstrSize) { + SMP_fprintf(this->GetXrefsFile(), "%18llx %6zu INSTR XREF IBT FROMUNKNOWN \n", + (unsigned long long) ToAddr, InstrSize); + return; +} + // Read the foo.exe.policy file to initialize our security policies for system calls. void STARS_Program_t::ZST_InitPolicies(void) { string ZSTPolicyFileName(this->GetRootFileName()); diff --git a/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id index a32081bdc006a199083af1a08267df24a8bedbc4..e92ec3bfbaf40c815e5c2916a18d8693a7cab059 100644 --- a/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id +++ b/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id @@ -1 +1 @@ -c1ce9a28bae332d56f8b2632e733683802430009 \ No newline at end of file +c7e6e41e739c3a48fdb22883a9f7472fd0049d69 \ No newline at end of file diff --git a/tests/commit/trimmed-sorted-save-ffmpeg.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-ffmpeg.psexe.annot.REMOVED.git-id index 317b58c7214302a90b1cb7dd334328c2b44431b4..5b9f18d899f8ead60968dbbb743876252e14cc45 100644 --- a/tests/commit/trimmed-sorted-save-ffmpeg.psexe.annot.REMOVED.git-id +++ b/tests/commit/trimmed-sorted-save-ffmpeg.psexe.annot.REMOVED.git-id @@ -1 +1 @@ -923578564814ffb4d04bdd98c8f50ae5913099ee \ No newline at end of file +adbb7c5587f18c7df6c886dc5cbb6f3b0a3c8fc1 \ No newline at end of file diff --git a/tests/commit/trimmed-sorted-save-gnome-keyring-daemon.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-gnome-keyring-daemon.psexe.annot.REMOVED.git-id index cfb920490057dd021cdfed27cbbdcad0470fe931..5aa0831e990d05dc11ddae01cef3d721f516cc7e 100644 --- a/tests/commit/trimmed-sorted-save-gnome-keyring-daemon.psexe.annot.REMOVED.git-id +++ b/tests/commit/trimmed-sorted-save-gnome-keyring-daemon.psexe.annot.REMOVED.git-id @@ -1 +1 @@ -3536c66f9100e048225e97efe58e35919fd2c7d1 \ No newline at end of file +72ecc82bb0ff731606efa24f8f221c0c753c4c6b \ No newline at end of file diff --git a/tests/commit/trimmed-sorted-save-gnome-system-monitor.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-gnome-system-monitor.psexe.annot.REMOVED.git-id index 750e5aaa7dde99e9fd8892a210ae990c6fc4af8a..50df6fa5c04316407a1692bdc494b55891d9f2c3 100644 --- a/tests/commit/trimmed-sorted-save-gnome-system-monitor.psexe.annot.REMOVED.git-id +++ b/tests/commit/trimmed-sorted-save-gnome-system-monitor.psexe.annot.REMOVED.git-id @@ -1 +1 @@ -49f46e70b725844e589d3080d22ca3ed2948e0ab \ No newline at end of file +bae540f57290a329e4d82bc1e054f23a2d8d8eee \ No newline at end of file diff --git a/tests/commit/trimmed-sorted-save-grep.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-grep.psexe.annot.REMOVED.git-id index 680c2abb5d6bcd0c39ae910541e8c48ce1d66b7f..9944f12b5022d1260ae33e62324446956b01dc79 100644 --- a/tests/commit/trimmed-sorted-save-grep.psexe.annot.REMOVED.git-id +++ b/tests/commit/trimmed-sorted-save-grep.psexe.annot.REMOVED.git-id @@ -1 +1 @@ -79f17aa2383d9322ac7cecc33d456bd3d0be3a1d \ No newline at end of file +bba39a4d9cf29717b8235f9446ff14ef12263d14 \ No newline at end of file diff --git a/tests/commit/trimmed-sorted-save-httpd.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-httpd.psexe.annot.REMOVED.git-id index 467cf8e42196bcc406c395c9113f7918795418e9..a7b92d8b482825264087a5ac0db73712a88aca41 100644 --- a/tests/commit/trimmed-sorted-save-httpd.psexe.annot.REMOVED.git-id +++ b/tests/commit/trimmed-sorted-save-httpd.psexe.annot.REMOVED.git-id @@ -1 +1 @@ -1e25021cd38d9d41c1a7d116b0df0b822999e8e9 \ No newline at end of file +8189b0ce26fe4cd7253e3c3ef0d65d301288f64b \ No newline at end of file diff --git a/tests/commit/trimmed-sorted-save-less.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-less.psexe.annot.REMOVED.git-id index f51042651050f3bc22f4bb3792f0751e28d514cd..6077270c4fb10b05ff2d89080ae08bb1045e6f40 100644 --- a/tests/commit/trimmed-sorted-save-less.psexe.annot.REMOVED.git-id +++ b/tests/commit/trimmed-sorted-save-less.psexe.annot.REMOVED.git-id @@ -1 +1 @@ -939982e16244197438b57be806fceb5ced72090a \ No newline at end of file +2f43af66d9e890ffabd27b78774a2e39a2fe7d4d \ No newline at end of file diff --git a/tests/commit/trimmed-sorted-save-synaptic.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-synaptic.psexe.annot.REMOVED.git-id index 71805e6fc7fc181c642afa7623f557f7e6687bde..4390eb91a384bda0d1104848628dfe28b1e49bcc 100644 --- a/tests/commit/trimmed-sorted-save-synaptic.psexe.annot.REMOVED.git-id +++ b/tests/commit/trimmed-sorted-save-synaptic.psexe.annot.REMOVED.git-id @@ -1 +1 @@ -0be8f380ac953c404041e8933eb64fb20408792f \ No newline at end of file +2be79abe1a336faec41d2f7001e91275857b3305 \ No newline at end of file diff --git a/tests/commit/trimmed-sorted-save-xedit.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-xedit.psexe.annot.REMOVED.git-id index bf34ab5e5f25063623d87e05292f837f7d35f82b..3d39841ca80d318eac30b3b0a6f0cab27457ec4b 100644 --- a/tests/commit/trimmed-sorted-save-xedit.psexe.annot.REMOVED.git-id +++ b/tests/commit/trimmed-sorted-save-xedit.psexe.annot.REMOVED.git-id @@ -1 +1 @@ -c9d7626b2f940434f19eafefecb39f89b4fa1863 \ No newline at end of file +0eb9db4077cbc94208edd6a90ea64b087964ce7a \ No newline at end of file