]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Ensure minimum stack size for preallocated task stacks
authorJohannes Kliemann <kliemann@adacore.com>
Tue, 12 Nov 2024 16:53:34 +0000 (17:53 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 12 Dec 2024 09:57:53 +0000 (10:57 +0100)
On targets with preallocated task stacks the minimum stack size is
defined as a constant in System.Parameters. When adding preallocated
tasks to the expanded code the compiler does not have direct access to
that value. Instead generate the expression
Max (Task_Size, Minimum_Task_Size) in the expanded tree and let it be
resolved later in the compilation process.

gcc/ada/ChangeLog:

* exp_ch9.adb (Expand_N_Task_Type_Declaration): Take
Minimum_Stack_Size into account when preallocating task stacks.
* rtsfind.ads (RE_Id, RE_Unit_Table): Add RE_Minimum_Stack_Size.

gcc/ada/exp_ch9.adb
gcc/ada/rtsfind.ads

index cf4d4d822562e1bdd9846763581fdd99b2781ee4..df51856f9c906e3cc320993d46745d69280a919a 100644 (file)
@@ -11945,6 +11945,35 @@ package body Exp_Ch9 is
                else
                   Task_Size := New_Copy_Tree (Expr_N);
                end if;
+
+               --  On targets with a preallocated task stack the minimum stack
+               --  size is defined in System.Parameters. Since we do not have
+               --  access to the value of that definition here we replace the
+               --  static task size with the static expression
+               --  Size_Type'Max (Task_Size, Minimum_Stack_Size).
+               --  The compiler will evaluate this expression and replace the
+               --  task size with the Minimum_Stack_Size if needed. It is
+               --  important for this expression to be static to avoid
+               --  introducing implicit heap allocations that would break code
+               --  with the No_Implicit_Heap_Allocations restriction.
+               --  On some runtimes the allocation of the minimum stack size is
+               --  ensured by a call to Adjust_Storage_Size. We cannot use this
+               --  function here as it is not static and evaluated at runtime.
+               --  Note: This expression may not appear in the expanded code
+               --  as the compiler evaluates this expression before code
+               --  generation.
+
+               Task_Size :=
+                 Convert_To
+                   (RTE (RE_Storage_Offset),
+                    Make_Attribute_Reference (Loc,
+                      Attribute_Name => Name_Max,
+                      Prefix         =>
+                        New_Occurrence_Of
+                          (RTE (RE_Size_Type), Loc), Expressions => New_List (
+                             Convert_To (RTE (RE_Size_Type), Task_Size),
+                             New_Occurrence_Of (RTE (RE_Minimum_Stack_Size),
+                               Loc))));
             end;
 
          else
index 9cfd2ed4c48c0be6d13ba97c9ee9de656a485c65..16c817dc37ed2084ae1e601ab18b99fa3bb970cc 100644 (file)
@@ -1618,6 +1618,7 @@ package Rtsfind is
 
      RE_Adjust_Storage_Size,             -- System.Parameters
      RE_Default_Stack_Size,              -- System.Parameters
+     RE_Minimum_Stack_Size,              -- System.Parameters
      RE_Size_Type,                       -- System.Parameters
      RE_Unspecified_Size,                -- System.Parameters
 
@@ -3274,6 +3275,7 @@ package Rtsfind is
 
      RE_Adjust_Storage_Size              => System_Parameters,
      RE_Default_Stack_Size               => System_Parameters,
+     RE_Minimum_Stack_Size               => System_Parameters,
      RE_Size_Type                        => System_Parameters,
      RE_Unspecified_Size                 => System_Parameters,