m68k disassembler bug in error handling support

James E Wilson wilson@specifix.com
Sat Apr 29 17:51:00 GMT 2006


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
-------------- next part --------------
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
        ...
-------------- next part --------------
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>
 
        ...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.induce.bug
Type: text/x-patch
Size: 488 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20060429/fc9b1e7f/attachment.bin>
-------------- next part --------------
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;
  	}
      }


More information about the Binutils mailing list