public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Olivier Hainque <hainque@adacore.com>
Subject: [Ada] Fix end-of dwarf section detection in address symbolizer
Date: Tue, 05 Dec 2017 12:12:00 -0000	[thread overview]
Message-ID: <20171205121234.GA147035@adacore.com> (raw)

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

When executing a Line Number program statement, the state machine bails
out a few bytes before the current offset reaches the end of section to
account for possible padding bytes at the end.

The current test is checking if current_offset + 4 >= section_length,
which is too early for e.g. a program terminating with

  Advance PC by constant 17 to 0x776
  Extended opcode 1: End of Sequence

at offset 101 for a section with length 105.

This change tightens the computation, allowing proper interpretation
in the example case above, and explains the rationale.

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-12-05  Olivier Hainque  <hainque@adacore.com>

	* s-dwalin.adb (Read_And_Execute_Isn): Adjust test checking for the end
	of section. Add comments explaining the rationale of the computation.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1445 bytes --]

Index: libgnat/s-dwalin.adb
===================================================================
--- libgnat/s-dwalin.adb	(revision 255411)
+++ libgnat/s-dwalin.adb	(working copy)
@@ -578,14 +578,21 @@
          Initialize_State_Machine (C);
       end if;
 
-      --  Read the next prologue
+      --  If we have reached the next prologue, read it. Beware of possibly
+      --  empty blocks.
 
+      --  When testing for the end of section, beware of possible zero padding
+      --  at the end. Bail out as soon as there's not even room for at least a
+      --  DW_LNE_end_sequence, 3 bytes from Off to Off+2. This resolves to
+      --  Off+2 > Last_Offset_Within_Section, that is Off+2 > Section_Length-1,
+      --  or Off+3 > Section_Length.
+
       Tell (C.Lines, Off);
       while Off = C.Next_Prologue loop
          Initialize_State_Machine (C);
          Parse_Prologue (C);
          Tell (C.Lines, Off);
-         exit when Off + 4 >= Length (C.Lines);
+         exit when Off + 3 > Length (C.Lines);
       end loop;
 
       --  Test whether we're done
@@ -595,7 +602,7 @@
       --  We are finished when we either reach the end of the section, or we
       --  have reached zero padding at the end of the section.
 
-      if Prologue.Unit_Length = 0 or else Off + 4 >= Length (C.Lines) then
+      if Prologue.Unit_Length = 0 or else Off + 3 > Length (C.Lines) then
          Done := True;
          return;
       end if;

                 reply	other threads:[~2017-12-05 12: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=20171205121234.GA147035@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hainque@adacore.com \
    /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).