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]

[PATCH] Debug information checking


Hi all,

I'm investigating a problem in which I see the following message:

arm-none-eabi-ld: Dwarf Error: Offset (273) greater than or equal to .debug_str size (268).

Unfortunately, I haven't figured out what's causing the problem, but I have discovered that the linker only detects this condition some of the time - specifically when it is the first read from the .debug_str section. The rest of the time it just reads from the offset even though it's out of range.


Note that you only get to this code when there are undefined symbols and the link is about to fail - it's looking for the filename and line number.

The attached patch ensures that it never misses a broken offset.

Does anybody have any clues what could be causing the real problem - the apparently broken debug info? The size given for .debug_str is incorrect, but I don't yet know why.

Anyway, is this patch OK?

Andrew
2009-03-11  Andrew Stubbs  <ams@codesourcery.com>

	bfd/
	* dwarf2.c (read_section): Always check the offset, even when the
	section has been read before.

---
 src/binutils-mainline/bfd/dwarf2.c |   76 ++++++++++++++++++++--------------------
 1 files changed, 38 insertions(+), 38 deletions(-)

Index: src/binutils-mainline/bfd/dwarf2.c
===================================================================
--- src/binutils-mainline/bfd/dwarf2.c.orig
+++ src/binutils-mainline/bfd/dwarf2.c
@@ -417,49 +417,49 @@ read_section (bfd *           abfd,
   bfd_boolean section_is_compressed = FALSE;
 
   /* read_section is a noop if the section has already been read.  */
-  if (*section_buffer)
-    return TRUE;
-
-  msec = bfd_get_section_by_name (abfd, section_name);
-  if (! msec && compressed_section_name)
-    {
-      msec = bfd_get_section_by_name (abfd, compressed_section_name);
-      section_is_compressed = TRUE;
-    }
-  if (! msec)
-    {
-      (*_bfd_error_handler) (_("Dwarf Error: Can't find %s section."), section_name);
-      bfd_set_error (bfd_error_bad_value);
-      return FALSE;
-    }
-
-  if (syms)
+  if (!*section_buffer)
     {
-      *section_size = msec->size;
-      *section_buffer
-	  = bfd_simple_get_relocated_section_contents (abfd, msec, NULL, syms);
-      if (! *section_buffer)
-	return FALSE;
-    }
-  else
-    {
-      *section_size = msec->rawsize ? msec->rawsize : msec->size;
-      *section_buffer = bfd_malloc (*section_size);
-      if (! *section_buffer)
-	return FALSE;
-      if (! bfd_get_section_contents (abfd, msec, *section_buffer,
-				      0, *section_size))
-	return FALSE;
-    }
-
-  if (section_is_compressed)
-    {
-      if (! bfd_uncompress_section_contents (section_buffer, section_size))
+      msec = bfd_get_section_by_name (abfd, section_name);
+      if (! msec && compressed_section_name)
 	{
-	  (*_bfd_error_handler) (_("Dwarf Error: unable to decompress %s section."), compressed_section_name);
+	  msec = bfd_get_section_by_name (abfd, compressed_section_name);
+	  section_is_compressed = TRUE;
+	}
+      if (! msec)
+	{
+	  (*_bfd_error_handler) (_("Dwarf Error: Can't find %s section."), section_name);
 	  bfd_set_error (bfd_error_bad_value);
 	  return FALSE;
 	}
+
+      if (syms)
+	{
+	  *section_size = msec->size;
+	  *section_buffer
+	      = bfd_simple_get_relocated_section_contents (abfd, msec, NULL, syms);
+	  if (! *section_buffer)
+	    return FALSE;
+	}
+      else
+	{
+	  *section_size = msec->rawsize ? msec->rawsize : msec->size;
+	  *section_buffer = bfd_malloc (*section_size);
+	  if (! *section_buffer)
+	    return FALSE;
+	  if (! bfd_get_section_contents (abfd, msec, *section_buffer,
+					  0, *section_size))
+	    return FALSE;
+	}
+
+      if (section_is_compressed)
+	{
+	  if (! bfd_uncompress_section_contents (section_buffer, section_size))
+	    {
+	      (*_bfd_error_handler) (_("Dwarf Error: unable to decompress %s section."), compressed_section_name);
+	      bfd_set_error (bfd_error_bad_value);
+	      return FALSE;
+	    }
+	}
     }
 
   /* It is possible to get a bad value for the offset into the section

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