public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Adapt Ada.Command_Line to work on configurable runtimes
@ 2023-12-19 14:30 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-12-19 14:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: Patrick Bernardi

From: Patrick Bernardi <bernardi@adacore.com>

The behaviour of the binder when handling command line arguments and exit
codes is simplified so that references to the corresponding runtime symbols
are always generated when the runtime is configured with command line
argument and exit code support. This allows Ada.Command_Line to work with
all runtimes, which was not the case previously.

As a result of this change, configurable runtimes that do not include
Ada.Command_Line and it support files, but are configured with
Command_Line_Args and/or Exit_Status_Supported set to True will need to
provide the symbols required by the binder, as these symbols will no longer
be defined in the binder generated file.

argv.c includes a small change to exclude adaint.h when compiling for a
light runtime, since this header is not required.

gcc/ada/

	* argv.c: Do not include adaint.h if LIGHT_RUNTIME is defined.
	* bindgen.adb (Gen_Main): Simplify command line argument and exit
	handling by requiring the runtime to always provide the required
	symbols if command line argument and exit code is enabled.
	* targparm.ads: Update comments to reflect changes to gnatbind.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/argv.c       |  2 ++
 gcc/ada/bindgen.adb  | 60 ++++++++++++++++----------------------------
 gcc/ada/targparm.ads | 20 ++++-----------
 3 files changed, 28 insertions(+), 54 deletions(-)

diff --git a/gcc/ada/argv.c b/gcc/ada/argv.c
index a773befb8c0..17369a9f3f9 100644
--- a/gcc/ada/argv.c
+++ b/gcc/ada/argv.c
@@ -51,7 +51,9 @@
 #include "system.h"
 #endif
 
+#ifndef LIGHT_RUNTIME
 #include "adaint.h"
+#endif
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/gcc/ada/bindgen.adb b/gcc/ada/bindgen.adb
index 87f162e6b43..03315fe2251 100644
--- a/gcc/ada/bindgen.adb
+++ b/gcc/ada/bindgen.adb
@@ -2092,12 +2092,14 @@ package body Bindgen is
 
       WBI ("   begin");
 
-      --  Acquire command-line arguments if present on target
+      --  Acquire command-line arguments if present and supported on the
+      --  target. Do not acquire command-line arguments if pragma No_Run_Time
+      --  is in effect as the run-time symbols will not be available.
 
       if CodePeer_Mode then
          null;
 
-      elsif Command_Line_Args_On_Target then
+      elsif Command_Line_Args_On_Target and then not No_Run_Time_Mode then
 
          --  Initialize gnat_argc/gnat_argv only if not already initialized,
          --  to avoid losing the result of any command-line processing done by
@@ -2109,20 +2111,6 @@ package body Bindgen is
          WBI ("      end if;");
          WBI ("      gnat_envp := envp;");
          WBI ("");
-
-      --  If configurable run-time and no command-line args, then nothing needs
-      --  to be done since the gnat_argc/argv/envp variables are suppressed in
-      --  this case.
-
-      elsif Configurable_Run_Time_On_Target then
-         null;
-
-      --  Otherwise set dummy values (to be filled in by some other unit?)
-
-      else
-         WBI ("      gnat_argc := 0;");
-         WBI ("      gnat_argv := System.Null_Address;");
-         WBI ("      gnat_envp := System.Null_Address;");
       end if;
 
       if Opt.Default_Exit_Status /= 0
@@ -2199,7 +2187,11 @@ package body Bindgen is
          if No_Main_Subprogram
            or else ALIs.Table (ALIs.First).Main_Program = Proc
          then
-            WBI ("      return (gnat_exit_status);");
+            if No_Run_Time_Mode then
+               WBI ("      return (0);");
+            else
+               WBI ("      return (gnat_exit_status);");
+            end if;
          else
             WBI ("      return (Result);");
          end if;
@@ -2595,38 +2587,28 @@ package body Bindgen is
       if Bind_Main_Program then
          --  Generate argc/argv stuff unless suppressed
 
