public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: binutils@sourceware.org
Subject: Commit: Use reloc_at to detect partial debug_line sections
Date: Fri, 05 Jun 2015 15:59:00 -0000	[thread overview]
Message-ID: <87h9qmdu3f.fsf@redhat.com> (raw)

Hi Guys,

  I am checking in the patch below to fix the heuristic in
  read_debug_line_header that detect partial .debug_line sections.
  Previously it used to check for a negative length, but this is not
  guaranteed to happen.  (It depends upon the relocs used to compute the
  correct values for the debug_line header).  Instead we can now use the
  reloc_at function to detect that a reloc is needed to compute the
  correct header length, and take the appropriate steps.

  Tested with no regressions on lots of toolchains.

Cheers
  Nick

binutils/ChangeLog
2015-06-05  Nick Clifton  <nickc@redhat.com>

	* dwarf.c (read_debug_line_header): Use reloc_at to detect
	incomplete .debug_line headers

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 71b0e97..c3dc814 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -2761,18 +2761,20 @@ read_debug_line_header (struct dwarf_section * section,
 
   if (linfo->li_length + initial_length_size > section->size)
     {
-      /* If the length is just a bias against the initial_length_size then
-	 this means that the field has a relocation against it which has not
-	 been applied.  (Ie we are dealing with an object file, not a linked
-	 binary).  Do not complain but instead assume that the rest of the
-	 section applies to this particular header.  */
-      if (linfo->li_length == - initial_length_size)
+      /* If the length field has a relocation against it, then we should
+	 not complain if it is inaccurate (and probably negative).  This
+	 happens in object files when the .debug_line section is actually
+	 comprised of several different .debug_line.* sections, (some of
+	 which may be removed by linker garbage collection), and a relocation
+	 is used to compute the correct length once that is done.  */
+      if (reloc_at (section, (hdrptr - section->start) - offset_size))
 	{
-	  linfo->li_length = section->size - initial_length_size;
+	  linfo->li_length = (end - data) - initial_length_size;
 	}
       else
 	{
-	  warn (_("The line info appears to be corrupt - the section is too small\n"));
+	  warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
+		(long) linfo->li_length);
 	  return NULL;
 	}
     }

                 reply	other threads:[~2015-06-05 15:59 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=87h9qmdu3f.fsf@redhat.com \
    --to=nickc@redhat.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).