From c60a86a4985e99f7fd3f0f16bfe5e12876a15127 Mon Sep 17 00:00:00 2001
From: clc5q <clc5q@git.zephyr-software.com>
Date: Tue, 9 Aug 2011 05:32:59 +0000
Subject: [PATCH] Handle indirect calls within functions.

---
 SMPFunction.cpp       | 13 +++++++++----
 SMPStaticAnalyzer.cpp |  3 +++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/SMPFunction.cpp b/SMPFunction.cpp
index de400ef8..f04fdb11 100644
--- a/SMPFunction.cpp
+++ b/SMPFunction.cpp
@@ -2476,8 +2476,10 @@ void SMPFunction::SetLinks(void) {
 	//  we cannot conclude that a block with no predecessors is unreachable. Also, the block
 	//  order might be such that removal of a block makes an already processed block
 	//  unreachable, so we have to iterate until there are no more changes.
+	// NOTE: An odd new gcc recursion optimization uses indirect calls within the function, so
+	//  they can behave like indirect jumps.
 #if SMP_USE_SWITCH_TABLE_INFO
-	if (!(this->HasUnresolvedIndirectJumps())) {
+	if (!(this->HasUnresolvedIndirectJumps() || this->HasUnresolvedIndirectCalls())) {
 #else
 	if (!(this->HasIndirectJumps())) {
 #endif
@@ -2629,10 +2631,13 @@ void SMPFunction::RPONumberBlocks(void) {
 	//  (no predecessors from SetLinks() because they are reached only via indirect
 	//  jumps). We need to number these and push them on the RPOBlocks vector so
 	//  that the vector contains all the blocks.
-	if (this->HasIndirectJumps()) {
+	// NOTE: Odd new gcc recursion optimization seems to use indirect calls to reach
+	//  some blocks within a recursive function, operating somewhat like an indirect
+	//  jump.
+	if (this->HasIndirectJumps() || this->HasIndirectCalls()) {
 		for (CurrBlock = this->Blocks.begin(); CurrBlock != this->Blocks.end(); ++CurrBlock) {
 			if (SMP_BLOCKNUM_UNINIT == CurrBlock->GetNumber()) {
-				msg("Numbering indirectly reachable block at %x\n", CurrBlock->GetFirstAddr());
+				msg("WARNING: Numbering indirectly reachable block at %x\n", CurrBlock->GetFirstAddr());
 				CurrBlock->SetNumber(CurrNum);
 				this->RPOBlocks.push_back(CurrBlock);
 				++CurrNum;
@@ -2773,7 +2778,7 @@ void SMPFunction::ComputeIDoms(void) {
 			}
 			if (NewIdom == SMP_BLOCKNUM_UNINIT) {
 				msg("Failure on NewIdom in ComputeIDoms for %s\n", this->GetFuncName());
-				if (this->HasIndirectJumps()) {
+				if (this->HasIndirectJumps() || this->HasIndirectCalls()) {
 					// Might be reachable only through indirect jumps.
 					NewIdom = 0; // make it dominated by entry block
 				}
diff --git a/SMPStaticAnalyzer.cpp b/SMPStaticAnalyzer.cpp
index 31db49c7..666cfda5 100644
--- a/SMPStaticAnalyzer.cpp
+++ b/SMPStaticAnalyzer.cpp
@@ -229,6 +229,9 @@ void IDAP_run(int arg) {
 #if SMP_DEBUG
 	msg("Beginning IDAP_run.\n");
 #endif
+
+	msg("IDA SDK version: %d \n", IDA_SDK_VERSION);
+
 	// Open the output file.
 	ssize_t FileLen;
 	FileLen = get_root_filename(RootFileName, sizeof(RootFileName) - 1);
-- 
GitLab