From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id DAA913857407; Wed, 18 May 2022 08:44:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAA913857407 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-605] [Ada] Fix DWARF parsing for 32-bit targets on 64-bit hosts X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?K=C3=A9vin_Le_Gouguec?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 72de114c23027f1d1f0df4c78e69c4302e39e058 X-Git-Newrev: 91b46ee298bf76401006f7699544ac9c107d92f9 Message-Id: <20220518084438.DAA913857407@sourceware.org> Date: Wed, 18 May 2022 08:44:38 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 May 2022 08:44:39 -0000 https://gcc.gnu.org/g:91b46ee298bf76401006f7699544ac9c107d92f9 commit r13-605-g91b46ee298bf76401006f7699544ac9c107d92f9 Author: Kévin Le Gouguec Date: Thu Apr 7 10:51:51 2022 +0200 [Ada] Fix DWARF parsing for 32-bit targets on 64-bit hosts Currently, a 64-bit gnatsymbolize fails to output line numbers and accurate symbol names when run on 32-bit executables (and vice-versa). This is because a couple of spots in System.Dwarf_Lines expect the Address_Size found in the DWARF data to match the host Address'Size. This patch corrects that assumption. gcc/ada/ * libgnat/s-dwalin.adb (Aranges_Lookup, Enable_Cache): Adapt to changes in the signature of Read_Aranges_*. (Debug_Info_Lookup): Do not control address size read from DWARF. (Read_Aranges_Header): Do not control address size read from DWARF; return this size. (Read_Aranges_Entry): Use the size returned by Read_Aranges_Header. Diff: --- gcc/ada/libgnat/s-dwalin.adb | 45 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/gcc/ada/libgnat/s-dwalin.adb b/gcc/ada/libgnat/s-dwalin.adb index aff552cf57b..50662ddceff 100644 --- a/gcc/ada/libgnat/s-dwalin.adb +++ b/gcc/ada/libgnat/s-dwalin.adb @@ -44,8 +44,6 @@ with System.Storage_Elements; use System.Storage_Elements; package body System.Dwarf_Lines is - SSU : constant := System.Storage_Unit; - function Get_Load_Displacement (C : Dwarf_Context) return Storage_Offset; -- Return the displacement between the load address present in the binary -- and the run-time address at which it is loaded (i.e. non-zero for PIE). @@ -76,14 +74,16 @@ package body System.Dwarf_Lines is -- Read an entry format array, as specified by 6.2.4.1 procedure Read_Aranges_Entry - (C : in out Dwarf_Context; - Start : out Address; - Len : out Storage_Count); + (C : in out Dwarf_Context; + Addr_Size : Natural; + Start : out Address; + Len : out Storage_Count); -- Read a single .debug_aranges pair procedure Read_Aranges_Header (C : in out Dwarf_Context; Info_Offset : out Offset; + Addr_Size : out Natural; Success : out Boolean); -- Read .debug_aranges header @@ -1069,12 +1069,13 @@ package body System.Dwarf_Lines is Info_Offset : out Offset; Success : out Boolean) is + Addr_Size : Natural; begin Info_Offset := 0; Seek (C.Aranges, 0); while Tell (C.Aranges) < Length (C.Aranges) loop - Read_Aranges_Header (C, Info_Offset, Success); + Read_Aranges_Header (C, Info_Offset, Addr_Size, Success); exit when not Success; loop @@ -1082,7 +1083,7 @@ package body System.Dwarf_Lines is Start : Address; Len : Storage_Count; begin - Read_Aranges_Entry (C, Start, Len); + Read_Aranges_Entry (C, Addr_Size, Start, Len); exit when Start = 0 and Len = 0; if Addr >= Start and then Addr < Start + Len @@ -1280,9 +1281,6 @@ package body System.Dwarf_Lines is Unit_Type := Read (C.Info); Addr_Sz := Read (C.Info); - if Addr_Sz /= (Address'Size / SSU) then - return; - end if; Read_Section_Offset (C.Info, Abbrev_Offset, Is64); @@ -1290,9 +1288,6 @@ package body System.Dwarf_Lines is Read_Section_Offset (C.Info, Abbrev_Offset, Is64); Addr_Sz := Read (C.Info); - if Addr_Sz /= (Address'Size / SSU) then - return; - end if; else return; @@ -1354,6 +1349,7 @@ package body System.Dwarf_Lines is procedure Read_Aranges_Header (C : in out Dwarf_Context; Info_Offset : out Offset; + Addr_Size : out Natural; Success : out Boolean) is Unit_Length : Offset; @@ -1376,10 +1372,7 @@ package body System.Dwarf_Lines is -- Read address_size (ubyte) - Sz := Read (C.Aranges); - if Sz /= (Address'Size / SSU) then - return; - end if; + Addr_Size := Natural (uint8'(Read (C.Aranges))); -- Read segment_size (ubyte) @@ -1392,7 +1385,7 @@ package body System.Dwarf_Lines is declare Cur_Off : constant Offset := Tell (C.Aranges); - Align : constant Offset := 2 * Address'Size / SSU; + Align : constant Offset := 2 * Offset (Addr_Size); Space : constant Offset := Cur_Off mod Align; begin if Space /= 0 then @@ -1408,14 +1401,15 @@ package body System.Dwarf_Lines is ------------------------ procedure Read_Aranges_Entry - (C : in out Dwarf_Context; - Start : out Address; - Len : out Storage_Count) + (C : in out Dwarf_Context; + Addr_Size : Natural; + Start : out Address; + Len : out Storage_Count) is begin -- Read table - if Address'Size = 32 then + if Addr_Size = 4 then declare S, L : uint32; begin @@ -1425,7 +1419,7 @@ package body System.Dwarf_Lines is Len := Storage_Count (L); end; - elsif Address'Size = 64 then + elsif Addr_Size = 8 then declare S, L : uint64; begin @@ -1520,6 +1514,7 @@ package body System.Dwarf_Lines is declare Info_Offset : Offset; Line_Offset : Offset; + Addr_Size : Natural; Success : Boolean; Ar_Start : Address; Ar_Len : Storage_Count; @@ -1531,7 +1526,7 @@ package body System.Dwarf_Lines is Seek (C.Aranges, 0); while Tell (C.Aranges) < Length (C.Aranges) loop - Read_Aranges_Header (C, Info_Offset, Success); + Read_Aranges_Header (C, Info_Offset, Addr_Size, Success); exit when not Success; Debug_Info_Lookup (C, Info_Offset, Line_Offset, Success); @@ -1540,7 +1535,7 @@ package body System.Dwarf_Lines is -- Read table loop - Read_Aranges_Entry (C, Ar_Start, Ar_Len); + Read_Aranges_Entry (C, Addr_Size, Ar_Start, Ar_Len); exit when Ar_Start = Null_Address and Ar_Len = 0; Len := uint32 (Ar_Len);