This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: objdump infinite loop on v850 object file


On Mon, Oct 04, 2010 at 12:33:49PM +0100, Lee Moore wrote:
> http://lists.gnu.org/archive/html/bug-binutils/2010-10/msg00037.html
> v850-elf-objdump -D asmtest.exe ;# WARNING - infinite loop
> 
> please let me know how to fix this issue

opcodes/v850-dis.c:print_insn_v850 is returning zero.  It is supposed
to return the number of bytes disassembled, or a negative value on
error.  That needs fixing by someone who cares about v850.  (You,
perhaps?)

The following patch reports an error if backend disassembler functions
return bad status like this, and fixes a few other issues I noticed.

	* bucomm.c (bfd_nonfatal): Flush stdout before output to stderr.
	(bfd_nonfatal_message, report, list_matching_formats): Likewise.
	(list_supported_targets): Tidy.
	* objdump.c (free_only_list): Formatting.
	(slurp_dynamic_symtab): Non-zero exit status for "not a dynamic
	object".
	(update_source_path): Delete redundant check for NULL filename.
	(disassemble_bytes): Error if disassemble_fn returns a value
	that won't increment address.
	(disassemble_data): Don't capitalize error message.
	(read_section_stabs): Likewise.
	(main): Return non-zero exit status on bad options.
	
Index: binutils/bucomm.c
===================================================================
RCS file: /cvs/src/src/binutils/bucomm.c,v
retrieving revision 1.39
diff -u -p -r1.39 bucomm.c
--- binutils/bucomm.c	11 Dec 2009 13:42:05 -0000	1.39
+++ binutils/bucomm.c	5 Oct 2010 03:07:22 -0000
@@ -52,8 +52,10 @@ char *program_name;
 void
 bfd_nonfatal (const char *string)
 {
-  const char *errmsg = bfd_errmsg (bfd_get_error ());
+  const char *errmsg;
 
+  fflush (stdout);
+  errmsg = bfd_errmsg (bfd_get_error ());
   if (string)
     fprintf (stderr, "%s: %s: %s\n", program_name, string, errmsg);
   else
@@ -78,10 +80,13 @@ bfd_nonfatal_message (const char *filena
 		      const asection *section,
 		      const char *format, ...)
 {
-  const char *errmsg = bfd_errmsg (bfd_get_error ());
-  const char *section_name = NULL;
+  const char *errmsg;
+  const char *section_name;
   va_list args;
 
+  fflush (stdout);
+  errmsg = bfd_errmsg (bfd_get_error ());
+  section_name = NULL;
   va_start (args, format);
   fprintf (stderr, "%s", program_name);
   
@@ -116,6 +121,7 @@ bfd_fatal (const char *string)
 void
 report (const char * format, va_list args)
 {
+  fflush (stdout);
   fprintf (stderr, "%s: ", program_name);
   vfprintf (stderr, format, args);
   putc ('\n', stderr);
@@ -165,6 +171,7 @@ set_default_bfd_target (void)
 void
 list_matching_formats,  (char **p)
 {
+  fflush (stdout);
   fprintf (stderr, _("%s: Matching formats:"), program_name);
   while (*p)
     fprintf (stderr, " %s", *p++);
@@ -177,13 +184,14 @@ void
 list_supported_targets (const char *name, FILE *f)
 {
   int t;
-  const char **targ_names = bfd_target_list ();
+  const char **targ_names;
 
   if (name == NULL)
     fprintf (f, _("Supported targets:"));
   else
     fprintf (f, _("%s: supported targets:"), name);
 
+  targ_names = bfd_target_list ();
   for (t = 0; targ_names[t] != NULL; t++)
     fprintf (f, " %s", targ_names[t]);
   fprintf (f, "\n");
Index: binutils/objdump.c
===================================================================
RCS file: /cvs/src/src/binutils/objdump.c,v
retrieving revision 1.176
diff -u -p -r1.176 objdump.c
--- binutils/objdump.c	2 Sep 2010 22:35:18 -0000	1.176
+++ binutils/objdump.c	5 Oct 2010 03:07:23 -0000
@@ -393,7 +393,8 @@ free_only_list (void)
     {
       if (! at_least_one_seen)
 	{
-	  non_fatal (_("Section '%s' mentioned in a -j option, but not found in any input file"),
+	  non_fatal (_("section '%s' mentioned in a -j option, "
+		       "but not found in any input file"),
 		     only->name);
 	  exit_status = 1;
 	}
@@ -555,6 +556,7 @@ slurp_dynamic_symtab (bfd *abfd)
       if (!(bfd_get_file_flags (abfd) & DYNAMIC))
 	{
 	  non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd));
+	  exit_status = 1;
 	  dynsymcount = 0;
 	  return NULL;
 	}
@@ -1210,9 +1212,6 @@ update_source_path (const char *filename
   const char *fname;
   int i;
 
-  if (filename == NULL)
-    return NULL;
-
   p = try_print_file_open (filename, filename);
   if (p != NULL)
     return p;
@@ -1626,10 +1625,16 @@ disassemble_bytes (struct disassemble_in
 	      inf->stream = stdout;
 	      if (insn_width == 0 && inf->bytes_per_line != 0)
 		octets_per_line = inf->bytes_per_line;
-	      if (octets < 0)
+	      if (octets < (int) opb)
 		{
 		  if (sfile.pos)
 		    printf ("%s\n", sfile.buffer);
+		  if (octets >= 0)
+		    {
+		      non_fatal (_("disassemble_fn returned length %d"),
+				 octets);
+		      exit_status = 1;
+		    }
 		  break;
 		}
 	    }
@@ -2107,7 +2112,7 @@ disassemble_data (bfd *abfd)
       const bfd_arch_info_type *inf = bfd_scan_arch (machine);
 
       if (inf == NULL)
-	fatal (_("Can't use supplied machine %s"), machine);
+	fatal (_("can't use supplied machine %s"), machine);
 
       abfd->arch_info = inf;
     }
@@ -2126,7 +2131,7 @@ disassemble_data (bfd *abfd)
   aux.disassemble_fn = disassembler (abfd);
   if (!aux.disassemble_fn)
     {
-      non_fatal (_("Can't disassemble for architecture %s\n"),
+      non_fatal (_("can't disassemble for architecture %s\n"),
 		 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
       exit_status = 1;
       return;
@@ -2396,11 +2401,11 @@ read_section_stabs (bfd *abfd, const cha
 
   if (! bfd_get_section_contents (abfd, stabsect, contents, 0, size))
     {
-      non_fatal (_("Reading %s section of %s failed: %s"),
+      non_fatal (_("reading %s section of %s failed: %s"),
 		 sect_name, bfd_get_filename (abfd),
 		 bfd_errmsg (bfd_get_error ()));
-      free (contents);
       exit_status = 1;
+      free (contents);
       return NULL;
     }
 
@@ -3350,7 +3355,7 @@ main (int argc, char **argv)
 	    endian = BFD_ENDIAN_LITTLE;
 	  else
 	    {
-	      non_fatal (_("unrecognized -E option"));
+	      nonfatal (_("unrecognized -E option"));
 	      usage (stderr, 1);
 	    }
 	  break;
@@ -3362,6 +3367,7 @@ main (int argc, char **argv)
 	  else
 	    {
 	      non_fatal (_("unrecognized --endian type `%s'"), optarg);
+	      exit_status = 1;
 	      usage (stderr, 1);
 	    }
 	  break;

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]