From patchwork Thu Jul 11 08:03:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1130694 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-504899-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="PHmMoVr3"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45kpZ01JpNz9sNF for ; Thu, 11 Jul 2019 18:07:20 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=q67CZgD6BzuddJ7QvQShoLKcgznC9GeTZQekRWN05Yu3FnLPwd B9j6DKSN/av4gz+Ns+ceJJsoC/DUwattlmh+o51CMTxWEkjRpGuZSMO1ofDPza6m uehSdzS5RgPUfZe1fixILVwvoQMfStDBFdVUy0y0iJwHjWzkYeGM5RP5g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=HSR8FUDC7UPQ/Xk4NamDYid12OM=; b=PHmMoVr3F2V20Awwzcmb LKC1c0GYLWtJJgJyNHy2oYoo7qFuN+ue8c/VYLFvPOslHlxVhOBGwGEXtsmVAPIP r1Ex999t5Vgth2vcXID58Q82q2XB4dHBdXZ82hoYWY4BGxv9nsF/tkxzqgXqnpkq kBFYjMPo1nYaTwbDuhrq6Bo= Received: (qmail 89599 invoked by alias); 11 Jul 2019 08:04:09 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 88168 invoked by uid 89); 11 Jul 2019 08:03:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_NEUTRAL, WEIRD_QUOTING autolearn=ham version=3.3.1 spammy= X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (209.51.188.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 Jul 2019 08:03:53 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlU3Q-0007vY-Ht for gcc-patches@gcc.gnu.org; Thu, 11 Jul 2019 04:03:50 -0400 Received: from rock.gnat.com ([205.232.38.15]:38476) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlU3Q-0007uU-7K for gcc-patches@gcc.gnu.org; Thu, 11 Jul 2019 04:03:48 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 1BD10561F4; Thu, 11 Jul 2019 04:03:47 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 2QU64zdyJwaw; Thu, 11 Jul 2019 04:03:47 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 0AA5C56019; Thu, 11 Jul 2019 04:03:47 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 0945D6F7; Thu, 11 Jul 2019 04:03:47 -0400 (EDT) Date: Thu, 11 Jul 2019 04:03:47 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Patrick Bernardi Subject: [Ada] Minimal binder Message-ID: <20190711080346.GA95257@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 205.232.38.15 X-IsSubscribed: yes 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. Tested on x86_64-pc-linux-gnu, committed on trunk 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. --- gcc/ada/bindgen.adb +++ 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 (""); --- gcc/ada/bindusg.adb +++ 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 --- gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst +++ 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) --- gcc/ada/gnat_ugn.texi +++ 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} --- gcc/ada/gnatbind.adb +++ 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 --- gcc/ada/opt.ads +++ 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