https://gcc.gnu.org/g:0ec1b03ee1579d5a44d0cfb852cfecee7a6db883

commit r14-12885-g0ec1b03ee1579d5a44d0cfb852cfecee7a6db883
Author: Andrew Teylu <[email protected]>
Date:   Tue Sep 22 14:49:01 2026 +0200

    Ada: Close the DWARF 5 line-string stream
    
    System.Dwarf_Lines.Open creates a mapped stream for .debug_line_str when
    the optional DWARF 5 section is present.  Close omits that stream, losing
    one mapped-region allocation on every complete open/close cycle.
    
    This changes the procedure to close that stream along with the other debug
    streams, before closing the object file.
    
    gcc/ada/
            * libgnat/s-dwalin.ads (Dwarf_Context): Add Has_Line_Str.
            * libgnat/s-dwalin.adb (Open): Set Has_Line_Str when creating the
            line-string stream.
            (Close): Close the line-string stream if it was created.

Diff:
---
 gcc/ada/libgnat/s-dwalin.adb | 7 +++++++
 gcc/ada/libgnat/s-dwalin.ads | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/gcc/ada/libgnat/s-dwalin.adb b/gcc/ada/libgnat/s-dwalin.adb
index 46a7d61e78db..b00e18ce7556 100644
--- a/gcc/ada/libgnat/s-dwalin.adb
+++ b/gcc/ada/libgnat/s-dwalin.adb
@@ -283,6 +283,10 @@ package body System.Dwarf_Lines is
          Close (C.Abbrev);
          Close (C.Info);
          Close (C.Aranges);
+
+         if C.Has_Line_Str then
+            Close (C.Line_Str);
+         end if;
       end if;
 
       Close (C.Obj.all);
@@ -516,6 +520,9 @@ package body System.Dwarf_Lines is
 
       if Line_Str /= Null_Section then
          C.Line_Str := Create_Stream (C.Obj.all, Line_Str);
+         C.Has_Line_Str := True;
+      else
+         C.Has_Line_Str := False;
       end if;
 
       --  All operations are successful, context is valid
diff --git a/gcc/ada/libgnat/s-dwalin.ads b/gcc/ada/libgnat/s-dwalin.ads
index 1c4252169ab5..20178744115d 100644
--- a/gcc/ada/libgnat/s-dwalin.ads
+++ b/gcc/ada/libgnat/s-dwalin.ads
@@ -185,6 +185,9 @@ private
       Has_Debug : Boolean;
       --  True if all debug sections are available
 
+      Has_Line_Str : Boolean;
+      --  True if the .debug_line_str section is available
+
       Cache : Search_Array_Access;
       --  Quick access to symbol and debug info (when present).

Reply via email to