From be04e8eda375765f5336316085f0c4bd4ef468d5 Mon Sep 17 00:00:00 2001 From: Patrick Bernardi Date: Thu, 11 Jul 2019 08:03:04 +0000 Subject: [PATCH] [Ada] Minimal binder The new minimal binder option ("-minimal") suppresses the generation of binder objects that are not strictly required for program operation. This option is suitable for space constrained applications and comes with the restriction that programs can no longer be debugged using GDB. 2019-07-11 Patrick Bernardi gcc/ada/ * bindgen.adb (Gen_Main): Do not generate a reference to Ada_Main_Program_Name when the Minimal_Binder flag is set. (Gen_Output_File_Ada): Do not output GNAT_Version and Ada_Main_Program_Name info if Minimal_Binder flag is set. * bindusg.adb: Add documentation for new -minimal switch. * gnatbind.adb (Scan_Bind_Arg): Scan -minimal switch. * opt.ads: Add new global flag Minimal_Binder to indicate if the binder should not produce global variables. * doc/gnat_ugn/building_executable_programs_with_gnat.rst: Update documentation with new binder -minimal switch. * gnat_ugn.texi: Regenerate. From-SVN: r273401 --- gcc/ada/ChangeLog | 14 ++++++++ gcc/ada/bindgen.adb | 36 ++++++++++--------- gcc/ada/bindusg.adb | 6 ++++ ...building_executable_programs_with_gnat.rst | 11 +++++- gcc/ada/gnat_ugn.texi | 19 ++++++++++ gcc/ada/gnatbind.adb | 11 ++++++ gcc/ada/opt.ads | 6 ++++ 7 files changed, 86 insertions(+), 17 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index cc3eb1d56a8..472a6fdcd2d 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,17 @@ +2019-07-11 Patrick Bernardi + + * bindgen.adb (Gen_Main): Do not generate a reference to + Ada_Main_Program_Name when the Minimal_Binder flag is set. + (Gen_Output_File_Ada): Do not output GNAT_Version and + Ada_Main_Program_Name info if Minimal_Binder flag is set. + * bindusg.adb: Add documentation for new -minimal switch. + * gnatbind.adb (Scan_Bind_Arg): Scan -minimal switch. + * opt.ads: Add new global flag Minimal_Binder to indicate if the + binder should not produce global variables. + * doc/gnat_ugn/building_executable_programs_with_gnat.rst: + Update documentation with new binder -minimal switch. + * gnat_ugn.texi: Regenerate. + 2019-07-11 Eric Botcazou * Makefile.rtl: Add warning note about compilation flags and diff --git a/gcc/ada/bindgen.adb b/gcc/ada/bindgen.adb index e1355400ab0..8ea8a6b94da 100644 --- a/gcc/ada/bindgen.adb +++ b/gcc/ada/bindgen.adb @@ -1810,9 +1810,11 @@ package body Bindgen is -- with a pragma Volatile in order to tell the compiler to preserve -- this variable at any level of optimization. - -- CodePeer and CCG do not need this extra code on the other hand + -- CodePeer and CCG do not need this extra code. The code is also not + -- needed if the binder is in "Minimal Binder" mode. if Bind_Main_Program + and then not Minimal_Binder and then not CodePeer_Mode and then not Generate_C_Code then @@ -2354,25 +2356,27 @@ package body Bindgen is -- program uses two Ada libraries). Also zero terminate the string -- so that its end can be found reliably at run time. - WBI (""); - WBI (" GNAT_Version : constant String :="); - WBI (" """ & Ver_Prefix & - Gnat_Version_String & - """ & ASCII.NUL;"); - WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");"); + if not Minimal_Binder then + WBI (""); + WBI (" GNAT_Version : constant String :="); + WBI (" """ & Ver_Prefix & + Gnat_Version_String & + """ & ASCII.NUL;"); + WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");"); - WBI (""); - Set_String (" Ada_Main_Program_Name : constant String := """); - Get_Name_String (Units.Table (First_Unit_Entry).Uname); + WBI (""); + Set_String (" Ada_Main_Program_Name : constant String := """); + Get_Name_String (Units.Table (First_Unit_Entry).Uname); - Set_Main_Program_Name; - Set_String (""" & ASCII.NUL;"); + Set_Main_Program_Name; + Set_String (""" & ASCII.NUL;"); - Write_Statement_Buffer; + Write_Statement_Buffer; - WBI - (" pragma Export (C, Ada_Main_Program_Name, " & - """__gnat_ada_main_program_name"");"); + WBI + (" pragma Export (C, Ada_Main_Program_Name, " & + """__gnat_ada_main_program_name"");"); + end if; end if; WBI (""); diff --git a/gcc/ada/bindusg.adb b/gcc/ada/bindusg.adb index 0207479c03b..833174571c8 100644 --- a/gcc/ada/bindusg.adb +++ b/gcc/ada/bindusg.adb @@ -178,6 +178,12 @@ package body Bindusg is (" -mnnn Limit number of detected errors/warnings to nnn " & "(1-999999)"); + -- Line for -minimal switch + + Write_Line + (" -minimal Generate binder file suitable for space-constrained " + & "applications"); + -- Line for -M switch Write_Line diff --git a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst index af8f8a4492b..2e867e2c0b2 100644 --- a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst +++ b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst @@ -6475,7 +6475,6 @@ be presented in subsequent sections. Rename generated main program from main to xyz. This option is supported on cross environments only. - .. index:: -m (gnatbind) :switch:`-m{n}` @@ -6488,6 +6487,16 @@ be presented in subsequent sections. A value of zero means that no limit is enforced. The equal sign is optional. + .. index:: -minimal (gnatbind) + +:switch:`-minimal` + Generate a binder file suitable for space-constrained applications. When + active, binder-generated objects not required for program operation are no + longer generated. **Warning:** this option comes with the following + limitations: + + * Debugging will not work; + * Programs using GNAT.Compiler_Version will not link. .. index:: -n (gnatbind) diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi index 29424e76155..e3d6a3a6acb 100644 --- a/gcc/ada/gnat_ugn.texi +++ b/gcc/ada/gnat_ugn.texi @@ -15892,6 +15892,25 @@ limit, then a message is output and the bind is abandoned. A value of zero means that no limit is enforced. The equal sign is optional. +@geindex -minimal (gnatbind) + +@item @code{-minimal} + +Generate a binder file suitable for space-constrained applications. When +active, binder-generated objects not required for program operation are no +longer generated. @strong{Warning:} this option comes with the following +limitations: + + +@itemize * + +@item +Debugging will not work; + +@item +Programs using GNAT.Compiler_Version will not link. +@end itemize + @geindex -n (gnatbind) @item @code{-n} diff --git a/gcc/ada/gnatbind.adb b/gcc/ada/gnatbind.adb index 40c85b95ac0..a3b6a7eb359 100644 --- a/gcc/ada/gnatbind.adb +++ b/gcc/ada/gnatbind.adb @@ -474,6 +474,17 @@ procedure Gnatbind is Mapping_File := new String'(Argv (4 .. Argv'Last)); + -- -minimal + + elsif Argv (2 .. Argv'Last) = "minimal" then + if not Is_Cross_Compiler then + Write_Line + ("gnatbind: -minimal not expected to be used on native " & + "platforms"); + end if; + + Opt.Minimal_Binder := True; + -- -Mname elsif Argv'Length >= 3 and then Argv (2) = 'M' then diff --git a/gcc/ada/opt.ads b/gcc/ada/opt.ads index 4c1cf6ff453..4d3e87edc80 100644 --- a/gcc/ada/opt.ads +++ b/gcc/ada/opt.ads @@ -1120,6 +1120,12 @@ package Opt is -- Maximum number of processes that should be spawned to carry out -- compilations. + Minimal_Binder : Boolean := False; + -- GNATBIND + -- Set to True to suppress the generation of objects by the binder that + -- are not strictly required for a program to run. Intended for ZFP + -- applications that have tight memory constraints. + Minimal_Recompilation : Boolean := False; -- GNATMAKE -- Set to True if minimal recompilation mode requested -- 2.30.2