Re: [RFA] fix for intel disassembly, truncated BFD_VMA

H.J. Lu
2016-02-16T00:07:32Z

[-- Attachment #1: Type: text/plain, Size: 2169 bytes --]

On Wed, Feb 9, 2011 at 10:43 AM, Michael Snyder <msnyder@vmware.com> wrote:
> H.J. Lu wrote:
>>
>> On Wed, Feb 9, 2011 at 10:36 AM, Michael Snyder <msnyder@vmware.com>
>> wrote:
>>>
>>> This expression needed parentheses. Without them, it was truncating the
>>> target address of jumps and calls from BFD_VMA to 32-bits.
>>>
>>> Disassembly at high addresses is vastly improved.
>>>
>>>
>>> 2011-02-09 Michael Snyder <msnyder@vmware.com>
>>>
>>> * i386-dis.c (OP_J): Parenthesize expression to prevent
>>> truncated addresses.
>>> (print_insn): Fix indentation off-by-one.
>>>
>>> Index: i386-dis.c
>>> ===================================================================
>>> RCS file: /cvs/src/src/opcodes/i386-dis.c,v
>>> retrieving revision 1.257
>>> diff -u -p -u -p -r1.257 i386-dis.c
>>> --- i386-dis.c 18 Jan 2011 17:08:13 -0000 1.257
>>> +++ i386-dis.c 9 Feb 2011 18:28:02 -0000
>>> @@ -1,6 +1,6 @@
>>> /* Print i386 instructions for GDB, the GNU debugger.
>>> Copyright 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
>>> - 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
>>> + 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
>>> Free Software Foundation, Inc.
>>>
>>> This file is part of the GNU opcodes library.
>>> @@ -11702,9 +11702,9 @@ print_insn (bfd_vma pc, disassemble_info
>>> modrm.rm = *codep & 7;
>>> }
>>>
>>> - need_vex = 0;
>>> - need_vex_reg = 0;
>>> - vex_w_done = 0;
>>> + need_vex = 0;
>>> + need_vex_reg = 0;
>>> + vex_w_done = 0;
>>>
>>> if (dp->name == NULL && dp->op[0].bytemode == FLOATCODE)
>>> {
>>> @@ -13817,7 +13817,7 @@ OP_J (int bytemode, int sizeflag)
>>> oappend (INTERNAL_DISASSEMBLER_ERROR);
>>> return;
>>> }
>>> - disp = ((start_pc + codep - start_codep + disp) & mask) | segment;
>>> + disp = ((start_pc + (codep - start_codep) + disp) & mask) | segment;
>>> set_op (disp, 0);
>>> print_operand_value (scratchbuf, 1, disp);
>>> oappend (scratchbuf);
>>>
>>>
>>
>> OK.
>
>
> Thanks, committed.

I got a hit with a similar case. I checked this patch into trunk
and 2.26 branch.

--
H.J.

[-- Attachment #2: 0001-Add-parentheses-to-prevent-truncated-addresses.patch --]
[-- Type: text/x-patch, Size: 1703 bytes --]

From 89e1725d35e190ab3b746ff5491bc8bd35287f84 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Mon, 15 Feb 2016 15:58:42 -0800
Subject: [PATCH] Add parentheses to prevent truncated addresses

* i386-dis.c (print_insn): Parenthesize expression to prevent
truncated addresses.
(OP_J): Likewise.
---
opcodes/ChangeLog | 6 ++++++
opcodes/i386-dis.c | 4 ++--
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index 24c1680..e9f1578 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,3 +1,9 @@
+2016-02-15 H.J. Lu <hongjiu.lu@intel.com>
+
+ * i386-dis.c (print_insn): Parenthesize expression to prevent
+ truncated addresses.
+ (OP_J): Likewise.
+
2016-02-10 Claudiu Zissulescu <claziss@synopsys.com>
Janek van Oirschot <jvanoirs@synopsys.com>

diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c
index 5f4aed5..de0534c 100644
--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -13644,7 +13644,7 @@ print_insn (bfd_vma pc, disassemble_info *info)
if (op_index[i] != -1 && op_riprel[i])
{
(*info->fprintf_func) (info->stream, " # ");
- (*info->print_address_func) ((bfd_vma) (start_pc + codep - start_codep
+ (*info->print_address_func) ((bfd_vma) (start_pc + (codep - start_codep)
+ op_address[op_index[i]]), info);
break;
}
@@ -16158,7 +16158,7 @@ OP_J (int bytemode, int sizeflag)
the displacement is added! */
mask = 0xffff;
if ((prefixes & PREFIX_DATA) == 0)
- segment = ((start_pc + codep - start_codep)
+ segment = ((start_pc + (codep - start_codep))
& ~((bfd_vma) 0xffff));
}
if (address_mode != mode_64bit
--
2.5.0