From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57634 invoked by alias); 5 Dec 2017 12:12:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 57617 invoked by uid 89); 5 Dec 2017 12:12:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=beware X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Dec 2017 12:12:35 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 75FA3116E0F; Tue, 5 Dec 2017 07:12:34 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id N4C6JvGIVTQa; Tue, 5 Dec 2017 07:12:34 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 63665116E0E; Tue, 5 Dec 2017 07:12:34 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4862) id 5FA9E379; Tue, 5 Dec 2017 07:12:34 -0500 (EST) Date: Tue, 05 Dec 2017 12:12:00 -0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Olivier Hainque Subject: [Ada] Fix end-of dwarf section detection in address symbolizer Message-ID: <20171205121234.GA147035@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="fdj2RfSjLxBAspz7" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00206.txt.bz2 --fdj2RfSjLxBAspz7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 812 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 * s-dwalin.adb (Read_And_Execute_Isn): Adjust test checking for the end of section. Add comments explaining the rationale of the computation. --fdj2RfSjLxBAspz7 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=difs Content-length: 1445 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; --fdj2RfSjLxBAspz7--