public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
To: Simon Wright <simon.j.wright@mac.com>
Cc: gcc-patches@gcc.gnu.org, Arnaud Charlet <charlet@adacore.com>
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	[thread overview]
Message-ID: <146E92A8-A4E2-420F-A83D-92A585E32A2A@pushface.org> (raw)
In-Reply-To: <F37044CA-476B-488D-8C3C-EB6E0DE799FA@pushface.org>

[-- 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 --]



  reply	other threads:[~2017-03-07 16:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-15 16:31 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 [this message]
2017-12-05 17:16           ` Simon Wright
2017-12-05 18:09             ` Arnaud Charlet
2017-12-19  8:41             ` Arnaud Charlet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=146E92A8-A4E2-420F-A83D-92A585E32A2A@pushface.org \
    --to=simon@pushface.org \
    --cc=charlet@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=simon.j.wright@mac.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).