From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 097AE3870C0D for ; Tue, 19 Dec 2023 14:30:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 097AE3870C0D 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 097AE3870C0D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702996259; cv=none; b=LSMq4Dvbn1+rsTVtyltvR6CA2SzcvelRzZs1ESf9Is2Sp09FHUzCbNms6F8xOg9719QcZrozBA7vOEYmm2QBrerOAw1U2bDUaGLwhiLRjo4hVxp7nYEjvVPsC5zdhYygz+c+UcqjXf006rRNJxi4VuhA3lRne0I/r5nRfFIho9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702996259; c=relaxed/simple; bh=gZ8ymIt7KIUWmBd1J1kMI26bysG7Ir2EnW+i9sOfiXk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KlWd34GPib1yqPHqApoeZjprVEYjKnoGCgx7jUl5px+sH68V+CS4e5cYG7fAvyLAaWUiklgYz2tFTbYdFfnXCFsQyK87TeLuiDW0fyASDB4OVuFEmL98bsAL9XsubynC2JLUA37C7yHf50stAyGSRKbrVNguzYCtJb4bOYju4bE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-33668163949so2531509f8f.2 for ; Tue, 19 Dec 2023 06:30:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702996256; x=1703601056; 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=dn8dK4bpxJhhs4VtsJM5+mfLuiSzWqCEUkhZgm2XjKA=; b=JmvsglBCgOGODPwSRbE4WoMgPaInLUtHaXtWBZwOERoY/grD4jBWQK31oKWlihAbCI HhkIrYiCly8PrdsgqtFKeYLF3ZvbJJIMjOqS894Mp4VYJ6S+zQnOE/zH5sr7xEdC0RMW EOLnWwjXE+7F1gaM5rjCU3WCAbs37aAVpr2zQ09Gtk2Lk6Pa5aw2ItrzqaJAx8WHRtCb vv0QZYlLiP//01mzqosekU7tTjsNqmSVh/wZqR9mM9hfepFl/DzJuCnvYV6DkkH54/cA +Sqjc/VaeOOoMsUvM8ECnxCXYarhPtoqpUZI8FHslbgV2DyfY1rMBwvB1HAzTEOiWWwp 1/Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702996256; x=1703601056; 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=dn8dK4bpxJhhs4VtsJM5+mfLuiSzWqCEUkhZgm2XjKA=; b=lk1WFVQFxJ/T5vyK+QSy41k5dFGNPawoFs2F4fZrOqyZuvWHxmBdBgHERAlzveXEPJ j+4FNbps2GNXth0X/MHzN9yoT5PqmsGgnwiryAvIyOqYktuMWpChl1PYn7tZxVSo3dPf mG7Jym4ZDcZ5HOVKUhS3ZP6U7D2FoaE+Yp+yieamkdapp+VcZeDIGT9jwn4bO0x15zgU tDXrxrwJ3fI1YkJZQ7N3wD460Dm8x3U7UtMxn/O8b+YpEScn/TEPOi1c66fDmEKKfLRl ytcE3C1pmiPcu/JntSFtojzFdkhbocu6qxAtTF5RtvnSRDj4p0y5OwrvG3inENAZFalC 6qbA== X-Gm-Message-State: AOJu0Yy0m3qAPWFoPZyrSrN/oqAMoR75EHzC8KTFRrx91v24F8bcIVsz muRibSX1cBOlHYfxNC+pTSJLxyD7ByAfXcY+mY0= X-Google-Smtp-Source: AGHT+IHBK5JYq6oaYQBXVZAUnmovElVjqqOGLVA0SvzOsTGecmVunpLc4qoS0KwlK7zDjbvhiZOJTQ== X-Received: by 2002:a5d:6e0c:0:b0:333:3a1e:4357 with SMTP id h12-20020a5d6e0c000000b003333a1e4357mr4304485wrz.20.1702996255796; Tue, 19 Dec 2023 06:30:55 -0800 (PST) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:fe1e:443:c34f:edaa]) by smtp.gmail.com with ESMTPSA id e7-20020a5d5307000000b0033667c94839sm5825796wrv.61.2023.12.19.06.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 06:30:55 -0800 (PST) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Patrick Bernardi Subject: [COMMITTED] ada: gnatbind: Do not generate Ada.Command_Line references when not used Date: Tue, 19 Dec 2023 15:30:54 +0100 Message-ID: <20231219143054.455618-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 It was previously assumed that configurable runtimes could not return exit statuses, however this assumption no longer holds. Instead, only import the required symbols from Ada.Command_Line's support packages if Ada.Command_Line is in the closure of the partition when a configurable runtime is used. gcc/ada/ * bindgen.adb (Command_Line_Used): New object. (Gen_Main): Only generate references to symbols used by Ada.Command_Line if the package is used by the partition. (Gen_Output_File_Ada): Ditto. (Resolve_Binder_Options): Check if Ada.Command_Line is in the closure of the partition. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/bindgen.adb | 55 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/gcc/ada/bindgen.adb b/gcc/ada/bindgen.adb index 03315fe2251..005ad70f507 100644 --- a/gcc/ada/bindgen.adb +++ b/gcc/ada/bindgen.adb @@ -65,6 +65,15 @@ package body Bindgen is -- Number of default-sized primary stacks the binder needs to allocate for -- task objects declared in the program. + Command_Line_Used : Boolean := False; + -- Flag indicating whether the unit Ada.Command_Line is in the closure of + -- the partition. This is set by Resolve_Binder_Options, and is used to + -- determine whether or not to import and use symbols defined in + -- Ada.Command_Line's support packages (gnat_argc, gnat_argv, gnat_envp + -- and gnat_exit_status). Conservatively, it is always set to True for + -- non-configurable run-times as parts of the compiler and run-time assume + -- these symbols are available and can be imported directly. + System_Restrictions_Used : Boolean := False; -- Flag indicating whether the unit System.Restrictions is in the closure -- of the partition. This is set by Resolve_Binder_Options, and is used @@ -2092,15 +2101,13 @@ package body Bindgen is WBI (" begin"); - -- 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. + -- Acquire command-line arguments if supported on the target and used + -- by the program. if CodePeer_Mode then null; - elsif Command_Line_Args_On_Target and then not No_Run_Time_Mode then - + elsif Command_Line_Args_On_Target and then Command_Line_Used then -- Initialize gnat_argc/gnat_argv only if not already initialized, -- to avoid losing the result of any command-line processing done by -- earlier GNAT run-time initialization. @@ -2187,10 +2194,13 @@ package body Bindgen is if No_Main_Subprogram or else ALIs.Table (ALIs.First).Main_Program = Proc then - if No_Run_Time_Mode then - WBI (" return (0);"); - else + -- Return gnat_exit_status if Ada.Command_Line is used otherwise + -- return 0. + + if Command_Line_Used then WBI (" return (gnat_exit_status);"); + else + WBI (" return (0);"); end if; else WBI (" return (Result);"); @@ -2589,8 +2599,11 @@ package body Bindgen is -- A run-time configured to support command line arguments defines -- a number of internal symbols that need to be set by the binder. + -- We do not do this in cases where the program does not use + -- Ada.Command_Line, as the package and it's support files may not be + -- present. - if Command_Line_Args_On_Target and then not No_Run_Time_Mode then + if Command_Line_Args_On_Target and then Command_Line_Used then WBI (""); WBI (" gnat_argc : Integer;"); WBI (" gnat_argv : System.Address;"); @@ -2602,13 +2615,17 @@ package body Bindgen is WBI (" pragma Import (C, gnat_envp);"); end if; - -- 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. + -- Define exit status if supported by the target. The exit status is + -- stored in the run-time library to allow applications set the state + -- through Ada.Command_Line and is initialized in the run-time. Like + -- command line arguments, skip if Ada.Command_Line is not used in + -- the enclosure of the partition because this package may not be + -- available in the runtime. WBI (""); - if Exit_Status_Supported_On_Target and then not No_Run_Time_Mode then + if Exit_Status_Supported_On_Target and then Command_Line_Used + then WBI (" gnat_exit_status : Integer;"); WBI (" pragma Import (C, gnat_exit_status);"); end if; @@ -3371,6 +3388,18 @@ package body Bindgen is Check_Package (System_Version_Control_Used, "system.version_control%s"); + + -- Ditto for the use of Ada.Command_Line, except we always set + -- Command_Line_Used to True if on a non-configurable run-time + -- as parts of the compiler and run-time assume the GNAT command + -- line symbols are available and can be imported directly (as + -- long as No_Run_Time mode is not set). + + if Configurable_Run_Time_On_Target then + Check_Package (Command_Line_Used, "ada.command_line%s"); + elsif not No_Run_Time_Mode then + Command_Line_Used := True; + end if; end loop; end Resolve_Binder_Options; -- 2.43.0