From fd0451c70513303de0ae0d061ed3f8d1516640bf Mon Sep 17 00:00:00 2001
From: Jason Hiser <jdhiser@gmail.com>
Date: Thu, 1 Aug 2019 11:33:48 -0400
Subject: [PATCH] updated to elide setting address to 0 when applying pcrel
 reloc.  pcrel reloc now ignores virtualOffset field

---
 irdb-libs/ir_builders/fix_calls.cpp    | 19 ++++++++++++++-----
 irdb-libs/libIRDB-cfg/src/domgraph.cpp |  2 +-
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/irdb-libs/ir_builders/fix_calls.cpp b/irdb-libs/ir_builders/fix_calls.cpp
index ff650611c..2e2f97ab5 100644
--- a/irdb-libs/ir_builders/fix_calls.cpp
+++ b/irdb-libs/ir_builders/fix_calls.cpp
@@ -782,6 +782,9 @@ class FixCalls_t : public TransformStep_t
 			if(virt_offset == 0 || virt_offset == (uintptr_t)-1)
 				return;
 
+			// do verbosity output
+			const auto verbose_fix_calls = getenv("VERBOSE_FIX_CALLS") != nullptr;
+
 			const auto cur_relocs     = insn->getRelocations();
 			const auto pcrel_reloc_it = find_if(ALLOF(cur_relocs), [](const Relocation_t* r) { return r->getType()=="pcrel"; });
 			if(pcrel_reloc_it != end(cur_relocs)) return; // already exists.
@@ -806,7 +809,7 @@ class FixCalls_t : public TransformStep_t
 						// figure out how to rewrite pcrel arm insns, then change the virt addr
 						// insn->getAddress()->setVirtualOffset(0);	
 						// for now, we aren't doing this... we may need to for doing xforms.
-						if(getenv("VERBOSE_FIX_CALLS"))
+						if(verbose_fix_calls)
 							cout << "Detected arm32/64 pc-rel operand in " << disasm->getDisassembly()  << endl;
 					}
 					else if(mt==admtX86_64 ||  mt==admtI386)
@@ -861,13 +864,19 @@ class FixCalls_t : public TransformStep_t
 						data.replace(0, data.length(), cstr, data.length());
 						insn->setDataBits(data);
 
-						other_fixes++;
+#if 0
+						// and it's important to set the VO to 0, so that the pcrel-ness is calculated correctly.
+						insn->getAddress()->setVirtualOffset(0);	
+#endif
 
-						if(getenv("VERBOSE_FIX_CALLS"))
+						// log
+						if(verbose_fix_calls)
 							cout << " Converted to: " << insn->getDisassembly() << endl;
 
-						// and it's important to set the VO to 0, so that the pcrel-ness is calculated correctly.
-						insn->getAddress()->setVirtualOffset(0);	
+						// keep up with stats.
+						other_fixes++;
+
+
 					}
 					else
 						throw std::invalid_argument("Unknown architecture in fix_other_pcrel");
diff --git a/irdb-libs/libIRDB-cfg/src/domgraph.cpp b/irdb-libs/libIRDB-cfg/src/domgraph.cpp
index 36a10b4ce..9c90080ba 100644
--- a/irdb-libs/libIRDB-cfg/src/domgraph.cpp
+++ b/irdb-libs/libIRDB-cfg/src/domgraph.cpp
@@ -76,7 +76,7 @@ DominatorGraph_t::DominatorGraph_t(const ControlFlowGraph_t* p_cfg, bool needs_p
 
 /*
 
-algorithm from advanced compiler design & impelmentation, Mucnick, 2nd edition page 18
+algorithm from advanced compiler design & impelmentation, Mucnick, 2nd edition page 186
 
 procedure Dom_Comp(N,Pred,r) returns Node-> set of Node
 	N: in set of Node
-- 
GitLab