From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 97493 invoked by alias); 7 Mar 2017 16:20:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 97475 invoked by uid 89); 7 Mar 2017 16:20:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=U*charlet, sk:charlet, Hx-languages-length:2544, wright X-HELO: smtp.hosts.co.uk Received: from smtp.hosts.co.uk (HELO smtp.hosts.co.uk) (85.233.160.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 Mar 2017 16:20:50 +0000 Received: from [86.174.95.28] (helo=[192.168.1.99]) by smtp.hosts.co.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.88) (envelope-from ) id 1clHqz-0002ku-Ba; Tue, 07 Mar 2017 16:20:49 +0000 From: Simon Wright Message-Id: <146E92A8-A4E2-420F-A83D-92A585E32A2A@pushface.org> Content-Type: multipart/mixed; boundary="Apple-Mail=_C720453C-EB32-4A20-B3A6-B9F5F53F9FD1" Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Subject: Re: [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime Date: Tue, 07 Mar 2017 16:20:00 -0000 In-Reply-To: Cc: gcc-patches@gcc.gnu.org, Arnaud Charlet To: Simon Wright References: <7942AA17-3258-4B36-8B93-35C0574583AA@pushface.org> <666D196C-C248-45B3-A20F-138CE6B00457@pushface.org> <20151112100205.GA9491@adacore.com> X-IsSubscribed: yes X-SW-Source: 2017-03/txt/msg00319.txt.bz2 --Apple-Mail=_C720453C-EB32-4A20-B3A6-B9F5F53F9FD1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Content-length: 2545 On 19 Dec 2015, at 22:05, Simon Wright wrote: >=20 > On 12 Nov 2015, at 10:02, Arnaud Charlet wrote: >>=20 >>>> This situation arises, for example, with an embedded RTS that >>>> incorporates the >>>> Ada 2012 generalized container iterators. >>>=20 >>> I should add, this PR is the ???other half??? of PR ada/66242, which is= fixed >>> in GCC 6; so please can it be reviewed? >>=20 >> The proper patch for PR ada/66242 hasn't been committed yet (it's pendin= g), >> so I'd rather review the situation once PR ada/66242 is dealt with. >>=20 >> I'm not convinced at all that your patch is the way to go, so I'd rather >> consider it only after PR ada/66242 is solved properly. >=20 > Looks as though PR ada/66242 has been sorted out. >=20 > Since we can now *compile* code that is built with finalization enabled i= n a restricted runtime, but we can't *bind* it, could we take another look = at this? the patch I provided in this thread still applies at snapshot 2015= 1213 with minor offsets (8). Same problem exists in gcc version 7.0.1 20170302 (experimental) (GCC). Note, what may not have been clear before and is now relevant given AdaCore= 's -full- embedded runtimes, the problem occurs when the runtime doesn't su= pport exception propagation but does support finalization. As far as gnatbi= nd is concerned, "runtime does not support exception propagation" appears t= o be indicated by "Suppress_Standard_Library_On_Target" rather than "Cumula= tive_Restrictions.Set (No_Exception_Propagation)" - the latter is partition= -wide, so could be used instead maybe? I attach an updated patch. I've tested the new gnatbind against gcc version= 7.0.1 20170302 (experimental) (GCC) on native x86_64-apple-darwin16 by run= ning 'make check-ada', and for --target=3Darm-eabi by successfully making a= nd running builds for an STM32F4 target without exception propagation but w= ith and without finalization. I used the same gnatbind for both targets - renamed to arm-eabi-gnatbind fo= r those builds - seeing there's no target dependence in gnatbind itself. gcc/ada/Changelog: 2017-03-07 Simon Wright PR ada/66205 * bindgen.adb: If the restriction No_Finalization is absent (i.e. fin= alization is supported) but Suppress_Standard_Library_On_Target is true, then= =20 - don't import __gnat_initialize or __gnat_finalize (as Initialize,= Finalize rsp). - don't call Initialize or Finalize. - don't generate or call adafinal. --Apple-Mail=_C720453C-EB32-4A20-B3A6-B9F5F53F9FD1 Content-Disposition: attachment; filename=gcc-ada-bindgen.adb.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="gcc-ada-bindgen.adb.diff" Content-Transfer-Encoding: 7bit Content-length: 2473 diff --git a/gcc/ada/bindgen.adb b/gcc/ada/bindgen.adb index b4d7cec..daf4fa0 100644 --- a/gcc/ada/bindgen.adb +++ b/gcc/ada/bindgen.adb @@ -1603,6 +1603,7 @@ package body Bindgen is if not CodePeer_Mode and then not Cumulative_Restrictions.Set (No_Finalization) + and then not Suppress_Standard_Library_On_Target then WBI (" procedure Initialize (Addr : System.Address);"); WBI (" pragma Import (C, Initialize, ""__gnat_initialize"");"); @@ -1706,6 +1707,7 @@ package body Bindgen is end if; if not Cumulative_Restrictions.Set (No_Finalization) + and then not Suppress_Standard_Library_On_Target and then not CodePeer_Mode then if not No_Main_Subprogram @@ -1736,9 +1738,12 @@ package body Bindgen is end if; end if; - -- Adafinal call is skipped if no finalization + -- Adafinal call is skipped if no finalization or no exception + -- propagation - if not Cumulative_Restrictions.Set (No_Finalization) then + if not Cumulative_Restrictions.Set (No_Finalization) + and then not Suppress_Standard_Library_On_Target + then WBI (" adafinal;"); end if; @@ -1751,6 +1756,7 @@ package body Bindgen is -- Finalize is only called if we have a run time if not Cumulative_Restrictions.Set (No_Finalization) + and then not Suppress_Standard_Library_On_Target and then not CodePeer_Mode then WBI (" Finalize;"); @@ -2203,7 +2209,9 @@ package body Bindgen is WBI (" pragma Linker_Constructor (" & Ada_Init_Name.all & ");"); end if; - if not Cumulative_Restrictions.Set (No_Finalization) then + if not Cumulative_Restrictions.Set (No_Finalization) + and then not Suppress_Standard_Library_On_Target + then WBI (""); WBI (" procedure " & Ada_Final_Name.all & ";"); WBI (" pragma Export (C, " & Ada_Final_Name.all & ", """ & @@ -2388,7 +2396,9 @@ package body Bindgen is -- Generate the adafinal routine unless there is no finalization to do - if not Cumulative_Restrictions.Set (No_Finalization) then + if not Cumulative_Restrictions.Set (No_Finalization) + and then not Suppress_Standard_Library_On_Target + then if Needs_Library_Finalization then Gen_Finalize_Library (Elab_Order); end if; --Apple-Mail=_C720453C-EB32-4A20-B3A6-B9F5F53F9FD1 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Content-length: 1 --Apple-Mail=_C720453C-EB32-4A20-B3A6-B9F5F53F9FD1--