From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 367173875450 for ; Tue, 19 Dec 2023 14:30:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 367173875450 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 367173875450 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702996250; cv=none; b=d24hH+fsxpzHlIyJkPuyceUAUSHinLGBQXhC8H3xixXmC4R0j8FQJk2k31wqZp4JoKKFzx1uPT4BRHi7cG67/lRBOzc75jyU7cYZip1CPhfGcXkOrEZcmz4NZ8WKAZvBnBlvjVxYKQACOELL9cHWb4ue+qv7QGfPGxMoHeIMTAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702996250; c=relaxed/simple; bh=9a/8abfRfiL4hR5jcwNpKbeGNYGx5ONR5l/GilnX644=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PiRHXSG6VcyFg1Le2Rw7+7XbU+okN8XhrpQGQVCzfjH+iA3G6EG9kxVqehTB9g8moqMA/do8H0ltO/RRhJPD+Fhh4rMQDfowJUNe+lM8sESLqqFBNkUAndyeA0PrP2vNOlFd3tDwzsAAEM71rohXY+7562YzpKaQkq3MPaRywBg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40c60dfa5bfso55094295e9.0 for ; Tue, 19 Dec 2023 06:30:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702996247; x=1703601047; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=pVwpZ99lhHHUhjDa7k3SCOmVfRMjXOHzJUAlzKAmhLs=; b=hfwWyCnhO+/hUXAQ5t+cgZN0dVIkiwTh+mPBMLRbhv5dhLGHiZ+symkaf0ViZowcp9 H9mBip2fd4Z+sWw64qEEIV/E7kAG0ZRPDcNyCQWMZUELLtXaxr5HzXpkqG4gm2Gs9Hal 2JPF4giGcVwJ0XixQ+H3z+qB1ywoAhPKb++Gx8btYAMr1zkY4mFPGznGD55E+asfRCt8 ac45O/1MwfMegNDDBiHLfCJx6t5MHhCNkU74ZGUUT2nx/pg6TIB/R3Y822uLqr6k+OBN 3Rv9LNuC4P6X3c6ZEtG9Dqe+n/PTPdqQPmYGc26VRy3ZRa91a5cp5RwMsfr/NDZSAtwc u0cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702996247; x=1703601047; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pVwpZ99lhHHUhjDa7k3SCOmVfRMjXOHzJUAlzKAmhLs=; b=ZX9OW+8C7vP8+/rNMg59Ni4nRXFt7TgCUTvieWu34zt3sUNkOH6Xg2632eFvUO5IAK GIEk4N0Tu4ckYi3MKJBme1jtifvRq2TXaHPdREl0pSLAUCh9p8FOHwfAQlE85gw2K6/j UNyQXDwucD0i5vEPTB4tB37AU+ZNAevZK3ZkUZH64Jcgtxmht6AEI3VKMB6JXhvE4CkU RGlJU2mAuSYT6oN43+nAzHxE+zhCvwap9RhBT1RFSvZtO84zhDMC695bNebVtIt2m+iZ UdrpjcUFgtSsG5UPuJ6hLbttzfSLul2tim/356Xym1w++xxubJsNW1dRPYB76NK6s1Xk 3efA== X-Gm-Message-State: AOJu0Yz6OeDzIGM1tB4NduGSKhLPPn5HH0B7KFl2fOEzQfdRFJnGjc1o Uc+Tna6JSaOaUQCDPw1QjZqwPomba2UJ0/QHR9I= X-Google-Smtp-Source: AGHT+IESUZx8KVB868UOyoahgLG/pcdm/jE4Ssbv9RP0YsuD91YBihugs52Pw6ESNgDYtN75JiBPeQ== X-Received: by 2002:a05:600c:b99:b0:40d:247c:ad1e with SMTP id fl25-20020a05600c0b9900b0040d247cad1emr650503wmb.14.1702996246933; Tue, 19 Dec 2023 06:30:46 -0800 (PST) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:fe1e:443:c34f:edaa]) by smtp.gmail.com with ESMTPSA id v16-20020a05600c471000b0040c4886f254sm3063671wmo.13.2023.12.19.06.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 06:30:46 -0800 (PST) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Patrick Bernardi Subject: [COMMITTED] ada: Adapt Ada.Command_Line to work on configurable runtimes Date: Tue, 19 Dec 2023 15:30:45 +0100 Message-ID: <20231219143045.455298-1-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Patrick Bernardi 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