* [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime @ 2015-06-15 16:31 Simon Wright 2015-11-11 19:43 ` Simon Wright 0 siblings, 1 reply; 9+ messages in thread From: Simon Wright @ 2015-06-15 16:31 UTC (permalink / raw) To: gcc-patches [-- Attachment #1: Type: text/plain, Size: 1060 bytes --] If the RTS in use is "configurable" (I believe this is the same in this context as "restricted") and includes finalization, gnatbind generates binder code that won't compile. This situation arises, for example, with an embedded RTS that incorporates the Ada 2012 generalized container iterators. The attached patch was bootstrapped/regression tested (make check-ada) against 5.1.0 on x86_64-apple-darwin13 (which confirms that the patch hasn't broken builds against the standard RTS). arm-eabi-gnatbind was successful against both an RTS with finalization and one without. The patch applies with no offset to the trunk. gcc/ada/Changelog: 2015-6-15 Simon Wright <simon@pushface.org> PR ada/66205 * bindgen.adb (Gen_Adafinal): if Configurable_Run_Time_On_Target is true, generate a null body. (Gen_Main): if Configurable_Run_Time_On_Target is true, then - don't import __gnat_initialize or __gnat_finalize (as Initialize, Finalize rsp). - don't call Initialize or Finalize. [-- Attachment #2: pr66205.diff --] [-- Type: application/octet-stream, Size: 1431 bytes --] diff -r 241625079f4f gcc/ada/bindgen.adb --- a/gcc/ada/bindgen.adb Sat Apr 25 16:51:45 2015 +0100 +++ b/gcc/ada/bindgen.adb Mon Jun 15 16:51:38 2015 +0100 @@ -380,6 +380,15 @@ begin WBI (" procedure " & Ada_Final_Name.all & " is"); + if Configurable_Run_Time_On_Target then + -- Nothing to do + WBI (" begin"); + WBI (" null;"); + WBI (" end " & Ada_Final_Name.all & ";"); + WBI (""); + return; + end if; + if VM_Target = No_VM and Bind_Main_Program and not CodePeer_Mode @@ -1703,6 +1712,7 @@ if not CodePeer_Mode and then not Cumulative_Restrictions.Set (No_Finalization) + and then not Configurable_Run_Time_On_Target then WBI (" procedure Initialize (Addr : System.Address);"); WBI (" pragma Import (C, Initialize, ""__gnat_initialize"");"); @@ -1806,6 +1816,7 @@ end if; if not Cumulative_Restrictions.Set (No_Finalization) + and then not Configurable_Run_Time_On_Target and then not CodePeer_Mode then if not No_Main_Subprogram @@ -1851,6 +1862,7 @@ -- Finalize is only called if we have a run time if not Cumulative_Restrictions.Set (No_Finalization) + and then not Configurable_Run_Time_On_Target and then not CodePeer_Mode then WBI (" Finalize;"); ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime 2015-06-15 16:31 [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime Simon Wright @ 2015-11-11 19:43 ` Simon Wright 2015-11-12 8:56 ` Simon Wright 0 siblings, 1 reply; 9+ messages in thread From: Simon Wright @ 2015-11-11 19:43 UTC (permalink / raw) To: Simon Wright; +Cc: gcc-patches [-- Attachment #1: Type: text/plain, Size: 1638 bytes --] I’ve updated the original patch, which was built against 5.1.0 on x64_64-apple-darwin13, this patch is against 6.0.0-20151101 on x86_64-apple-darwin15. -------------- If the RTS in use is "configurable" (I believe this is the same in this context as "restricted") and includes finalization, gnatbind generates binder code that won't compile. This situation arises, for example, with an embedded RTS that incorporates the Ada 2012 generalized container iterators. I note that in the last 3 hunks of the attached patch there may be overkill; the original code checks whether the No_Finalization restriction doesn’t occur, and I’ve added a check that Configurable_Run_Time_On_Target isn’t set; I suspect, given other areas of the code, that the No_Finalization check is actually intended as a way of determining that this is a restricted runtime, and that the Configurable_Run_Time_On_Target check could replace it. The attached patch was bootstrapped/regression tested (make check-ada) against 6.0.0 on x86_64-apple-darwin15 (which confirms that the patch hasn't broken builds against the standard RTS). arm-eabi-gnatbind was successful against both an RTS with finalization and one without. gcc/ada/Changelog: 2015-11-11 Simon Wright <simon@pushface.org> PR ada/66205 * bindgen.adb (Gen_Adafinal): if Configurable_Run_Time_On_Target is true, generate a null body. (Gen_Main): if Configurable_Run_Time_On_Target is true, then - don't import __gnat_initialize or __gnat_finalize (as Initialize, Finalize rsp). - don't call Initialize or Finalize. [-- Attachment #2: gcc-6.0.0-20151101-gcc-ada-bindgen.adb.diff --] [-- Type: application/octet-stream, Size: 1758 bytes --] diff --git a/gcc/ada/bindgen.adb b/gcc/ada/bindgen.adb --- a/gcc/ada/bindgen.adb +++ b/gcc/ada/bindgen.adb @@ -415,6 +415,18 @@ begin WBI (" procedure " & Ada_Final_Name.all & " is"); + -- For restricted run-time libraries (ZFP and Ravenscar) tasks + -- are non-terminating, so we do not want finalization. + + if Configurable_Run_Time_On_Target then + -- Nothing to do + WBI (" begin"); + WBI (" null;"); + WBI (" end " & Ada_Final_Name.all & ";"); + WBI (""); + return; + end if; + if Bind_Main_Program and not CodePeer_Mode then WBI (" procedure s_stalib_adafinal;"); Set_String (" pragma Import (C, s_stalib_adafinal, "); @@ -1643,6 +1655,7 @@ if not CodePeer_Mode and then not Cumulative_Restrictions.Set (No_Finalization) + and then not Configurable_Run_Time_On_Target then WBI (" procedure Initialize (Addr : System.Address);"); WBI (" pragma Import (C, Initialize, ""__gnat_initialize"");"); @@ -1746,6 +1759,7 @@ end if; if not Cumulative_Restrictions.Set (No_Finalization) + and then not Configurable_Run_Time_On_Target and then not CodePeer_Mode then if not No_Main_Subprogram @@ -1788,9 +1802,11 @@ WBI (" Output_Results;"); end if; - -- Finalize is only called if we have a run time + -- Finalize is only called if we have a full (non-restricted) + -- run time if not Cumulative_Restrictions.Set (No_Finalization) + and then not Configurable_Run_Time_On_Target and then not CodePeer_Mode then WBI (" Finalize;"); ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime 2015-11-11 19:43 ` Simon Wright @ 2015-11-12 8:56 ` Simon Wright 2015-11-12 10:02 ` Arnaud Charlet 0 siblings, 1 reply; 9+ messages in thread From: Simon Wright @ 2015-11-12 8:56 UTC (permalink / raw) To: gcc-patches On 11 Nov 2015, at 19:43, Simon Wright <simon@pushface.org> wrote: > This situation arises, for example, with an embedded RTS that incorporates the > Ada 2012 generalized container iterators. 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? I didn’t make it plain that the comment I’ve put in the first hunk, -- For restricted run-time libraries (ZFP and Ravenscar) tasks -- are non-terminating, so we do not want finalization. is lifted from the unpatched code at line 480, where it relates to the use of Configurable_Run_Time_On_Target for this purpose. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime 2015-11-12 8:56 ` Simon Wright @ 2015-11-12 10:02 ` Arnaud Charlet 2015-12-19 22:05 ` Simon Wright 0 siblings, 1 reply; 9+ messages in thread From: Arnaud Charlet @ 2015-11-12 10:02 UTC (permalink / raw) To: Simon Wright; +Cc: gcc-patches > > This situation arises, for example, with an embedded RTS that > > incorporates the > > Ada 2012 generalized container iterators. > > 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? The proper patch for PR ada/66242 hasn't been committed yet (it's pending), so I'd rather review the situation once PR ada/66242 is dealt with. 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. Arno ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime 2015-11-12 10:02 ` Arnaud Charlet @ 2015-12-19 22:05 ` Simon Wright 2017-03-07 16:20 ` Simon Wright 0 siblings, 1 reply; 9+ messages in thread From: Simon Wright @ 2015-12-19 22:05 UTC (permalink / raw) To: Arnaud Charlet; +Cc: gcc-patches On 12 Nov 2015, at 10:02, Arnaud Charlet <charlet@adacore.com> wrote: > >>> This situation arises, for example, with an embedded RTS that >>> incorporates the >>> Ada 2012 generalized container iterators. >> >> 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? > > The proper patch for PR ada/66242 hasn't been committed yet (it's pending), > so I'd rather review the situation once PR ada/66242 is dealt with. > > 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. Looks as though PR ada/66242 has been sorted out. Since we can now *compile* code that is built with finalization enabled in 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 20151213 with minor offsets (8). ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime 2015-12-19 22:05 ` Simon Wright @ 2017-03-07 16:20 ` Simon Wright 2017-12-05 17:16 ` Simon Wright 0 siblings, 1 reply; 9+ messages in thread From: Simon Wright @ 2017-03-07 16:20 UTC (permalink / raw) To: Simon Wright; +Cc: gcc-patches, Arnaud Charlet [-- Attachment #1: Type: text/plain, Size: 2530 bytes --] On 19 Dec 2015, at 22:05, Simon Wright <simon@pushface.org> wrote: > > On 12 Nov 2015, at 10:02, Arnaud Charlet <charlet@adacore.com> wrote: >> >>>> This situation arises, for example, with an embedded RTS that >>>> incorporates the >>>> Ada 2012 generalized container iterators. >>> >>> 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? >> >> The proper patch for PR ada/66242 hasn't been committed yet (it's pending), >> so I'd rather review the situation once PR ada/66242 is dealt with. >> >> 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. > > Looks as though PR ada/66242 has been sorted out. > > Since we can now *compile* code that is built with finalization enabled in 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 20151213 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 support exception propagation but does support finalization. As far as gnatbind is concerned, "runtime does not support exception propagation" appears to be indicated by "Suppress_Standard_Library_On_Target" rather than "Cumulative_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 running 'make check-ada', and for --target=arm-eabi by successfully making and running builds for an STM32F4 target without exception propagation but with and without finalization. I used the same gnatbind for both targets - renamed to arm-eabi-gnatbind for those builds - seeing there's no target dependence in gnatbind itself. gcc/ada/Changelog: 2017-03-07 Simon Wright <simon@pushface.org> PR ada/66205 * bindgen.adb: If the restriction No_Finalization is absent (i.e. finalization is supported) but Suppress_Standard_Library_On_Target is true, then - don't import __gnat_initialize or __gnat_finalize (as Initialize, Finalize rsp). - don't call Initialize or Finalize. - don't generate or call adafinal. [-- Attachment #2: gcc-ada-bindgen.adb.diff --] [-- Type: application/octet-stream, Size: 2473 bytes --] 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; [-- Attachment #3: Type: text/plain, Size: 1 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime 2017-03-07 16:20 ` Simon Wright @ 2017-12-05 17:16 ` Simon Wright 2017-12-05 18:09 ` Arnaud Charlet 2017-12-19 8:41 ` Arnaud Charlet 0 siblings, 2 replies; 9+ messages in thread From: Simon Wright @ 2017-12-05 17:16 UTC (permalink / raw) To: Simon Wright; +Cc: gcc-patches, Arnaud Charlet [-- Attachment #1: Type: text/plain, Size: 2367 bytes --] On 7 Mar 2017, at 16:20, Simon Wright <simon@pushface.org> wrote: > > On 19 Dec 2015, at 22:05, Simon Wright <simon@pushface.org> wrote: >> >> On 12 Nov 2015, at 10:02, Arnaud Charlet <charlet@adacore.com> wrote: >>> >>>>> This situation arises, for example, with an embedded RTS that >>>>> incorporates the >>>>> Ada 2012 generalized container iterators. >>>> >>>> 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? >>> >>> The proper patch for PR ada/66242 hasn't been committed yet (it's pending), >>> so I'd rather review the situation once PR ada/66242 is dealt with. >>> >>> 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. >> >> Looks as though PR ada/66242 has been sorted out. >> >> Since we can now *compile* code that is built with finalization enabled in 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 20151213 with minor offsets (8). > > Same problem exists in gcc version 7.0.1 20170302 (experimental) (GCC). and with gcc 8.0.0 20171102 (experimental) (r254339); and there's been no change to the affected file (bindgen.adb) since then. I've come up with a considerably simpler patch, which merely causes the procedure adafinal to be generated with a null body if the restriction No_Task_Termination is set (note, this restriction is part of the Ravenscar profile; if tasks can't terminate, program level finalization can't happen [ARM 10.2(25), "When the environment task completes (normally or abnormally), it waits for the termination of all such tasks, and then finalizes any remaining objects of the partition."] I've bootstrapped the compiler (x86_64-apple-darwin15), and "make check-ada" produces the same results with and without the patch (the same 3 FAILs occur in both, in gnat.sum). For the arm-eabi compiler, I successfully make and run builds for an STM32F4 target without exception propagation but with and without finalization. gcc/ada/Changelog: 2017-12-05 Simon Wright <simon@pushface.org> PR ada/66205 * bindgen.adb (Gen_AdaFinal): If the restriction No_Task_Termination is present, generate a null body. [-- Attachment #2: bindgen.adb.diff --] [-- Type: application/octet-stream, Size: 1003 bytes --] diff --git a/gcc/ada/bindgen.adb b/gcc/ada/bindgen.adb index e3d875bc8cc..b02360087ef 100644 --- a/gcc/ada/bindgen.adb +++ b/gcc/ada/bindgen.adb @@ -450,6 +450,20 @@ package body Bindgen is begin WBI (" procedure " & Ada_Final_Name.all & " is"); + -- If task termination isn't allowed (as is the case in + -- restricted runtimes, such as Ravenscar or ZFP, but may not + -- be the case for all configurable runtimes), we don't need + -- program-level finalization. + + if Cumulative_Restrictions.Set (No_Task_Termination) then + -- Nothing to do + WBI (" begin"); + WBI (" null;"); + WBI (" end " & Ada_Final_Name.all & ";"); + WBI (""); + return; + end if; + -- Call s_stalib_adafinal to await termination of tasks and so on. We -- want to do this if there is a main program, either in Ada or in some -- other language. (Note that Bind_Main_Program is True for Ada mains, ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime 2017-12-05 17:16 ` Simon Wright @ 2017-12-05 18:09 ` Arnaud Charlet 2017-12-19 8:41 ` Arnaud Charlet 1 sibling, 0 replies; 9+ messages in thread From: Arnaud Charlet @ 2017-12-05 18:09 UTC (permalink / raw) To: Simon Wright; +Cc: gcc-patches > I've come up with a considerably simpler patch, which merely causes the > procedure adafinal to be generated with a null body if the restriction > No_Task_Termination is set (note, this restriction is part of the > Ravenscar profile; if tasks can't terminate, program level finalization > can't happen [ARM 10.2(25), "When the environment task completes > (normally or abnormally), it waits for the termination of all such tasks, > and then finalizes any remaining objects of the partition."] > > I've bootstrapped the compiler (x86_64-apple-darwin15), and "make > check-ada" produces the same results with and without the patch (the same 3 > FAILs occur in both, in gnat.sum). For the arm-eabi compiler, I > successfully make and run builds for an STM32F4 target without exception > propagation but with and without finalization. That's a much simpler and better approach indeed. OK to commit. > gcc/ada/Changelog: > > 2017-12-05 Simon Wright <simon@pushface.org> > > PR ada/66205 > * bindgen.adb (Gen_AdaFinal): If the restriction > No_Task_Termination is present, generate a null body. > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime 2017-12-05 17:16 ` Simon Wright 2017-12-05 18:09 ` Arnaud Charlet @ 2017-12-19 8:41 ` Arnaud Charlet 1 sibling, 0 replies; 9+ messages in thread From: Arnaud Charlet @ 2017-12-19 8:41 UTC (permalink / raw) To: Simon Wright; +Cc: gcc-patches, Eric Botcazou, Pierre-Marie de Rodat Simon, Unfortunately we've discovered that your patch is causing unexpected consequences and break e.g. testing of ravenscar application, where although the Ada RM requires no task termination, for practical purposes, waiting for terminating task is something we rely upon for automatic testing, so your patch is suitable after all, sorry about the oversight. After internal discussions at AdaCore, it appears that if you want Finalization, you chould set Suppress_Standard_Library_On_Target to False. All your troubles come from the fac tthat you tries to stick to Suppress_Standard_Library_On_Target set to True, but this combination (Suppress_Standard_Library_On_Target set to True, and Finalization enabled) is simpled not supported in the GNAT runtime, and the binder doesn't expect it either. So I'm going to revert your change in bindgen.adb and will let you experiment with setting Suppress_Standard_Library_On_Target to False in your system.ads. This is what we do in e.g.. our ravenscar-full runtime which supports precisely both ravenscar tasking, and finalization (among other things), on bare metal targets, which seems to correspond to what you are trying to do. Arno > gcc/ada/Changelog: > > 2017-12-05 Simon Wright <simon@pushface.org> > > PR ada/66205 > * bindgen.adb (Gen_AdaFinal): If the restriction > No_Task_Termination is present, generate a null body. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2017-12-19 8:41 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-06-15 16:31 [PATCH] PR ada/66205 gnatbind generates invalid code when finalization is enabled in restricted runtime Simon Wright 2015-11-11 19:43 ` Simon Wright 2015-11-12 8:56 ` Simon Wright 2015-11-12 10:02 ` Arnaud Charlet 2015-12-19 22:05 ` Simon Wright 2017-03-07 16:20 ` Simon Wright 2017-12-05 17:16 ` Simon Wright 2017-12-05 18:09 ` Arnaud Charlet 2017-12-19 8:41 ` Arnaud Charlet
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).