-         if Command_Line_Args_On_Target
-           or not Configurable_Run_Time_On_Target
-         then
+         --  A run-time configured to support command line arguments defines
+         --  a number of internal symbols that need to be set by the binder.
+
+         if Command_Line_Args_On_Target and then not No_Run_Time_Mode then
             WBI ("");
             WBI ("   gnat_argc : Integer;");
             WBI ("   gnat_argv : System.Address;");
             WBI ("   gnat_envp : System.Address;");
 
-            --  If the standard library is not suppressed, these variables
-            --  are in the run-time data area for easy run time access.
-
-            if not Suppress_Standard_Library_On_Target then
-               WBI ("");
-               WBI ("   pragma Import (C, gnat_argc);");
-               WBI ("   pragma Import (C, gnat_argv);");
-               WBI ("   pragma Import (C, gnat_envp);");
-            end if;
+            WBI ("");
+            WBI ("   pragma Import (C, gnat_argc);");
+            WBI ("   pragma Import (C, gnat_argv);");
+            WBI ("   pragma Import (C, gnat_envp);");
          end if;
 
-         --  Define exit status. Again in normal mode, this is in the run-time
-         --  library, and is initialized there, but in the configurable
-         --  run-time case, the variable is declared and initialized in this
-         --  file.
+         --  Define exit status. The exit status is stored in the run-time
+         --  library to allow applications set the state through
+         --  Ada.Command_Line. It is initialized there.
 
          WBI ("");
 
-         if Configurable_Run_Time_Mode then
-            if Exit_Status_Supported_On_Target then
-               WBI ("   gnat_exit_status : Integer := 0;");
-            end if;
-
-         else
+         if Exit_Status_Supported_On_Target and then not No_Run_Time_Mode then
             WBI ("   gnat_exit_status : Integer;");
             WBI ("   pragma Import (C, gnat_exit_status);");
          end if;
diff --git a/gcc/ada/targparm.ads b/gcc/ada/targparm.ads
index 212725219d7..c76b4e77a9f 100644
--- a/gcc/ada/targparm.ads
+++ b/gcc/ada/targparm.ads
@@ -272,16 +272,8 @@ package Targparm is
    --    If Command_Line_Args_On_Target is set to False, then the
    --    generation of these variables is suppressed completely.
    --
-   --    The binder generates the gnat_exit_status variable in the binder
-   --    file instead of being imported from the run-time library. If
-   --    Exit_Status_Supported_On_Target is set to False, then the
-   --    generation of this variable is suppressed entirely.
-   --
    --    The routine __gnat_break_start is defined within the binder file
    --    instead of being imported from the run-time library.
-   --
-   --    The variable __gnat_exit_status is generated within the binder file
-   --    instead of being imported from the run-time library.
 
    Suppress_Standard_Library_On_Target : Boolean := False;
    --  If this flag is True, then the standard library is not included by
@@ -461,19 +453,17 @@ package Targparm is
    --  required on such targets (RM A.15(13)).
 
    Command_Line_Args_On_Target : Boolean := True;
-   --  Set False if no command line arguments on target. Note that if this
-   --  is False in with Configurable_Run_Time_On_Target set to True, then
-   --  this causes suppression of generation of the argv/argc variables
-   --  used to record command line arguments.
+   --  Set False if no command line arguments on target. This will suppress
+   --  generation of references to the argv/argc variables used to record
+   --  command line arguments.
 
    --  Similarly, most targets support the use of an exit status, but other
    --  targets might not, as allowed by RM A.15(18-20).
 
    Exit_Status_Supported_On_Target : Boolean := True;
    --  Set False if returning of an exit status is not supported on target.
-   --  Note that if this False in with Configurable_Run_Time_On_Target
-   --  set to True, then this causes suppression of the gnat_exit_status
-   --  variable used to record the exit status.
+   --  This will cause the binder to not generate a reference to the
+   --  gnat_exit_status run-time symbol.
 
    -----------------------
    -- Main Program Name --
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-19 14:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-19 14:30 [COMMITTED] ada: Adapt Ada.Command_Line to work on configurable runtimes Marc Poulhiès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).