public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: James E Wilson <wilson@specifix.com>
To: binutils@sourceware.org
Subject: m68k disassembler bug in error handling support
Date: Sat, 29 Apr 2006 17:51:00 -0000	[thread overview]
Message-ID: <1146280330.15759.389.camel@aretha.corp.specifix.com> (raw)

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

I noticed this while talking to Ben Elliston about PR 1298.

In the file opcodes/m68k-dis.c, in the function match_insn_m68k, there
is code to handle an error return from print_insn_m68k.  This prints an
error message and then exits with an error code.  However, we disabled
printing right before the print_insn_m68k call, so no error message will
ever be printed here.  We need to restore the print functions before we
try to print the error message.

This is trivial to demonstrate by modifying print_insn_arg to return -2
unconditionally, and then running the disassembler on some m68k code. 
Unpatched and patched results are attached.

I tested this with a x86_64-x-m68k-elf cross binutils.  There were no
regressions.  I went ahead and checked in the bug fix patch.
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com

[-- Attachment #2: result.unpatched --]
[-- Type: text/plain, Size: 260 bytes --]

aretha$ cat tmp.s
        movl $d0, $d1
        movl $d0, $d1
aretha$ ./as-new tmp.s
aretha$ ../binutils/objdump -d a.out
 
a.out:     file format elf32-m68k
 
Disassembly of section .text:
 
00000000 <.text>:
   0:   23f9
        ...
   a:   23f9
        ...

[-- Attachment #3: result.patched --]
[-- Type: text/plain, Size: 376 bytes --]

aretha$ cat tmp.s
        movl $d0, $d1
        movl $d0, $d1
aretha$ ./as-new tmp.s
aretha$ ../binutils/objdump -d a.out
 
a.out:     file format elf32-m68k
 
Disassembly of section .text:
 
00000000 <.text>:
   0:   23f9            <internal error in opcode table: movel *l%d>
 
        ...
   a:   23f9            <internal error in opcode table: movel *l%d>
 
        ...

[-- Attachment #4: patch.induce.bug --]
[-- Type: text/x-patch, Size: 488 bytes --]

Index: m68k-dis.c
===================================================================
RCS file: /cvs/src/src/opcodes/m68k-dis.c,v
retrieving revision 1.21
diff -p -p -r1.21 m68k-dis.c
*** m68k-dis.c	7 Feb 2006 19:01:10 -0000	1.21
--- m68k-dis.c	29 Apr 2006 02:58:02 -0000
*************** print_insn_arg (const char *d,
*** 584,589 ****
--- 584,591 ----
    bfd_signed_vma disp;
    unsigned int uval;
  
+   return -2;
+ 
    switch (*d)
      {
      case 'c':		/* Cache identifier.  */

[-- Attachment #5: patch.print.error --]
[-- Type: text/plain, Size: 1222 bytes --]

2006-04-28  James E Wilson  <wilson@specifix.com>

	* m68k-dis.c (match_insn_m68k): Restore fprintf_func before printing
	error message.

Index: m68k-dis.c
===================================================================
RCS file: /cvs/src/src/opcodes/m68k-dis.c,v
retrieving revision 1.21
diff -p -p -r1.21 m68k-dis.c
*** m68k-dis.c	7 Feb 2006 19:01:10 -0000	1.21
--- m68k-dis.c	29 Apr 2006 02:46:14 -0000
*************** match_insn_m68k (bfd_vma memaddr,
*** 1308,1319 ****
  	}
        else
  	{
  	  info->fprintf_func (info->stream,
  			      /* xgettext:c-format */
  			      _("<internal error in opcode table: %s %s>\n"),
  			      best->name,  best->args);
- 	  info->fprintf_func = save_printer;
- 	  info->print_address_func = save_print_address;
  	  return 2;
  	}
      }
--- 1308,1321 ----
  	}
        else
  	{
+ 	  /* We must restore the print functions before trying to print the
+ 	     error message.  */
+ 	  info->fprintf_func = save_printer;
+ 	  info->print_address_func = save_print_address;
  	  info->fprintf_func (info->stream,
  			      /* xgettext:c-format */
  			      _("<internal error in opcode table: %s %s>\n"),
  			      best->name,  best->args);
  	  return 2;
  	}
      }

                 reply	other threads:[~2006-04-29  3:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1146280330.15759.389.camel@aretha.corp.specifix.com \
    --to=wilson@specifix.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).