From: Arnaud Charlet Date: Sun, 3 Apr 2022 08:08:48 +0000 (+0000) Subject: [Ada] Secondary stack and a-tags X-Git-Tag: basepoints/gcc-14~6611 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dea655ad57bc17377c87306e0c538ad8c065493d;p=thirdparty%2Fgcc.git [Ada] Secondary stack and a-tags The simple use of Ada.Tags triggers a dependency on the secondary stack mechanism, which is unwanted on small embedded targets. To avoid this dependency, we special case a-tags.ali in ALI.Scan_ALI to not set Sec_Stack_Used. If some other code calls one of the functions returning a string, this code will also be marked as requiring the secondary stack. We also remove the need to import and set __gnat_binder_ss_count in this case by ensuring this variable defaults to 0. gcc/ada/ * ali.adb (Scan_ALI): Special case a-tags.ali when setting Sec_Stack_Used. * bindgen.adb (Gen_Adainit): Simplify handling of secondary stack related code, and only import __gnat_binder_ss_count when needed. * libgnat/s-secsta.adb (Binder_SS_Count): Default initialize to 0. --- diff --git a/gcc/ada/ali.adb b/gcc/ada/ali.adb index a5fba5dffd1..bcc8822940e 100644 --- a/gcc/ada/ali.adb +++ b/gcc/ada/ali.adb @@ -2079,7 +2079,15 @@ package body ALI is -- Processing for SS elsif C = 'S' then - Opt.Sec_Stack_Used := True; + -- Special case: a-tags.ali by itself should not set + -- Sec_Stack_Used, only if other code uses the secondary + -- stack should we set this flag. This ensures that we do + -- not bring the secondary stack unnecessarily when using + -- Ada.Tags and not actually using the secondary stack. + + if Get_Name_String (F) /= "a-tags.ali" then + Opt.Sec_Stack_Used := True; + end if; -- Invalid switch starting with S diff --git a/gcc/ada/bindgen.adb b/gcc/ada/bindgen.adb index 35587087178..3b55cc9634a 100644 --- a/gcc/ada/bindgen.adb +++ b/gcc/ada/bindgen.adb @@ -80,12 +80,6 @@ package body Bindgen is -- domains just before calling the main procedure from the environment -- task. - System_Secondary_Stack_Package_In_Closure : Boolean := False; - -- Flag indicating whether the unit System.Secondary_Stack is in the - -- closure of the partition. This is set by Resolve_Binder_Options, and - -- is used to initialize the package in cases where the run-time brings - -- in package but the secondary stack is not used. - System_Tasking_Restricted_Stages_Used : Boolean := False; -- Flag indicating whether the unit System.Tasking.Restricted.Stages is in -- the closure of the partition. This is set by Resolve_Binder_Options, @@ -612,33 +606,27 @@ package body Bindgen is """__gnat_initialize_stack_limit"");"); end if; - if System_Secondary_Stack_Package_In_Closure then - -- System.Secondary_Stack is in the closure of the program - -- because the program uses the secondary stack or the restricted - -- run-time is unconditionally calling SS_Init. In both cases, - -- SS_Init needs to know the number of secondary stacks created by - -- the binder. - + if Num_Sec_Stacks > 0 then WBI (" Binder_Sec_Stacks_Count : Natural;"); WBI (" pragma Import (Ada, Binder_Sec_Stacks_Count, " & """__gnat_binder_ss_count"");"); WBI (""); + end if; - -- Import secondary stack pool variables if the secondary stack - -- used. They are not referenced otherwise. + -- Import secondary stack pool variables if the secondary stack is + -- used. They are not referenced otherwise. - if Sec_Stack_Used then - WBI (" Default_Secondary_Stack_Size : " & - "System.Parameters.Size_Type;"); - WBI (" pragma Import (C, Default_Secondary_Stack_Size, " & - """__gnat_default_ss_size"");"); + if Sec_Stack_Used then + WBI (" Default_Secondary_Stack_Size : " & + "System.Parameters.Size_Type;"); + WBI (" pragma Import (C, Default_Secondary_Stack_Size, " & + """__gnat_default_ss_size"");"); - WBI (" Default_Sized_SS_Pool : System.Address;"); - WBI (" pragma Import (Ada, Default_Sized_SS_Pool, " & - """__gnat_default_ss_pool"");"); + WBI (" Default_Sized_SS_Pool : System.Address;"); + WBI (" pragma Import (Ada, Default_Sized_SS_Pool, " & + """__gnat_default_ss_pool"");"); - WBI (""); - end if; + WBI (""); end if; WBI (" begin"); @@ -686,46 +674,36 @@ package body Bindgen is -- Generate the default-sized secondary stack pool if the secondary -- stack is used by the program. - if System_Secondary_Stack_Package_In_Closure then - if Sec_Stack_Used then - -- Elaborate the body of the binder to initialize the default- - -- sized secondary stack pool. - - WBI (""); - WBI (" " & Get_Ada_Main_Name & "'Elab_Body;"); - - -- Generate the default-sized secondary stack pool and set the - -- related secondary stack globals. + if Sec_Stack_Used then + -- Elaborate the body of the binder to initialize the default- + -- sized secondary stack pool. - Set_String (" Default_Secondary_Stack_Size := "); + WBI (""); + WBI (" " & Get_Ada_Main_Name & "'Elab_Body;"); - if Opt.Default_Sec_Stack_Size /= Opt.No_Stack_Size then - Set_Int (Opt.Default_Sec_Stack_Size); - else - Set_String - ("System.Parameters.Runtime_Default_Sec_Stack_Size"); - end if; + -- Generate the default-sized secondary stack pool and set the + -- related secondary stack globals. - Set_Char (';'); - Write_Statement_Buffer; + Set_String (" Default_Secondary_Stack_Size := "); - Set_String (" Binder_Sec_Stacks_Count := "); - Set_Int (Num_Sec_Stacks); - Set_Char (';'); - Write_Statement_Buffer; + if Opt.Default_Sec_Stack_Size /= Opt.No_Stack_Size then + Set_Int (Opt.Default_Sec_Stack_Size); + else + Set_String + ("System.Parameters.Runtime_Default_Sec_Stack_Size"); + end if; - WBI (" Default_Sized_SS_Pool := " & - "Sec_Default_Sized_Stacks'Address;"); - WBI (""); + Set_Char (';'); + Write_Statement_Buffer; - else - -- The presence of System.Secondary_Stack in the closure of the - -- program implies the restricted run-time is unconditionally - -- calling SS_Init. Let SS_Init know that no stacks were - -- created. + Set_String (" Binder_Sec_Stacks_Count := "); + Set_Int (Num_Sec_Stacks); + Set_Char (';'); + Write_Statement_Buffer; - WBI (" Binder_Sec_Stacks_Count := 0;"); - end if; + WBI (" Default_Sized_SS_Pool := " & + "Sec_Default_Sized_Stacks'Address;"); + WBI (""); end if; -- Normal case (standard library not suppressed). Set all global values @@ -3276,12 +3254,6 @@ package body Bindgen is Check_Package (System_Restrictions_Used, "system.restrictions%s"); - -- Ditto for the use of System.Secondary_Stack - - Check_Package - (System_Secondary_Stack_Package_In_Closure, - "system.secondary_stack%s"); - -- Ditto for use of an SMP bareboard runtime Check_Package (System_BB_CPU_Primitives_Multiprocessors_Used, diff --git a/gcc/ada/libgnat/s-secsta.adb b/gcc/ada/libgnat/s-secsta.adb index c2ab9226344..ac929c07b3e 100644 --- a/gcc/ada/libgnat/s-secsta.adb +++ b/gcc/ada/libgnat/s-secsta.adb @@ -53,7 +53,7 @@ package body System.Secondary_Stack is -- in order to avoid depending on the binder. Their values are set by the -- binder. - Binder_SS_Count : Natural; + Binder_SS_Count : Natural := 0; pragma Export (Ada, Binder_SS_Count, "__gnat_binder_ss_count"); -- The number of secondary stacks in the pool created by the binder