From: Kévin Le Gouguec Date: Thu, 7 Apr 2022 08:51:51 +0000 (+0200) Subject: [Ada] Fix DWARF parsing for 32-bit targets on 64-bit hosts X-Git-Tag: basepoints/gcc-14~6602 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91b46ee298bf76401006f7699544ac9c107d92f9;p=thirdparty%2Fgcc.git [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 --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);