From d0ba340d74f03cff12ba015d4457830445417bbb Mon Sep 17 00:00:00 2001 From: clc5q <clc5q@git.zephyr-software.com> Date: Mon, 5 Oct 2015 03:03:11 +0000 Subject: [PATCH] Emit BELONGTO annotations and FROMUNKNOWN *.STARSxrefs annotations for apparently unreachable blocks in functions with resolved indirect branches but no unresolved indirect branches to link to. Former-commit-id: 4a667610e5c9d98f81d220dfd75638b85216d396 --- include/base/SMPFunction.h | 2 +- include/interfaces/abstract/STARSProgram.h | 1 + src/base/SMPFunction.cpp | 26 ++++++++++++++++--- src/interfaces/abstract/STARSProgram.cpp | 7 +++++ ...ed-save-busybox.psexe.annot.REMOVED.git-id | 2 +- ...ted-save-ffmpeg.psexe.annot.REMOVED.git-id | 2 +- ...-keyring-daemon.psexe.annot.REMOVED.git-id | 2 +- ...-system-monitor.psexe.annot.REMOVED.git-id | 2 +- ...orted-save-grep.psexe.annot.REMOVED.git-id | 2 +- ...rted-save-httpd.psexe.annot.REMOVED.git-id | 2 +- ...orted-save-less.psexe.annot.REMOVED.git-id | 2 +- ...d-save-synaptic.psexe.annot.REMOVED.git-id | 2 +- ...rted-save-xedit.psexe.annot.REMOVED.git-id | 2 +- 13 files changed, 40 insertions(+), 14 deletions(-) diff --git a/include/base/SMPFunction.h b/include/base/SMPFunction.h index f3df1f03..1167a64e 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 d13481e4..afc7de01 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 4efccb45..425370ef 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 30452f39..82d46cfe 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 a32081bd..e92ec3bf 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 317b58c7..5b9f18d8 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 cfb92049..5aa0831e 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 750e5aaa..50df6fa5 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 680c2abb..9944f12b 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 467cf8e4..a7b92d8b 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 f5104265..6077270c 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 71805e6f..4390eb91 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 bf34ab5e..3d39841c 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 -- GitLab