[DynInst_API:] [PATCH] common: Skip get_immediate_operand without any imm


Date: Mon, 27 Jan 2014 18:29:50 -0800
From: Josh Stone <jistone@xxxxxxxxxx>
Subject: [DynInst_API:] [PATCH] common: Skip get_immediate_operand without any imm
For x86 image::findMain, we blindly look for the first call from the
entry address, then grab the immediate operand from the preceding
instruction.  Sometimes that instruction may not even have any immediate
operands, and the heuristic fails with a message on stderr like:

  arch-x86.C[5602]:  invalid immediate size 0 in insn

This now occurs with some ET_DYN binaries that are allowed by commit
44205dbd2d90, when those are really DSOs and not PIE.  However, this
could conceivably also happen for any executable that doesn't fit the
heuristic pattern.

This patch quietly returns 0 from get_immediate_operand when there are
no operands, and image::findMain will treat this as an invalid address.
---
 common/src/arch-x86.C | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/common/src/arch-x86.C b/common/src/arch-x86.C
index a227c8d29214..cfcf355b4c8a 100644
--- a/common/src/arch-x86.C
+++ b/common/src/arch-x86.C
@@ -5581,6 +5581,9 @@ Address get_immediate_operand(instruction *instr)
 
     ia32_decode(IA32_FULL_DECODER,(const unsigned char *)(instr->ptr()),detail);
 
+    if (loc.imm_cnt < 1)
+      return 0;
+
     // now find the immediate value in the locations
     Address immediate = 0;
 
-- 
1.8.5.3

[← Prev in Thread] Current Thread [Next in Thread→]
  • [DynInst_API:] [PATCH] common: Skip get_immediate_operand without any imm, Josh Stone <=