public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Help required re ARM EABI ZCX Ada (4.6.1)
@ 2011-10-09 19:43 Luke A. Guest
  2011-10-10  5:08 ` ARM EABI ZCX Ada (4.6.1) almost working Luke A. Guest
  0 siblings, 1 reply; 8+ messages in thread
From: Luke A. Guest @ 2011-10-09 19:43 UTC (permalink / raw)
  To: GCC ML

[-- Attachment #1: Type: text/plain, Size: 2583 bytes --]

Hi,

I got back to this yesterday and have tried to port over the ARM code
from the C++/Java exception files. I have managed to build a native
compiler (using make bootstrap) and run the test suite (logs not
included due to their size), but the general summary is as follows:

                === gcc Summary ===

# of expected passes            78536
# of unexpected failures        40
# of unexpected successes       38
# of expected failures          222
# of unsupported tests          1145

                === gnat Summary ===

# of expected passes            871
# of expected failures          10
# of unsupported tests          2

                === acats Summary ===
# of expected passes            2321
# of unexpected failures        0

My host machine is:

Linux rogue 2.6.32-5-amd64 #1 SMP Tue Jun 14 09:42:28 UTC 2011 x86_64
GNU/Linux


I have then built for arm-linux-gnueabi and have an installed toolchain
(no compile errors) and a running QEMU which can be logged into
automatically by me via SSH and which has a TAP set up, I run this with:

qemu-system-arm -k en-gb -m 256 -M versatilepb -kernel
~/opt/arm/vmlinuz-2.6.32-5-versatile -initrd
~/opt/arm/initrd.img-2.6.32-5-versatile -hda ~/opt/arm/arm-debian.img
-append "root=/dev/sda1" -net nic -net
tap,ifname=tap0,script=no,downscript=no

I have set up 2 env vars for DejaGNU:

DEJAGNU=/home/laguest/src/others/gcc-zxc-arm/dejagnu/site.exp
DEJAGNU_TIMEOUT=-1

I have the set up a board called angel.exp and these can be seen in the
attachments.

When I initially had the results, I had DEJAGNU_TIMEOUT=5400, I didn't
realise there was a separate timeout for the compiler. Due to the speed
I've not rerun these tests.

There is a problem with the Ada test suite for cross targets, on
starting I get the following error:

make[1]: Entering directory
`/home/laguest/src/others/gcc-zxc-arm/arm-build-gcc-4.6.1/gcc'
gnattools missing, exiting.
make[1]: *** [check-acats] Error 1

It then continues with the gnat tests, but fails to run the acats tests.
That message comes from the run_acats script.

I have compiled a test program, exc.adb which does not catch the
exceptions, so I know this ARM code does not work properly yet. The
error on the arm side is:

raised EXC.T : exc.adb:6

I'm obviously missing something here, can someone knowledgeable look
over the patch and see what it is?

Can anyone confirm that the Ada test suite should work for cross
targets?

If anyone has a target this can be tested for and has a working test
suite, can they apply the patch and see what results they get?

Thanks,
Luke.


[-- Attachment #2: site.exp --]
[-- Type: text/plain, Size: 163 bytes --]

append boards_dir "/home/laguest/src/others/gcc-zxc-arm/dejagnu/boards"
case "$target_triplet" in {
      { "arm*-linux-gnueabi" } { set target_list { angel } }
}

[-- Attachment #3: angel.exp --]
[-- Type: text/plain, Size: 201 bytes --]

load_generic_config "unix"
set_board_info hostname "192.168.0.5"
set_board_info username laguest
set_board_info rsh_prog /usr/bin/ssh
set_board_info rcp_prog /usr/bin/scp
set_board_info gcc,timeout -1

[-- Attachment #4: arm-linux-gnat.log.bz2 --]
[-- Type: application/x-bzip, Size: 62067 bytes --]

[-- Attachment #5: arm-linux-gnat.sum.bz2 --]
[-- Type: application/x-bzip, Size: 4642 bytes --]

[-- Attachment #6: arm-linux-zcx.diff --]
[-- Type: text/x-patch, Size: 23546 bytes --]

diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/a-exexpr-gcc.adb gcc-4.6.1/gcc/ada/a-exexpr-gcc.adb
--- gcc-4.6.1.orig/gcc/ada/a-exexpr-gcc.adb	2009-04-09 16:00:19.000000000 +0100
+++ gcc-4.6.1/gcc/ada/a-exexpr-gcc.adb	2011-10-07 02:30:41.000000000 +0100
@@ -35,87 +35,11 @@
 with Ada.Unchecked_Deallocation;
 
 with System.Storage_Elements;  use System.Storage_Elements;
+with System.Exception_Unwind;  use System.Exception_Unwind;
 
 separate (Ada.Exceptions)
 package body Exception_Propagation is
 
-   ------------------------------------------------
-   -- Entities to interface with the GCC runtime --
-   ------------------------------------------------
-
-   --  These come from "C++ ABI for Itanium: Exception handling", which is
-   --  the reference for GCC. They are used only when we are relying on
-   --  back-end tables for exception propagation, which in turn is currently
-   --  only the case for Zero_Cost_Exceptions in GNAT5.
-
-   --  Return codes from the GCC runtime functions used to propagate
-   --  an exception.
-
-   type Unwind_Reason_Code is
-     (URC_NO_REASON,
-      URC_FOREIGN_EXCEPTION_CAUGHT,
-      URC_PHASE2_ERROR,
-      URC_PHASE1_ERROR,
-      URC_NORMAL_STOP,
-      URC_END_OF_STACK,
-      URC_HANDLER_FOUND,
-      URC_INSTALL_CONTEXT,
-      URC_CONTINUE_UNWIND);
-
-   pragma Unreferenced
-     (URC_FOREIGN_EXCEPTION_CAUGHT,
-      URC_PHASE2_ERROR,
-      URC_PHASE1_ERROR,
-      URC_NORMAL_STOP,
-      URC_END_OF_STACK,
-      URC_HANDLER_FOUND,
-      URC_INSTALL_CONTEXT,
-      URC_CONTINUE_UNWIND);
-
-   pragma Convention (C, Unwind_Reason_Code);
-
-   --  Phase identifiers
-
-   type Unwind_Action is
-     (UA_SEARCH_PHASE,
-      UA_CLEANUP_PHASE,
-      UA_HANDLER_FRAME,
-      UA_FORCE_UNWIND);
-
-   for Unwind_Action use
-      (UA_SEARCH_PHASE  => 1,
-       UA_CLEANUP_PHASE => 2,
-       UA_HANDLER_FRAME => 4,
-       UA_FORCE_UNWIND  => 8);
-
-   pragma Convention (C, Unwind_Action);
-
-   --  Mandatory common header for any exception object handled by the
-   --  GCC unwinding runtime.
-
-   type Exception_Class is mod 2 ** 64;
-
-   GNAT_Exception_Class : constant Exception_Class := 16#474e552d41646100#;
-   --  "GNU-Ada\0"
-
-   type Unwind_Word is mod 2 ** System.Word_Size;
-   for Unwind_Word'Size use System.Word_Size;
-   --  Map the corresponding C type used in Unwind_Exception below
-
-   type Unwind_Exception is record
-      Class    : Exception_Class := GNAT_Exception_Class;
-      Cleanup  : System.Address  := System.Null_Address;
-      Private1 : Unwind_Word;
-      Private2 : Unwind_Word;
-   end record;
-   --  Map the GCC struct used for exception handling
-
-   for Unwind_Exception'Alignment use Standard'Maximum_Alignment;
-   --  The C++ ABI mandates the common exception header to be at least
-   --  doubleword aligned, and the libGCC implementation actually makes it
-   --  maximally aligned (see unwind.h). See additional comments on the
-   --  alignment below.
-
    --------------------------------------------------------------
    -- GNAT Specific Entities To Deal With The GCC EH Circuitry --
    --------------------------------------------------------------
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/ChangeLog gcc-4.6.1/gcc/ada/ChangeLog
--- gcc-4.6.1.orig/gcc/ada/ChangeLog	2011-06-27 11:03:04.000000000 +0100
+++ gcc-4.6.1/gcc/ada/ChangeLog	2011-10-09 11:51:05.000000000 +0100
@@ -1,3 +1,18 @@
+2011-10-09 Luke A. Guest <laguest@archeia.com>
+
+	* Initial port of ZCX code to ARM Linux.
+	* s-excunw-gcc.ads: New file, extracts the normal GCC Unwind_Exception
+	into it's own package.
+	* s-excunw-gcc-arm.ads: New file, extracts the ARM EABI GCC
+	Unwind_Exception into it's own package.
+	* a-exexpr-gcc.adb: Unwind_Exception and other enumerations removed.
+	* gcc-interface/Makefile.in: Handle new files to build for native and
+	ARM EABI exception blocks.
+	* Makefile.rtl: Added a line to build above unwind exception package.
+	* raise-gcc.c: Added support for ARM EABI UNWINDER.
+	* system-linux-armeb.ads: Changed to support ZCX instead of SJLJ.
+	* system-linux-armel.ads: Changed to support ZCX instead of SJLJ.
+
 2011-06-27  Release Manager
 
 	* GCC 4.6.1 released.
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/gcc-interface/Makefile.in gcc-4.6.1/gcc/ada/gcc-interface/Makefile.in
--- gcc-4.6.1.orig/gcc/ada/gcc-interface/Makefile.in	2011-02-08 22:55:57.000000000 +0000
+++ gcc-4.6.1/gcc/ada/gcc-interface/Makefile.in	2011-10-09 01:05:39.000000000 +0100
@@ -360,6 +360,10 @@
 
 EH_MECHANISM=
 
+# When using the GCC exception handling mechanism, we need to specify which
+# Unwind_Exception record to use.
+EH_UNWIND_BLOCK=
+
 # Default shared object option. Note that we rely on the fact that the "soname"
 # option will always be present and last in this flag, so that we can have
 # $(SO_OPTS)libgnat-x.xx
@@ -1869,7 +1873,8 @@
     indepsw.adb<indepsw-gnu.adb
 
   EXTRA_GNATRTL_TASKING_OBJS=s-linux.o
-  EH_MECHANISM=
+  EH_MECHANISM=-gcc
+  EH_UNWIND_BLOCK=-arm
   THREADSLIB = -lpthread
   GNATLIB_SHARED = gnatlib-shared-dual
   GMEM_LIB = gmemlib
@@ -2194,6 +2199,11 @@
   EXTRA_LIBGNAT_OBJS+=raise$(EH_MECHANISM).o
 endif
 
+# This only gets included if we're using ZCX.
+ifeq ($(EH_MECHANISM),-gcc)
+  LIBGNAT_TARGET_PAIRS += s-excunw.ads<s-excunw$(EH_MECHANISM)$(EH_UNWIND_BLOCK).ads
+endif
+
 # Use the Ada 2005 version of Ada.Exceptions by default, unless specified
 # explicitly already. The base files (a-except.ad?) are used only for building
 # the compiler and other basic tools.
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/Makefile.rtl gcc-4.6.1/gcc/ada/Makefile.rtl
--- gcc-4.6.1.orig/gcc/ada/Makefile.rtl	2010-10-26 11:42:02.000000000 +0100
+++ gcc-4.6.1/gcc/ada/Makefile.rtl	2011-10-07 12:10:47.000000000 +0100
@@ -468,6 +468,7 @@
   s-dsaser$(objext) \
   s-except$(objext) \
   s-exctab$(objext) \
+  s-excunw$(objext) \
   s-exnint$(objext) \
   s-exnllf$(objext) \
   s-exnlli$(objext) \
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/raise-gcc.c gcc-4.6.1/gcc/ada/raise-gcc.c
--- gcc-4.6.1.orig/gcc/ada/raise-gcc.c	2010-10-26 11:52:27.000000000 +0100
+++ gcc-4.6.1/gcc/ada/raise-gcc.c	2011-10-09 01:40:06.000000000 +0100
@@ -534,6 +534,24 @@
 /* Retrieve the ttype entry associated with FILTER in the REGION's
    ttype table.  */
 
+#ifdef __ARM_EABI_UNWINDER__
+
+/* Based on code inside eh_personality.cc (C++) and exception.cc (Java) */
+
+static const _Unwind_Ptr
+get_ttype_entry_for (region_descriptor *region, long filter)
+{
+  _Unwind_Ptr ttype_entry;
+
+  ttype_entry = (_Unwind_Ptr) (region->ttype_table - (filter * 4));
+  
+  ttype_entry = _Unwind_decode_target2(ttype_entry);
+
+  return ttype_entry;
+}
+
+#else
+
 static const _Unwind_Ptr
 get_ttype_entry_for (region_descriptor *region, long filter)
 {
@@ -547,6 +565,8 @@
   return ttype_entry;
 }
 
+#endif /* __ARM_EABI_UNWINDER__ */
+
 /* Fill out the REGION descriptor for the provided UW_CONTEXT.  */
 
 static void
@@ -1064,13 +1084,80 @@
 typedef _Unwind_Action phases_arg_t;
 #endif
 
+#ifdef __ARM_EABI_UNWINDER__
+
+#define CONTINUE_UNWINDING \
+  do								\
+    {								\
+      if (__gnu_unwind_frame(uw_exception, uw_context) != _URC_OK)	\
+	return _URC_FAILURE;					\
+      return _URC_CONTINUE_UNWIND;				\
+    }								\
+  while (0)
+
+PERSONALITY_FUNCTION (_Unwind_State state,
+		      struct _Unwind_Exception* uw_exception,
+		      struct _Unwind_Context* uw_context)
+#else
 _Unwind_Reason_Code
 PERSONALITY_FUNCTION (version_arg_t version_arg,
                       phases_arg_t phases_arg,
                       _Unwind_Exception_Class uw_exception_class,
                       _Unwind_Exception *uw_exception,
                       _Unwind_Context *uw_context)
+#endif
 {
+#ifdef __ARM_EABI_UNWINDER__
+  phases_arg_t phases_arg; /* _Unwind_Action actions; */
+  _Unwind_Ptr ip;
+
+  _Unwind_Action uw_phases = (_Unwind_Action) phases_arg;
+  _GNAT_Exception * gnat_exception = (_GNAT_Exception *) uw_exception;
+
+  region_descriptor region;
+  action_descriptor action;
+
+  switch (state & _US_ACTION_MASK)
+    {
+    case _US_VIRTUAL_UNWIND_FRAME:
+      phases_arg = _UA_SEARCH_PHASE;
+      break;
+
+    case _US_UNWIND_FRAME_STARTING:
+      phases_arg = _UA_CLEANUP_PHASE;
+
+      if (!(state & _US_FORCE_UNWIND)
+	  && uw_exception->barrier_cache.sp == _Unwind_GetGR(uw_context, 13))
+	phases_arg |= _UA_HANDLER_FRAME;
+      break;
+
+    case _US_UNWIND_FRAME_RESUME:
+      CONTINUE_UNWINDING;
+      /*      return _URC_CONTINUE_UNWIND;*/
+      break;
+
+    default:
+      /* Is this correct? */
+      /* return _URC_FATAL_PHASE1_ERROR;*/
+      abort ();
+    }
+  phases_arg |= state & _US_FORCE_UNWIND;
+
+  /* We don't know which runtime we're working with, so can't check this.
+   * However the ABI routines hide this from us, and we don't actually need
+   * to know.
+   */
+  /* foreign_exception = false; */
+
+  /* The dwarf unwinder assumes the context structure holds things like the
+   * function and LSDA pointers.  The ARM implementation caches these in
+   * the exception header (UCB).  To avoid rewriting everything we make the
+   * virtual IP register point at the UCB.
+   */
+  ip = (_Unwind_Ptr) uw_exception;
+
+  _Unwind_SetGR(uw_context, 12, ip);
+#else
   /* Fetch the version and phases args with their nominal ABI types for later
      use. This is a noop everywhere except on ia64-vms when called from the
      Condition Handling Facility.  */
@@ -1104,6 +1191,7 @@
 
       return _URC_FATAL_PHASE1_ERROR;
     }
+#endif
 
   db_indent (DB_INDENT_RESET);
   db_phases (uw_phases);
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/s-excunw-gcc.ads gcc-4.6.1/gcc/ada/s-excunw-gcc.ads
--- gcc-4.6.1.orig/gcc/ada/s-excunw-gcc.ads	1970-01-01 01:00:00.000000000 +0100
+++ gcc-4.6.1/gcc/ada/s-excunw-gcc.ads	2011-10-07 12:40:40.000000000 +0100
@@ -0,0 +1,116 @@
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT COMPILER COMPONENTS                         --
+--                                                                          --
+--              S Y S T E M . E X C E P T I O N _ U N W I N D               --
+--                                                                          --
+--                                 S p e c                                  --
+--                                                                          --
+--          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  This version of the EH data structures is used for normal GCC EH
+
+package System.Exception_Unwind is
+   pragma Warnings (Off);
+   pragma Preelaborate_05;
+   pragma Warnings (On);
+
+   ------------------------------------------------
+   -- Entities to interface with the GCC runtime --
+   ------------------------------------------------
+
+   --  These come from "C++ ABI for Itanium: Exception handling", which is
+   --  the reference for GCC. They are used only when we are relying on
+   --  back-end tables for exception propagation, which in turn is currently
+   --  only the case for Zero_Cost_Exceptions in GNAT5.
+
+   --  Return codes from the GCC runtime functions used to propagate
+   --  an exception.
+
+   type Unwind_Reason_Code is
+     (URC_NO_REASON,
+      URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_PHASE2_ERROR,
+      URC_PHASE1_ERROR,
+      URC_NORMAL_STOP,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND);
+
+   pragma Unreferenced
+     (URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_PHASE2_ERROR,
+      URC_PHASE1_ERROR,
+      URC_NORMAL_STOP,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND);
+
+   pragma Convention (C, Unwind_Reason_Code);
+
+   --  Phase identifiers
+
+   type Unwind_Action is
+     (UA_SEARCH_PHASE,
+      UA_CLEANUP_PHASE,
+      UA_HANDLER_FRAME,
+      UA_FORCE_UNWIND);
+
+   for Unwind_Action use
+      (UA_SEARCH_PHASE  => 1,
+       UA_CLEANUP_PHASE => 2,
+       UA_HANDLER_FRAME => 4,
+       UA_FORCE_UNWIND  => 8);
+
+   pragma Convention (C, Unwind_Action);
+
+   --  Mandatory common header for any exception object handled by the
+   --  GCC unwinding runtime.
+
+   type Exception_Class is mod 2 ** 64;
+
+   GNAT_Exception_Class : constant Exception_Class := 16#474e552d41646100#;
+   --  "GNU-Ada\0"
+
+   type Unwind_Word is mod 2 ** System.Word_Size;
+   for Unwind_Word'Size use System.Word_Size;
+   --  Map the corresponding C type used in Unwind_Exception below
+
+   type Unwind_Exception is record
+      Class    : Exception_Class := GNAT_Exception_Class;
+      Cleanup  : System.Address  := System.Null_Address;
+      Private1 : Unwind_Word;
+      Private2 : Unwind_Word;
+   end record;
+   --  Map the GCC struct used for exception handling
+
+   for Unwind_Exception'Alignment use Standard'Maximum_Alignment;
+   --  The C++ ABI mandates the common exception header to be at least
+   --  doubleword aligned, and the libGCC implementation actually makes it
+   --  maximally aligned (see unwind.h). See additional comments on the
+   --  alignment below.
+
+end System.Exception_Unwind;
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/s-excunw-gcc-arm.ads gcc-4.6.1/gcc/ada/s-excunw-gcc-arm.ads
--- gcc-4.6.1.orig/gcc/ada/s-excunw-gcc-arm.ads	1970-01-01 01:00:00.000000000 +0100
+++ gcc-4.6.1/gcc/ada/s-excunw-gcc-arm.ads	2011-10-09 02:00:52.000000000 +0100
@@ -0,0 +1,170 @@
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT COMPILER COMPONENTS                         --
+--                                                                          --
+--              S Y S T E M . E X C E P T I O N _ U N W I N D               --
+--                                                                          --
+--                                 S p e c                                  --
+--                                                                          --
+--          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  This version of the EH data structures is used for ARM EABI GCC EH
+
+package System.Exception_Unwind is
+   pragma Warnings (Off);
+   pragma Preelaborate_05;
+   pragma Warnings (On);
+
+   ------------------------------------------------
+   -- Entities to interface with the GCC runtime --
+   ------------------------------------------------
+
+   --  These come from "C++ ABI for Itanium: Exception handling", which is
+   --  the reference for GCC. They are used only when we are relying on
+   --  back-end tables for exception propagation, which in turn is currently
+   --  only the case for Zero_Cost_Exceptions in GNAT5.
+
+   --  Return codes from the GCC runtime functions used to propagate
+   --  an exception.
+
+   type Unwind_Reason_Code is
+     (URC_OK,
+      URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND,
+      URC_FAILURE);
+
+   pragma Unreferenced
+     (URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND,
+      URC_FAILURE);
+
+   pragma Convention (C, Unwind_Reason_Code);
+
+   --  Phase identifiers
+
+   type Unwind_State is
+     (US_VIRTUAL_UNWIND_FRAME,
+      US_UNWIND_FRAME_STARTING,
+      US_UNWIND_FRAME_RESUME,
+      US_ACTION_MASK,
+      US_FORCE_UNWIND,
+      US_END_OF_STACK);
+
+   for Unwind_State use
+     (US_VIRTUAL_UNWIND_FRAME  => 0,
+      US_UNWIND_FRAME_STARTING => 1,
+      US_UNWIND_FRAME_RESUME   => 2,
+      US_ACTION_MASK           => 3,
+      US_FORCE_UNWIND          => 8,
+      US_END_OF_STACK          => 16);
+
+   pragma Convention (C, Unwind_State);
+
+   subtype Unwind_Action is Unwind_State;
+
+   --  UA_SEARCH_PHASE renames Unwind_State.US_UNWIND_FRAME_STARTING;
+   --  UA_CLEANUP_PHASE renames Unwind_State.US_UNWIND_FRAME_RESUME;
+   --  UA_HANDLER_FRAME renames Unwind_State.US_; -- 4!??
+   --  UA_FORCE_UNWIND renames Unwind_State.US_FORCE_UNWIND;
+   --  UA_END_OF_STACK renames Unwind_State.US_END_OF_STACK;
+
+   URC_NO_REASON : Unwind_Reason_Code renames URC_OK;
+
+   --  Mandatory common header for any exception object handled by the
+   --  GCC unwinding runtime.
+
+   type Exception_Class is mod 2 ** 64;
+
+   GNAT_Exception_Class : constant Exception_Class := 16#474e552d41646100#;
+   --  "GNU-Ada\0"
+
+   type Unwind_Word is mod 2 ** System.Word_Size;
+   for Unwind_Word'Size use System.Word_Size;
+   --  Map the corresponding C type used in Unwind_Exception below
+
+   type Unwinder_Caches is record
+      Reserved1 : Unwind_Word;
+      Reserved2 : Unwind_Word;
+      Reserved3 : Unwind_Word;
+      Reserved4 : Unwind_Word;
+   end record;
+
+   pragma Convention (C, Unwinder_Caches);
+
+   type Unwind_Array is array (Integer range <>) of Unwind_Word;
+
+   pragma Convention (C, Unwind_Array);
+
+   type Barrier_Caches is record
+      SP          : Unwind_Word;
+      Bit_Pattern : Unwind_Array (1 .. 5);
+   end record;
+
+   pragma Convention (C, Barrier_Caches);
+
+   type Unwind_EHT_Header_Ptr is access Unwind_Word;
+
+   pragma Convention (C, Unwind_EHT_Header_Ptr);
+
+   type PR_Caches is record
+      Function_Start : Unwind_Word;
+      EHTP           : Unwind_EHT_Header_Ptr;
+      Additional1    : Unwind_Word;
+      Reserved1      : Unwind_Word;
+   end record;
+
+   pragma Convention (C, PR_Caches);
+
+   type Unwind_Control_Block is record
+      Class          : Exception_Class := GNAT_Exception_Class;
+      Cleanup        : System.Address  := System.Null_Address;
+      Unwinder_Cache : Unwinder_Caches;
+      Barrier_Cache  : Barrier_Caches;
+      Cleanup_Cache  : Unwind_Array (1 .. 4);
+      PR_Cache       : PR_Caches;
+
+      --  The following are for compatability with the usual GNAT EH mechanism.
+      Private1 : Unwind_Word;
+      Private2 : Unwind_Word;
+   end record;
+
+   pragma Convention (C, Unwind_Control_Block);
+   --  Map the GCC struct used for exception handling.
+   --  Found in gcc/config/arm/unwind-arm.h
+
+   for Unwind_Control_Block'Alignment use Standard'Maximum_Alignment;
+   --  The C++ ABI mandates the common exception header to be at least
+   --  doubleword aligned, and the libGCC implementation actually makes it
+   --  maximally aligned (see unwind.h). See additional comments on the
+   --  alignment below.
+
+   subtype Unwind_Exception is Unwind_Control_Block;
+
+end System.Exception_Unwind;
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/system-linux-armeb.ads gcc-4.6.1/gcc/ada/system-linux-armeb.ads
--- gcc-4.6.1.orig/gcc/ada/system-linux-armeb.ads	2010-01-22 11:55:45.000000000 +0000
+++ gcc-4.6.1/gcc/ada/system-linux-armeb.ads	2011-10-08 22:30:03.000000000 +0100
@@ -147,7 +147,7 @@
    Always_Compatible_Rep     : constant Boolean := False;
    Suppress_Standard_Library : constant Boolean := False;
    Use_Ada_Main_Program_Name : constant Boolean := False;
-   ZCX_By_Default            : constant Boolean := False;
-   GCC_ZCX_Support           : constant Boolean := False;
+   ZCX_By_Default            : constant Boolean := True;
+   GCC_ZCX_Support           : constant Boolean := True;
 
 end System;
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/system-linux-armel.ads gcc-4.6.1/gcc/ada/system-linux-armel.ads
--- gcc-4.6.1.orig/gcc/ada/system-linux-armel.ads	2010-01-22 11:55:45.000000000 +0000
+++ gcc-4.6.1/gcc/ada/system-linux-armel.ads	2011-10-08 22:29:43.000000000 +0100
@@ -147,7 +147,7 @@
    Always_Compatible_Rep     : constant Boolean := False;
    Suppress_Standard_Library : constant Boolean := False;
    Use_Ada_Main_Program_Name : constant Boolean := False;
-   ZCX_By_Default            : constant Boolean := False;
-   GCC_ZCX_Support           : constant Boolean := False;
+   ZCX_By_Default            : constant Boolean := True;
+   GCC_ZCX_Support           : constant Boolean := True;
 
 end System;

[-- Attachment #7: exc.adb --]
[-- Type: text/x-adasrc, Size: 211 bytes --]

with Ada.Text_IO; use Ada.Text_IO;

procedure exc is
   T : exception;
begin
   raise T;
exception
   when Constraint_Error =>
      Put_Line("Constraint");
   when others =>
      Put_Line("others");
end exc;


^ permalink raw reply	[flat|nested] 8+ messages in thread

* ARM EABI ZCX Ada (4.6.1) almost working
  2011-10-09 19:43 Help required re ARM EABI ZCX Ada (4.6.1) Luke A. Guest
@ 2011-10-10  5:08 ` Luke A. Guest
  2011-10-10  8:45   ` Luke A. Guest
  0 siblings, 1 reply; 8+ messages in thread
From: Luke A. Guest @ 2011-10-10  5:08 UTC (permalink / raw)
  To: GCC ML

[-- Attachment #1: Type: text/plain, Size: 854 bytes --]

Hi,

I managed to debug the my sample app and find an error, which has made
catching an exception work.

Anyway, I changed the code to throw an exception in a nested subprogram,
this was also caught by the outer subprogram. I then added a raise;
statement as a handler to see if it would reraise and then exit the
program, sadly, I get an infinite loop in the search phase (export
EH_DEBUG=1 shows this).

I've included the latest patch which gets the basics working. But I'm
lost as to why it's not working for the reraise case.

Can anyone help?

Thanks,
Luke.

   ** Just for info, so it's documented somewhere **

Just for people who need to know (as I couldn't find it anywhere), to
get gnatlib to build with debugging info, I used the following:

make -e GNATLIBCFLAGS='-ggdb -O0'

This is then picked up the gcc/ada makefiles later in the build.


[-- Attachment #2: arm-linux-zcx.diff --]
[-- Type: text/x-patch, Size: 23582 bytes --]

diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/a-exexpr-gcc.adb gcc-4.6.1/gcc/ada/a-exexpr-gcc.adb
--- gcc-4.6.1.orig/gcc/ada/a-exexpr-gcc.adb	2009-04-09 16:00:19.000000000 +0100
+++ gcc-4.6.1/gcc/ada/a-exexpr-gcc.adb	2011-10-07 02:30:41.000000000 +0100
@@ -35,87 +35,11 @@
 with Ada.Unchecked_Deallocation;
 
 with System.Storage_Elements;  use System.Storage_Elements;
+with System.Exception_Unwind;  use System.Exception_Unwind;
 
 separate (Ada.Exceptions)
 package body Exception_Propagation is
 
-   ------------------------------------------------
-   -- Entities to interface with the GCC runtime --
-   ------------------------------------------------
-
-   --  These come from "C++ ABI for Itanium: Exception handling", which is
-   --  the reference for GCC. They are used only when we are relying on
-   --  back-end tables for exception propagation, which in turn is currently
-   --  only the case for Zero_Cost_Exceptions in GNAT5.
-
-   --  Return codes from the GCC runtime functions used to propagate
-   --  an exception.
-
-   type Unwind_Reason_Code is
-     (URC_NO_REASON,
-      URC_FOREIGN_EXCEPTION_CAUGHT,
-      URC_PHASE2_ERROR,
-      URC_PHASE1_ERROR,
-      URC_NORMAL_STOP,
-      URC_END_OF_STACK,
-      URC_HANDLER_FOUND,
-      URC_INSTALL_CONTEXT,
-      URC_CONTINUE_UNWIND);
-
-   pragma Unreferenced
-     (URC_FOREIGN_EXCEPTION_CAUGHT,
-      URC_PHASE2_ERROR,
-      URC_PHASE1_ERROR,
-      URC_NORMAL_STOP,
-      URC_END_OF_STACK,
-      URC_HANDLER_FOUND,
-      URC_INSTALL_CONTEXT,
-      URC_CONTINUE_UNWIND);
-
-   pragma Convention (C, Unwind_Reason_Code);
-
-   --  Phase identifiers
-
-   type Unwind_Action is
-     (UA_SEARCH_PHASE,
-      UA_CLEANUP_PHASE,
-      UA_HANDLER_FRAME,
-      UA_FORCE_UNWIND);
-
-   for Unwind_Action use
-      (UA_SEARCH_PHASE  => 1,
-       UA_CLEANUP_PHASE => 2,
-       UA_HANDLER_FRAME => 4,
-       UA_FORCE_UNWIND  => 8);
-
-   pragma Convention (C, Unwind_Action);
-
-   --  Mandatory common header for any exception object handled by the
-   --  GCC unwinding runtime.
-
-   type Exception_Class is mod 2 ** 64;
-
-   GNAT_Exception_Class : constant Exception_Class := 16#474e552d41646100#;
-   --  "GNU-Ada\0"
-
-   type Unwind_Word is mod 2 ** System.Word_Size;
-   for Unwind_Word'Size use System.Word_Size;
-   --  Map the corresponding C type used in Unwind_Exception below
-
-   type Unwind_Exception is record
-      Class    : Exception_Class := GNAT_Exception_Class;
-      Cleanup  : System.Address  := System.Null_Address;
-      Private1 : Unwind_Word;
-      Private2 : Unwind_Word;
-   end record;
-   --  Map the GCC struct used for exception handling
-
-   for Unwind_Exception'Alignment use Standard'Maximum_Alignment;
-   --  The C++ ABI mandates the common exception header to be at least
-   --  doubleword aligned, and the libGCC implementation actually makes it
-   --  maximally aligned (see unwind.h). See additional comments on the
-   --  alignment below.
-
    --------------------------------------------------------------
    -- GNAT Specific Entities To Deal With The GCC EH Circuitry --
    --------------------------------------------------------------
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/ChangeLog gcc-4.6.1/gcc/ada/ChangeLog
--- gcc-4.6.1.orig/gcc/ada/ChangeLog	2011-06-27 11:03:04.000000000 +0100
+++ gcc-4.6.1/gcc/ada/ChangeLog	2011-10-09 11:51:05.000000000 +0100
@@ -1,3 +1,18 @@
+2011-10-09 Luke A. Guest <laguest@archeia.com>
+
+	* Initial port of ZCX code to ARM Linux.
+	* s-excunw-gcc.ads: New file, extracts the normal GCC Unwind_Exception
+	into it's own package.
+	* s-excunw-gcc-arm.ads: New file, extracts the ARM EABI GCC
+	Unwind_Exception into it's own package.
+	* a-exexpr-gcc.adb: Unwind_Exception and other enumerations removed.
+	* gcc-interface/Makefile.in: Handle new files to build for native and
+	ARM EABI exception blocks.
+	* Makefile.rtl: Added a line to build above unwind exception package.
+	* raise-gcc.c: Added support for ARM EABI UNWINDER.
+	* system-linux-armeb.ads: Changed to support ZCX instead of SJLJ.
+	* system-linux-armel.ads: Changed to support ZCX instead of SJLJ.
+
 2011-06-27  Release Manager
 
 	* GCC 4.6.1 released.
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/gcc-interface/Makefile.in gcc-4.6.1/gcc/ada/gcc-interface/Makefile.in
--- gcc-4.6.1.orig/gcc/ada/gcc-interface/Makefile.in	2011-02-08 22:55:57.000000000 +0000
+++ gcc-4.6.1/gcc/ada/gcc-interface/Makefile.in	2011-10-09 01:05:39.000000000 +0100
@@ -360,6 +360,10 @@
 
 EH_MECHANISM=
 
+# When using the GCC exception handling mechanism, we need to specify which
+# Unwind_Exception record to use.
+EH_UNWIND_BLOCK=
+
 # Default shared object option. Note that we rely on the fact that the "soname"
 # option will always be present and last in this flag, so that we can have
 # $(SO_OPTS)libgnat-x.xx
@@ -1869,7 +1873,8 @@
     indepsw.adb<indepsw-gnu.adb
 
   EXTRA_GNATRTL_TASKING_OBJS=s-linux.o
-  EH_MECHANISM=
+  EH_MECHANISM=-gcc
+  EH_UNWIND_BLOCK=-arm
   THREADSLIB = -lpthread
   GNATLIB_SHARED = gnatlib-shared-dual
   GMEM_LIB = gmemlib
@@ -2194,6 +2199,11 @@
   EXTRA_LIBGNAT_OBJS+=raise$(EH_MECHANISM).o
 endif
 
+# This only gets included if we're using ZCX.
+ifeq ($(EH_MECHANISM),-gcc)
+  LIBGNAT_TARGET_PAIRS += s-excunw.ads<s-excunw$(EH_MECHANISM)$(EH_UNWIND_BLOCK).ads
+endif
+
 # Use the Ada 2005 version of Ada.Exceptions by default, unless specified
 # explicitly already. The base files (a-except.ad?) are used only for building
 # the compiler and other basic tools.
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/Makefile.rtl gcc-4.6.1/gcc/ada/Makefile.rtl
--- gcc-4.6.1.orig/gcc/ada/Makefile.rtl	2010-10-26 11:42:02.000000000 +0100
+++ gcc-4.6.1/gcc/ada/Makefile.rtl	2011-10-07 12:10:47.000000000 +0100
@@ -468,6 +468,7 @@
   s-dsaser$(objext) \
   s-except$(objext) \
   s-exctab$(objext) \
+  s-excunw$(objext) \
   s-exnint$(objext) \
   s-exnllf$(objext) \
   s-exnlli$(objext) \
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/raise-gcc.c gcc-4.6.1/gcc/ada/raise-gcc.c
--- gcc-4.6.1.orig/gcc/ada/raise-gcc.c	2010-10-26 11:52:27.000000000 +0100
+++ gcc-4.6.1/gcc/ada/raise-gcc.c	2011-10-09 19:02:55.000000000 +0100
@@ -534,6 +534,24 @@
 /* Retrieve the ttype entry associated with FILTER in the REGION's
    ttype table.  */
 
+#ifdef __ARM_EABI_UNWINDER__
+
+/* Based on code inside eh_personality.cc (C++) and exception.cc (Java) */
+
+static const _Unwind_Ptr
+get_ttype_entry_for (region_descriptor *region, long filter)
+{
+  _Unwind_Ptr ttype_entry;
+
+  ttype_entry = (_Unwind_Ptr) (region->ttype_table - (filter * 4));
+  
+  ttype_entry = _Unwind_decode_target2(ttype_entry);
+
+  return ttype_entry;
+}
+
+#else
+
 static const _Unwind_Ptr
 get_ttype_entry_for (region_descriptor *region, long filter)
 {
@@ -547,6 +565,8 @@
   return ttype_entry;
 }
 
+#endif /* __ARM_EABI_UNWINDER__ */
+
 /* Fill out the REGION descriptor for the provided UW_CONTEXT.  */
 
 static void
@@ -1064,13 +1084,82 @@
 typedef _Unwind_Action phases_arg_t;
 #endif
 
+#ifdef __ARM_EABI_UNWINDER__
+
+#define CONTINUE_UNWINDING \
+  do								\
+    {								\
+      if (__gnu_unwind_frame(uw_exception, uw_context) != _URC_OK)	\
+	return _URC_FAILURE;					\
+      return _URC_CONTINUE_UNWIND;				\
+    }								\
+  while (0)
+
+PERSONALITY_FUNCTION (_Unwind_State state,
+		      struct _Unwind_Exception* uw_exception,
+		      struct _Unwind_Context* uw_context)
+#else
 _Unwind_Reason_Code
 PERSONALITY_FUNCTION (version_arg_t version_arg,
                       phases_arg_t phases_arg,
                       _Unwind_Exception_Class uw_exception_class,
                       _Unwind_Exception *uw_exception,
                       _Unwind_Context *uw_context)
+#endif
 {
+#ifdef __ARM_EABI_UNWINDER__
+  phases_arg_t phases_arg; /* _Unwind_Action actions; */
+  _Unwind_Ptr ip;
+
+  _Unwind_Action uw_phases; /*s = (_Unwind_Action) phases_arg;*/
+  _GNAT_Exception * gnat_exception = (_GNAT_Exception *) uw_exception;
+
+  region_descriptor region;
+  action_descriptor action;
+
+  switch (state & _US_ACTION_MASK)
+    {
+    case _US_VIRTUAL_UNWIND_FRAME:
+      phases_arg = _UA_SEARCH_PHASE;
+      break;
+
+    case _US_UNWIND_FRAME_STARTING:
+      phases_arg = _UA_CLEANUP_PHASE;
+
+      if (!(state & _US_FORCE_UNWIND)
+	  && uw_exception->barrier_cache.sp == _Unwind_GetGR(uw_context, 13))
+	phases_arg |= _UA_HANDLER_FRAME;
+      break;
+
+    case _US_UNWIND_FRAME_RESUME:
+      CONTINUE_UNWINDING;
+      /*      return _URC_CONTINUE_UNWIND;*/
+      break;
+
+    default:
+      /* Is this correct? */
+      /* return _URC_FATAL_PHASE1_ERROR;*/
+      abort ();
+    }
+  phases_arg |= state & _US_FORCE_UNWIND;
+
+  uw_phases = phases_arg;
+
+  /* We don't know which runtime we're working with, so can't check this.
+   * However the ABI routines hide this from us, and we don't actually need
+   * to know.
+   */
+  /* foreign_exception = false; */
+
+  /* The dwarf unwinder assumes the context structure holds things like the
+   * function and LSDA pointers.  The ARM implementation caches these in
+   * the exception header (UCB).  To avoid rewriting everything we make the
+   * virtual IP register point at the UCB.
+   */
+  ip = (_Unwind_Ptr) uw_exception;
+
+  _Unwind_SetGR(uw_context, 12, ip);
+#else
   /* Fetch the version and phases args with their nominal ABI types for later
      use. This is a noop everywhere except on ia64-vms when called from the
      Condition Handling Facility.  */
@@ -1104,6 +1193,7 @@
 
       return _URC_FATAL_PHASE1_ERROR;
     }
+#endif
 
   db_indent (DB_INDENT_RESET);
   db_phases (uw_phases);
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/s-excunw-gcc.ads gcc-4.6.1/gcc/ada/s-excunw-gcc.ads
--- gcc-4.6.1.orig/gcc/ada/s-excunw-gcc.ads	1970-01-01 01:00:00.000000000 +0100
+++ gcc-4.6.1/gcc/ada/s-excunw-gcc.ads	2011-10-07 12:40:40.000000000 +0100
@@ -0,0 +1,116 @@
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT COMPILER COMPONENTS                         --
+--                                                                          --
+--              S Y S T E M . E X C E P T I O N _ U N W I N D               --
+--                                                                          --
+--                                 S p e c                                  --
+--                                                                          --
+--          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  This version of the EH data structures is used for normal GCC EH
+
+package System.Exception_Unwind is
+   pragma Warnings (Off);
+   pragma Preelaborate_05;
+   pragma Warnings (On);
+
+   ------------------------------------------------
+   -- Entities to interface with the GCC runtime --
+   ------------------------------------------------
+
+   --  These come from "C++ ABI for Itanium: Exception handling", which is
+   --  the reference for GCC. They are used only when we are relying on
+   --  back-end tables for exception propagation, which in turn is currently
+   --  only the case for Zero_Cost_Exceptions in GNAT5.
+
+   --  Return codes from the GCC runtime functions used to propagate
+   --  an exception.
+
+   type Unwind_Reason_Code is
+     (URC_NO_REASON,
+      URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_PHASE2_ERROR,
+      URC_PHASE1_ERROR,
+      URC_NORMAL_STOP,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND);
+
+   pragma Unreferenced
+     (URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_PHASE2_ERROR,
+      URC_PHASE1_ERROR,
+      URC_NORMAL_STOP,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND);
+
+   pragma Convention (C, Unwind_Reason_Code);
+
+   --  Phase identifiers
+
+   type Unwind_Action is
+     (UA_SEARCH_PHASE,
+      UA_CLEANUP_PHASE,
+      UA_HANDLER_FRAME,
+      UA_FORCE_UNWIND);
+
+   for Unwind_Action use
+      (UA_SEARCH_PHASE  => 1,
+       UA_CLEANUP_PHASE => 2,
+       UA_HANDLER_FRAME => 4,
+       UA_FORCE_UNWIND  => 8);
+
+   pragma Convention (C, Unwind_Action);
+
+   --  Mandatory common header for any exception object handled by the
+   --  GCC unwinding runtime.
+
+   type Exception_Class is mod 2 ** 64;
+
+   GNAT_Exception_Class : constant Exception_Class := 16#474e552d41646100#;
+   --  "GNU-Ada\0"
+
+   type Unwind_Word is mod 2 ** System.Word_Size;
+   for Unwind_Word'Size use System.Word_Size;
+   --  Map the corresponding C type used in Unwind_Exception below
+
+   type Unwind_Exception is record
+      Class    : Exception_Class := GNAT_Exception_Class;
+      Cleanup  : System.Address  := System.Null_Address;
+      Private1 : Unwind_Word;
+      Private2 : Unwind_Word;
+   end record;
+   --  Map the GCC struct used for exception handling
+
+   for Unwind_Exception'Alignment use Standard'Maximum_Alignment;
+   --  The C++ ABI mandates the common exception header to be at least
+   --  doubleword aligned, and the libGCC implementation actually makes it
+   --  maximally aligned (see unwind.h). See additional comments on the
+   --  alignment below.
+
+end System.Exception_Unwind;
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/s-excunw-gcc-arm.ads gcc-4.6.1/gcc/ada/s-excunw-gcc-arm.ads
--- gcc-4.6.1.orig/gcc/ada/s-excunw-gcc-arm.ads	1970-01-01 01:00:00.000000000 +0100
+++ gcc-4.6.1/gcc/ada/s-excunw-gcc-arm.ads	2011-10-09 02:00:52.000000000 +0100
@@ -0,0 +1,170 @@
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT COMPILER COMPONENTS                         --
+--                                                                          --
+--              S Y S T E M . E X C E P T I O N _ U N W I N D               --
+--                                                                          --
+--                                 S p e c                                  --
+--                                                                          --
+--          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  This version of the EH data structures is used for ARM EABI GCC EH
+
+package System.Exception_Unwind is
+   pragma Warnings (Off);
+   pragma Preelaborate_05;
+   pragma Warnings (On);
+
+   ------------------------------------------------
+   -- Entities to interface with the GCC runtime --
+   ------------------------------------------------
+
+   --  These come from "C++ ABI for Itanium: Exception handling", which is
+   --  the reference for GCC. They are used only when we are relying on
+   --  back-end tables for exception propagation, which in turn is currently
+   --  only the case for Zero_Cost_Exceptions in GNAT5.
+
+   --  Return codes from the GCC runtime functions used to propagate
+   --  an exception.
+
+   type Unwind_Reason_Code is
+     (URC_OK,
+      URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND,
+      URC_FAILURE);
+
+   pragma Unreferenced
+     (URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND,
+      URC_FAILURE);
+
+   pragma Convention (C, Unwind_Reason_Code);
+
+   --  Phase identifiers
+
+   type Unwind_State is
+     (US_VIRTUAL_UNWIND_FRAME,
+      US_UNWIND_FRAME_STARTING,
+      US_UNWIND_FRAME_RESUME,
+      US_ACTION_MASK,
+      US_FORCE_UNWIND,
+      US_END_OF_STACK);
+
+   for Unwind_State use
+     (US_VIRTUAL_UNWIND_FRAME  => 0,
+      US_UNWIND_FRAME_STARTING => 1,
+      US_UNWIND_FRAME_RESUME   => 2,
+      US_ACTION_MASK           => 3,
+      US_FORCE_UNWIND          => 8,
+      US_END_OF_STACK          => 16);
+
+   pragma Convention (C, Unwind_State);
+
+   subtype Unwind_Action is Unwind_State;
+
+   --  UA_SEARCH_PHASE renames Unwind_State.US_UNWIND_FRAME_STARTING;
+   --  UA_CLEANUP_PHASE renames Unwind_State.US_UNWIND_FRAME_RESUME;
+   --  UA_HANDLER_FRAME renames Unwind_State.US_; -- 4!??
+   --  UA_FORCE_UNWIND renames Unwind_State.US_FORCE_UNWIND;
+   --  UA_END_OF_STACK renames Unwind_State.US_END_OF_STACK;
+
+   URC_NO_REASON : Unwind_Reason_Code renames URC_OK;
+
+   --  Mandatory common header for any exception object handled by the
+   --  GCC unwinding runtime.
+
+   type Exception_Class is mod 2 ** 64;
+
+   GNAT_Exception_Class : constant Exception_Class := 16#474e552d41646100#;
+   --  "GNU-Ada\0"
+
+   type Unwind_Word is mod 2 ** System.Word_Size;
+   for Unwind_Word'Size use System.Word_Size;
+   --  Map the corresponding C type used in Unwind_Exception below
+
+   type Unwinder_Caches is record
+      Reserved1 : Unwind_Word;
+      Reserved2 : Unwind_Word;
+      Reserved3 : Unwind_Word;
+      Reserved4 : Unwind_Word;
+   end record;
+
+   pragma Convention (C, Unwinder_Caches);
+
+   type Unwind_Array is array (Integer range <>) of Unwind_Word;
+
+   pragma Convention (C, Unwind_Array);
+
+   type Barrier_Caches is record
+      SP          : Unwind_Word;
+      Bit_Pattern : Unwind_Array (1 .. 5);
+   end record;
+
+   pragma Convention (C, Barrier_Caches);
+
+   type Unwind_EHT_Header_Ptr is access Unwind_Word;
+
+   pragma Convention (C, Unwind_EHT_Header_Ptr);
+
+   type PR_Caches is record
+      Function_Start : Unwind_Word;
+      EHTP           : Unwind_EHT_Header_Ptr;
+      Additional1    : Unwind_Word;
+      Reserved1      : Unwind_Word;
+   end record;
+
+   pragma Convention (C, PR_Caches);
+
+   type Unwind_Control_Block is record
+      Class          : Exception_Class := GNAT_Exception_Class;
+      Cleanup        : System.Address  := System.Null_Address;
+      Unwinder_Cache : Unwinder_Caches;
+      Barrier_Cache  : Barrier_Caches;
+      Cleanup_Cache  : Unwind_Array (1 .. 4);
+      PR_Cache       : PR_Caches;
+
+      --  The following are for compatability with the usual GNAT EH mechanism.
+      Private1 : Unwind_Word;
+      Private2 : Unwind_Word;
+   end record;
+
+   pragma Convention (C, Unwind_Control_Block);
+   --  Map the GCC struct used for exception handling.
+   --  Found in gcc/config/arm/unwind-arm.h
+
+   for Unwind_Control_Block'Alignment use Standard'Maximum_Alignment;
+   --  The C++ ABI mandates the common exception header to be at least
+   --  doubleword aligned, and the libGCC implementation actually makes it
+   --  maximally aligned (see unwind.h). See additional comments on the
+   --  alignment below.
+
+   subtype Unwind_Exception is Unwind_Control_Block;
+
+end System.Exception_Unwind;
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/system-linux-armeb.ads gcc-4.6.1/gcc/ada/system-linux-armeb.ads
--- gcc-4.6.1.orig/gcc/ada/system-linux-armeb.ads	2010-01-22 11:55:45.000000000 +0000
+++ gcc-4.6.1/gcc/ada/system-linux-armeb.ads	2011-10-08 22:30:03.000000000 +0100
@@ -147,7 +147,7 @@
    Always_Compatible_Rep     : constant Boolean := False;
    Suppress_Standard_Library : constant Boolean := False;
    Use_Ada_Main_Program_Name : constant Boolean := False;
-   ZCX_By_Default            : constant Boolean := False;
-   GCC_ZCX_Support           : constant Boolean := False;
+   ZCX_By_Default            : constant Boolean := True;
+   GCC_ZCX_Support           : constant Boolean := True;
 
 end System;
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/system-linux-armel.ads gcc-4.6.1/gcc/ada/system-linux-armel.ads
--- gcc-4.6.1.orig/gcc/ada/system-linux-armel.ads	2010-01-22 11:55:45.000000000 +0000
+++ gcc-4.6.1/gcc/ada/system-linux-armel.ads	2011-10-08 22:29:43.000000000 +0100
@@ -147,7 +147,7 @@
    Always_Compatible_Rep     : constant Boolean := False;
    Suppress_Standard_Library : constant Boolean := False;
    Use_Ada_Main_Program_Name : constant Boolean := False;
-   ZCX_By_Default            : constant Boolean := False;
-   GCC_ZCX_Support           : constant Boolean := False;
+   ZCX_By_Default            : constant Boolean := True;
+   GCC_ZCX_Support           : constant Boolean := True;
 
 end System;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM EABI ZCX Ada (4.6.1) almost working
  2011-10-10  5:08 ` ARM EABI ZCX Ada (4.6.1) almost working Luke A. Guest
@ 2011-10-10  8:45   ` Luke A. Guest
  2011-10-12  7:39     ` Eric Botcazou
  2011-10-12  8:12     ` Eric Botcazou
  0 siblings, 2 replies; 8+ messages in thread
From: Luke A. Guest @ 2011-10-10  8:45 UTC (permalink / raw)
  To: GCC ML

On Sun, 2011-10-09 at 20:38 +0100, Luke A. Guest wrote:
> Anyway, I changed the code to throw an exception in a nested subprogram,
> this was also caught by the outer subprogram. I then added a raise;
> statement as a handler to see if it would reraise and then exit the
> program, sadly, I get an infinite loop in the search phase (export
> EH_DEBUG=1 shows this).

On further thinking about this, I have a feeling this may have something
to do with the Private1 field of the unwind_exception, but I'm not too
sure how yet.

Luke.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM EABI ZCX Ada (4.6.1) almost working
  2011-10-10  8:45   ` Luke A. Guest
@ 2011-10-12  7:39     ` Eric Botcazou
  2011-10-12  8:12     ` Eric Botcazou
  1 sibling, 0 replies; 8+ messages in thread
From: Eric Botcazou @ 2011-10-12  7:39 UTC (permalink / raw)
  To: Luke A. Guest; +Cc: gcc

> On further thinking about this, I have a feeling this may have something
> to do with the Private1 field of the unwind_exception, but I'm not too
> sure how yet.

For sure, adding a couple of fields on the Ada side that don't exist on the C 
side is highly suspicious.  Better get rid of them in any case I'd think.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM EABI ZCX Ada (4.6.1) almost working
  2011-10-10  8:45   ` Luke A. Guest
  2011-10-12  7:39     ` Eric Botcazou
@ 2011-10-12  8:12     ` Eric Botcazou
  2011-10-12  8:17       ` Luke A. Guest
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Botcazou @ 2011-10-12  8:12 UTC (permalink / raw)
  To: gcc

> On further thinking about this, I have a feeling this may have something
> to do with the Private1 field of the unwind_exception, but I'm not too
> sure how yet.

For sure, adding a couple of fields on the Ada side that don't exist on the C 
side is highly suspicious.  Better get rid of them in any case I'd think.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM EABI ZCX Ada (4.6.1) almost working
  2011-10-12  8:12     ` Eric Botcazou
@ 2011-10-12  8:17       ` Luke A. Guest
  2011-10-12  9:34         ` Eric Botcazou
  0 siblings, 1 reply; 8+ messages in thread
From: Luke A. Guest @ 2011-10-12  8:17 UTC (permalink / raw)
  To: GCC ML

On Wed, 2011-10-12 at 09:09 +0200, Eric Botcazou wrote:
> > On further thinking about this, I have a feeling this may have something
> > to do with the Private1 field of the unwind_exception, but I'm not too
> > sure how yet.
> 
> For sure, adding a couple of fields on the Ada side that don't exist on the C 
> side is highly suspicious.  Better get rid of them in any case I'd think.

Aye, then the Ada side doesn't build. Can you see what it is I'm
missing? I can't say I truly understand this code, especially that in
raise-gcc.c. I do understand there are 2 phases, but I have to say the
code as the documentation (even where there is docs) is still very
cryptic.

I'm beginning to think the whole of a-exexpr-gcc needs to be extracted
into 2 distinct files, a-exexpr-gcc (normal GCC EH - as it is) and
a-exexpr-gcc-arm (ARM EABI EH).

Thanks,
Luke.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM EABI ZCX Ada (4.6.1) almost working
  2011-10-12  8:17       ` Luke A. Guest
@ 2011-10-12  9:34         ` Eric Botcazou
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Botcazou @ 2011-10-12  9:34 UTC (permalink / raw)
  To: Luke A. Guest; +Cc: gcc

> Aye, then the Ada side doesn't build. Can you see what it is I'm
> missing?

You need to further adjust the Ada code (a-exexpr-gcc.adb), which is written 
for DWARF EH.  In particular, you need to rewrite Propagate_Exception to build 
a proper exception for ARM EH.

> I'm beginning to think the whole of a-exexpr-gcc needs to be extracted
> into 2 distinct files, a-exexpr-gcc (normal GCC EH - as it is) and
> a-exexpr-gcc-arm (ARM EABI EH).

Probably some parts of it, yes.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Help required re ARM EABI ZCX Ada (4.6.1)
@ 2011-10-09 20:49 Luke A. Guest
  0 siblings, 0 replies; 8+ messages in thread
From: Luke A. Guest @ 2011-10-09 20:49 UTC (permalink / raw)
  To: GCC ML

[-- Attachment #1: Type: text/plain, Size: 2584 bytes --]

Hi,

I got back to this yesterday and have tried to port over the ARM code
from the C++/Java exception files. I have managed to build a native
compiler (using make bootstrap) and run the test suite (logs not
included due to their size), but the general summary is as follows:

                === gcc Summary ===

# of expected passes            78536
# of unexpected failures        40
# of unexpected successes       38
# of expected failures          222
# of unsupported tests          1145

                === gnat Summary ===

# of expected passes            871
# of expected failures          10
# of unsupported tests          2

                === acats Summary ===
# of expected passes            2321
# of unexpected failures        0

My host machine is:

Linux rogue 2.6.32-5-amd64 #1 SMP Tue Jun 14 09:42:28 UTC 2011 x86_64
GNU/Linux


I have then built for arm-linux-gnueabi and have an installed toolchain
(no compile errors) and a running QEMU which can be logged into
automatically by me via SSH and which has a TAP set up, I run this with:

qemu-system-arm -k en-gb -m 256 -M versatilepb -kernel
~/opt/arm/vmlinuz-2.6.32-5-versatile -initrd
~/opt/arm/initrd.img-2.6.32-5-versatile -hda ~/opt/arm/arm-debian.img
-append "root=/dev/sda1" -net nic -net
tap,ifname=tap0,script=no,downscript=no

I have set up 2 env vars for DejaGNU:

DEJAGNU=/home/laguest/src/others/gcc-zxc-arm/dejagnu/site.exp
DEJAGNU_TIMEOUT=-1

I have the set up a board called angel.exp and these can be seen in the
attachments.

When I initially had the results, I had DEJAGNU_TIMEOUT=5400, I didn't
realise there was a separate timeout for the compiler. Due to the speed
I've not rerun these tests.

There is a problem with the Ada test suite for cross targets, on
starting I get the following error:

make[1]: Entering directory
`/home/laguest/src/others/gcc-zxc-arm/arm-build-gcc-4.6.1/gcc'
gnattools missing, exiting.
make[1]: *** [check-acats] Error 1

It then continues with the gnat tests, but fails to run the acats tests.
That message comes from the run_acats script.

I have compiled a test program, exc.adb which does not catch the
exceptions, so I know this ARM code does not work properly yet. The
error on the arm side is:

raised EXC.T : exc.adb:6

I'm obviously missing something here, can someone knowledgeable look
over the patch and see what it is?

Can anyone confirm that the Ada test suite should work for cross
targets?

If anyone has a target this can be tested for and has a working test
suite, can they apply the patch and see what results they get?

Thanks,
Luke.



[-- Attachment #2: site.exp --]
[-- Type: text/plain, Size: 163 bytes --]

append boards_dir "/home/laguest/src/others/gcc-zxc-arm/dejagnu/boards"
case "$target_triplet" in {
      { "arm*-linux-gnueabi" } { set target_list { angel } }
}

[-- Attachment #3: angel.exp --]
[-- Type: text/plain, Size: 201 bytes --]

load_generic_config "unix"
set_board_info hostname "192.168.0.5"
set_board_info username laguest
set_board_info rsh_prog /usr/bin/ssh
set_board_info rcp_prog /usr/bin/scp
set_board_info gcc,timeout -1

[-- Attachment #4: arm-linux-gnat.log.bz2 --]
[-- Type: application/x-bzip, Size: 62067 bytes --]

[-- Attachment #5: arm-linux-gnat.sum.bz2 --]
[-- Type: application/x-bzip, Size: 4642 bytes --]

[-- Attachment #6: arm-linux-zcx.diff --]
[-- Type: text/x-patch, Size: 23546 bytes --]

diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/a-exexpr-gcc.adb gcc-4.6.1/gcc/ada/a-exexpr-gcc.adb
--- gcc-4.6.1.orig/gcc/ada/a-exexpr-gcc.adb	2009-04-09 16:00:19.000000000 +0100
+++ gcc-4.6.1/gcc/ada/a-exexpr-gcc.adb	2011-10-07 02:30:41.000000000 +0100
@@ -35,87 +35,11 @@
 with Ada.Unchecked_Deallocation;
 
 with System.Storage_Elements;  use System.Storage_Elements;
+with System.Exception_Unwind;  use System.Exception_Unwind;
 
 separate (Ada.Exceptions)
 package body Exception_Propagation is
 
-   ------------------------------------------------
-   -- Entities to interface with the GCC runtime --
-   ------------------------------------------------
-
-   --  These come from "C++ ABI for Itanium: Exception handling", which is
-   --  the reference for GCC. They are used only when we are relying on
-   --  back-end tables for exception propagation, which in turn is currently
-   --  only the case for Zero_Cost_Exceptions in GNAT5.
-
-   --  Return codes from the GCC runtime functions used to propagate
-   --  an exception.
-
-   type Unwind_Reason_Code is
-     (URC_NO_REASON,
-      URC_FOREIGN_EXCEPTION_CAUGHT,
-      URC_PHASE2_ERROR,
-      URC_PHASE1_ERROR,
-      URC_NORMAL_STOP,
-      URC_END_OF_STACK,
-      URC_HANDLER_FOUND,
-      URC_INSTALL_CONTEXT,
-      URC_CONTINUE_UNWIND);
-
-   pragma Unreferenced
-     (URC_FOREIGN_EXCEPTION_CAUGHT,
-      URC_PHASE2_ERROR,
-      URC_PHASE1_ERROR,
-      URC_NORMAL_STOP,
-      URC_END_OF_STACK,
-      URC_HANDLER_FOUND,
-      URC_INSTALL_CONTEXT,
-      URC_CONTINUE_UNWIND);
-
-   pragma Convention (C, Unwind_Reason_Code);
-
-   --  Phase identifiers
-
-   type Unwind_Action is
-     (UA_SEARCH_PHASE,
-      UA_CLEANUP_PHASE,
-      UA_HANDLER_FRAME,
-      UA_FORCE_UNWIND);
-
-   for Unwind_Action use
-      (UA_SEARCH_PHASE  => 1,
-       UA_CLEANUP_PHASE => 2,
-       UA_HANDLER_FRAME => 4,
-       UA_FORCE_UNWIND  => 8);
-
-   pragma Convention (C, Unwind_Action);
-
-   --  Mandatory common header for any exception object handled by the
-   --  GCC unwinding runtime.
-
-   type Exception_Class is mod 2 ** 64;
-
-   GNAT_Exception_Class : constant Exception_Class := 16#474e552d41646100#;
-   --  "GNU-Ada\0"
-
-   type Unwind_Word is mod 2 ** System.Word_Size;
-   for Unwind_Word'Size use System.Word_Size;
-   --  Map the corresponding C type used in Unwind_Exception below
-
-   type Unwind_Exception is record
-      Class    : Exception_Class := GNAT_Exception_Class;
-      Cleanup  : System.Address  := System.Null_Address;
-      Private1 : Unwind_Word;
-      Private2 : Unwind_Word;
-   end record;
-   --  Map the GCC struct used for exception handling
-
-   for Unwind_Exception'Alignment use Standard'Maximum_Alignment;
-   --  The C++ ABI mandates the common exception header to be at least
-   --  doubleword aligned, and the libGCC implementation actually makes it
-   --  maximally aligned (see unwind.h). See additional comments on the
-   --  alignment below.
-
    --------------------------------------------------------------
    -- GNAT Specific Entities To Deal With The GCC EH Circuitry --
    --------------------------------------------------------------
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/ChangeLog gcc-4.6.1/gcc/ada/ChangeLog
--- gcc-4.6.1.orig/gcc/ada/ChangeLog	2011-06-27 11:03:04.000000000 +0100
+++ gcc-4.6.1/gcc/ada/ChangeLog	2011-10-09 11:51:05.000000000 +0100
@@ -1,3 +1,18 @@
+2011-10-09 Luke A. Guest <laguest@archeia.com>
+
+	* Initial port of ZCX code to ARM Linux.
+	* s-excunw-gcc.ads: New file, extracts the normal GCC Unwind_Exception
+	into it's own package.
+	* s-excunw-gcc-arm.ads: New file, extracts the ARM EABI GCC
+	Unwind_Exception into it's own package.
+	* a-exexpr-gcc.adb: Unwind_Exception and other enumerations removed.
+	* gcc-interface/Makefile.in: Handle new files to build for native and
+	ARM EABI exception blocks.
+	* Makefile.rtl: Added a line to build above unwind exception package.
+	* raise-gcc.c: Added support for ARM EABI UNWINDER.
+	* system-linux-armeb.ads: Changed to support ZCX instead of SJLJ.
+	* system-linux-armel.ads: Changed to support ZCX instead of SJLJ.
+
 2011-06-27  Release Manager
 
 	* GCC 4.6.1 released.
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/gcc-interface/Makefile.in gcc-4.6.1/gcc/ada/gcc-interface/Makefile.in
--- gcc-4.6.1.orig/gcc/ada/gcc-interface/Makefile.in	2011-02-08 22:55:57.000000000 +0000
+++ gcc-4.6.1/gcc/ada/gcc-interface/Makefile.in	2011-10-09 01:05:39.000000000 +0100
@@ -360,6 +360,10 @@
 
 EH_MECHANISM=
 
+# When using the GCC exception handling mechanism, we need to specify which
+# Unwind_Exception record to use.
+EH_UNWIND_BLOCK=
+
 # Default shared object option. Note that we rely on the fact that the "soname"
 # option will always be present and last in this flag, so that we can have
 # $(SO_OPTS)libgnat-x.xx
@@ -1869,7 +1873,8 @@
     indepsw.adb<indepsw-gnu.adb
 
   EXTRA_GNATRTL_TASKING_OBJS=s-linux.o
-  EH_MECHANISM=
+  EH_MECHANISM=-gcc
+  EH_UNWIND_BLOCK=-arm
   THREADSLIB = -lpthread
   GNATLIB_SHARED = gnatlib-shared-dual
   GMEM_LIB = gmemlib
@@ -2194,6 +2199,11 @@
   EXTRA_LIBGNAT_OBJS+=raise$(EH_MECHANISM).o
 endif
 
+# This only gets included if we're using ZCX.
+ifeq ($(EH_MECHANISM),-gcc)
+  LIBGNAT_TARGET_PAIRS += s-excunw.ads<s-excunw$(EH_MECHANISM)$(EH_UNWIND_BLOCK).ads
+endif
+
 # Use the Ada 2005 version of Ada.Exceptions by default, unless specified
 # explicitly already. The base files (a-except.ad?) are used only for building
 # the compiler and other basic tools.
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/Makefile.rtl gcc-4.6.1/gcc/ada/Makefile.rtl
--- gcc-4.6.1.orig/gcc/ada/Makefile.rtl	2010-10-26 11:42:02.000000000 +0100
+++ gcc-4.6.1/gcc/ada/Makefile.rtl	2011-10-07 12:10:47.000000000 +0100
@@ -468,6 +468,7 @@
   s-dsaser$(objext) \
   s-except$(objext) \
   s-exctab$(objext) \
+  s-excunw$(objext) \
   s-exnint$(objext) \
   s-exnllf$(objext) \
   s-exnlli$(objext) \
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/raise-gcc.c gcc-4.6.1/gcc/ada/raise-gcc.c
--- gcc-4.6.1.orig/gcc/ada/raise-gcc.c	2010-10-26 11:52:27.000000000 +0100
+++ gcc-4.6.1/gcc/ada/raise-gcc.c	2011-10-09 01:40:06.000000000 +0100
@@ -534,6 +534,24 @@
 /* Retrieve the ttype entry associated with FILTER in the REGION's
    ttype table.  */
 
+#ifdef __ARM_EABI_UNWINDER__
+
+/* Based on code inside eh_personality.cc (C++) and exception.cc (Java) */
+
+static const _Unwind_Ptr
+get_ttype_entry_for (region_descriptor *region, long filter)
+{
+  _Unwind_Ptr ttype_entry;
+
+  ttype_entry = (_Unwind_Ptr) (region->ttype_table - (filter * 4));
+  
+  ttype_entry = _Unwind_decode_target2(ttype_entry);
+
+  return ttype_entry;
+}
+
+#else
+
 static const _Unwind_Ptr
 get_ttype_entry_for (region_descriptor *region, long filter)
 {
@@ -547,6 +565,8 @@
   return ttype_entry;
 }
 
+#endif /* __ARM_EABI_UNWINDER__ */
+
 /* Fill out the REGION descriptor for the provided UW_CONTEXT.  */
 
 static void
@@ -1064,13 +1084,80 @@
 typedef _Unwind_Action phases_arg_t;
 #endif
 
+#ifdef __ARM_EABI_UNWINDER__
+
+#define CONTINUE_UNWINDING \
+  do								\
+    {								\
+      if (__gnu_unwind_frame(uw_exception, uw_context) != _URC_OK)	\
+	return _URC_FAILURE;					\
+      return _URC_CONTINUE_UNWIND;				\
+    }								\
+  while (0)
+
+PERSONALITY_FUNCTION (_Unwind_State state,
+		      struct _Unwind_Exception* uw_exception,
+		      struct _Unwind_Context* uw_context)
+#else
 _Unwind_Reason_Code
 PERSONALITY_FUNCTION (version_arg_t version_arg,
                       phases_arg_t phases_arg,
                       _Unwind_Exception_Class uw_exception_class,
                       _Unwind_Exception *uw_exception,
                       _Unwind_Context *uw_context)
+#endif
 {
+#ifdef __ARM_EABI_UNWINDER__
+  phases_arg_t phases_arg; /* _Unwind_Action actions; */
+  _Unwind_Ptr ip;
+
+  _Unwind_Action uw_phases = (_Unwind_Action) phases_arg;
+  _GNAT_Exception * gnat_exception = (_GNAT_Exception *) uw_exception;
+
+  region_descriptor region;
+  action_descriptor action;
+
+  switch (state & _US_ACTION_MASK)
+    {
+    case _US_VIRTUAL_UNWIND_FRAME:
+      phases_arg = _UA_SEARCH_PHASE;
+      break;
+
+    case _US_UNWIND_FRAME_STARTING:
+      phases_arg = _UA_CLEANUP_PHASE;
+
+      if (!(state & _US_FORCE_UNWIND)
+	  && uw_exception->barrier_cache.sp == _Unwind_GetGR(uw_context, 13))
+	phases_arg |= _UA_HANDLER_FRAME;
+      break;
+
+    case _US_UNWIND_FRAME_RESUME:
+      CONTINUE_UNWINDING;
+      /*      return _URC_CONTINUE_UNWIND;*/
+      break;
+
+    default:
+      /* Is this correct? */
+      /* return _URC_FATAL_PHASE1_ERROR;*/
+      abort ();
+    }
+  phases_arg |= state & _US_FORCE_UNWIND;
+
+  /* We don't know which runtime we're working with, so can't check this.
+   * However the ABI routines hide this from us, and we don't actually need
+   * to know.
+   */
+  /* foreign_exception = false; */
+
+  /* The dwarf unwinder assumes the context structure holds things like the
+   * function and LSDA pointers.  The ARM implementation caches these in
+   * the exception header (UCB).  To avoid rewriting everything we make the
+   * virtual IP register point at the UCB.
+   */
+  ip = (_Unwind_Ptr) uw_exception;
+
+  _Unwind_SetGR(uw_context, 12, ip);
+#else
   /* Fetch the version and phases args with their nominal ABI types for later
      use. This is a noop everywhere except on ia64-vms when called from the
      Condition Handling Facility.  */
@@ -1104,6 +1191,7 @@
 
       return _URC_FATAL_PHASE1_ERROR;
     }
+#endif
 
   db_indent (DB_INDENT_RESET);
   db_phases (uw_phases);
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/s-excunw-gcc.ads gcc-4.6.1/gcc/ada/s-excunw-gcc.ads
--- gcc-4.6.1.orig/gcc/ada/s-excunw-gcc.ads	1970-01-01 01:00:00.000000000 +0100
+++ gcc-4.6.1/gcc/ada/s-excunw-gcc.ads	2011-10-07 12:40:40.000000000 +0100
@@ -0,0 +1,116 @@
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT COMPILER COMPONENTS                         --
+--                                                                          --
+--              S Y S T E M . E X C E P T I O N _ U N W I N D               --
+--                                                                          --
+--                                 S p e c                                  --
+--                                                                          --
+--          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  This version of the EH data structures is used for normal GCC EH
+
+package System.Exception_Unwind is
+   pragma Warnings (Off);
+   pragma Preelaborate_05;
+   pragma Warnings (On);
+
+   ------------------------------------------------
+   -- Entities to interface with the GCC runtime --
+   ------------------------------------------------
+
+   --  These come from "C++ ABI for Itanium: Exception handling", which is
+   --  the reference for GCC. They are used only when we are relying on
+   --  back-end tables for exception propagation, which in turn is currently
+   --  only the case for Zero_Cost_Exceptions in GNAT5.
+
+   --  Return codes from the GCC runtime functions used to propagate
+   --  an exception.
+
+   type Unwind_Reason_Code is
+     (URC_NO_REASON,
+      URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_PHASE2_ERROR,
+      URC_PHASE1_ERROR,
+      URC_NORMAL_STOP,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND);
+
+   pragma Unreferenced
+     (URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_PHASE2_ERROR,
+      URC_PHASE1_ERROR,
+      URC_NORMAL_STOP,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND);
+
+   pragma Convention (C, Unwind_Reason_Code);
+
+   --  Phase identifiers
+
+   type Unwind_Action is
+     (UA_SEARCH_PHASE,
+      UA_CLEANUP_PHASE,
+      UA_HANDLER_FRAME,
+      UA_FORCE_UNWIND);
+
+   for Unwind_Action use
+      (UA_SEARCH_PHASE  => 1,
+       UA_CLEANUP_PHASE => 2,
+       UA_HANDLER_FRAME => 4,
+       UA_FORCE_UNWIND  => 8);
+
+   pragma Convention (C, Unwind_Action);
+
+   --  Mandatory common header for any exception object handled by the
+   --  GCC unwinding runtime.
+
+   type Exception_Class is mod 2 ** 64;
+
+   GNAT_Exception_Class : constant Exception_Class := 16#474e552d41646100#;
+   --  "GNU-Ada\0"
+
+   type Unwind_Word is mod 2 ** System.Word_Size;
+   for Unwind_Word'Size use System.Word_Size;
+   --  Map the corresponding C type used in Unwind_Exception below
+
+   type Unwind_Exception is record
+      Class    : Exception_Class := GNAT_Exception_Class;
+      Cleanup  : System.Address  := System.Null_Address;
+      Private1 : Unwind_Word;
+      Private2 : Unwind_Word;
+   end record;
+   --  Map the GCC struct used for exception handling
+
+   for Unwind_Exception'Alignment use Standard'Maximum_Alignment;
+   --  The C++ ABI mandates the common exception header to be at least
+   --  doubleword aligned, and the libGCC implementation actually makes it
+   --  maximally aligned (see unwind.h). See additional comments on the
+   --  alignment below.
+
+end System.Exception_Unwind;
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/s-excunw-gcc-arm.ads gcc-4.6.1/gcc/ada/s-excunw-gcc-arm.ads
--- gcc-4.6.1.orig/gcc/ada/s-excunw-gcc-arm.ads	1970-01-01 01:00:00.000000000 +0100
+++ gcc-4.6.1/gcc/ada/s-excunw-gcc-arm.ads	2011-10-09 02:00:52.000000000 +0100
@@ -0,0 +1,170 @@
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT COMPILER COMPONENTS                         --
+--                                                                          --
+--              S Y S T E M . E X C E P T I O N _ U N W I N D               --
+--                                                                          --
+--                                 S p e c                                  --
+--                                                                          --
+--          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  This version of the EH data structures is used for ARM EABI GCC EH
+
+package System.Exception_Unwind is
+   pragma Warnings (Off);
+   pragma Preelaborate_05;
+   pragma Warnings (On);
+
+   ------------------------------------------------
+   -- Entities to interface with the GCC runtime --
+   ------------------------------------------------
+
+   --  These come from "C++ ABI for Itanium: Exception handling", which is
+   --  the reference for GCC. They are used only when we are relying on
+   --  back-end tables for exception propagation, which in turn is currently
+   --  only the case for Zero_Cost_Exceptions in GNAT5.
+
+   --  Return codes from the GCC runtime functions used to propagate
+   --  an exception.
+
+   type Unwind_Reason_Code is
+     (URC_OK,
+      URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND,
+      URC_FAILURE);
+
+   pragma Unreferenced
+     (URC_FOREIGN_EXCEPTION_CAUGHT,
+      URC_END_OF_STACK,
+      URC_HANDLER_FOUND,
+      URC_INSTALL_CONTEXT,
+      URC_CONTINUE_UNWIND,
+      URC_FAILURE);
+
+   pragma Convention (C, Unwind_Reason_Code);
+
+   --  Phase identifiers
+
+   type Unwind_State is
+     (US_VIRTUAL_UNWIND_FRAME,
+      US_UNWIND_FRAME_STARTING,
+      US_UNWIND_FRAME_RESUME,
+      US_ACTION_MASK,
+      US_FORCE_UNWIND,
+      US_END_OF_STACK);
+
+   for Unwind_State use
+     (US_VIRTUAL_UNWIND_FRAME  => 0,
+      US_UNWIND_FRAME_STARTING => 1,
+      US_UNWIND_FRAME_RESUME   => 2,
+      US_ACTION_MASK           => 3,
+      US_FORCE_UNWIND          => 8,
+      US_END_OF_STACK          => 16);
+
+   pragma Convention (C, Unwind_State);
+
+   subtype Unwind_Action is Unwind_State;
+
+   --  UA_SEARCH_PHASE renames Unwind_State.US_UNWIND_FRAME_STARTING;
+   --  UA_CLEANUP_PHASE renames Unwind_State.US_UNWIND_FRAME_RESUME;
+   --  UA_HANDLER_FRAME renames Unwind_State.US_; -- 4!??
+   --  UA_FORCE_UNWIND renames Unwind_State.US_FORCE_UNWIND;
+   --  UA_END_OF_STACK renames Unwind_State.US_END_OF_STACK;
+
+   URC_NO_REASON : Unwind_Reason_Code renames URC_OK;
+
+   --  Mandatory common header for any exception object handled by the
+   --  GCC unwinding runtime.
+
+   type Exception_Class is mod 2 ** 64;
+
+   GNAT_Exception_Class : constant Exception_Class := 16#474e552d41646100#;
+   --  "GNU-Ada\0"
+
+   type Unwind_Word is mod 2 ** System.Word_Size;
+   for Unwind_Word'Size use System.Word_Size;
+   --  Map the corresponding C type used in Unwind_Exception below
+
+   type Unwinder_Caches is record
+      Reserved1 : Unwind_Word;
+      Reserved2 : Unwind_Word;
+      Reserved3 : Unwind_Word;
+      Reserved4 : Unwind_Word;
+   end record;
+
+   pragma Convention (C, Unwinder_Caches);
+
+   type Unwind_Array is array (Integer range <>) of Unwind_Word;
+
+   pragma Convention (C, Unwind_Array);
+
+   type Barrier_Caches is record
+      SP          : Unwind_Word;
+      Bit_Pattern : Unwind_Array (1 .. 5);
+   end record;
+
+   pragma Convention (C, Barrier_Caches);
+
+   type Unwind_EHT_Header_Ptr is access Unwind_Word;
+
+   pragma Convention (C, Unwind_EHT_Header_Ptr);
+
+   type PR_Caches is record
+      Function_Start : Unwind_Word;
+      EHTP           : Unwind_EHT_Header_Ptr;
+      Additional1    : Unwind_Word;
+      Reserved1      : Unwind_Word;
+   end record;
+
+   pragma Convention (C, PR_Caches);
+
+   type Unwind_Control_Block is record
+      Class          : Exception_Class := GNAT_Exception_Class;
+      Cleanup        : System.Address  := System.Null_Address;
+      Unwinder_Cache : Unwinder_Caches;
+      Barrier_Cache  : Barrier_Caches;
+      Cleanup_Cache  : Unwind_Array (1 .. 4);
+      PR_Cache       : PR_Caches;
+
+      --  The following are for compatability with the usual GNAT EH mechanism.
+      Private1 : Unwind_Word;
+      Private2 : Unwind_Word;
+   end record;
+
+   pragma Convention (C, Unwind_Control_Block);
+   --  Map the GCC struct used for exception handling.
+   --  Found in gcc/config/arm/unwind-arm.h
+
+   for Unwind_Control_Block'Alignment use Standard'Maximum_Alignment;
+   --  The C++ ABI mandates the common exception header to be at least
+   --  doubleword aligned, and the libGCC implementation actually makes it
+   --  maximally aligned (see unwind.h). See additional comments on the
+   --  alignment below.
+
+   subtype Unwind_Exception is Unwind_Control_Block;
+
+end System.Exception_Unwind;
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/system-linux-armeb.ads gcc-4.6.1/gcc/ada/system-linux-armeb.ads
--- gcc-4.6.1.orig/gcc/ada/system-linux-armeb.ads	2010-01-22 11:55:45.000000000 +0000
+++ gcc-4.6.1/gcc/ada/system-linux-armeb.ads	2011-10-08 22:30:03.000000000 +0100
@@ -147,7 +147,7 @@
    Always_Compatible_Rep     : constant Boolean := False;
    Suppress_Standard_Library : constant Boolean := False;
    Use_Ada_Main_Program_Name : constant Boolean := False;
-   ZCX_By_Default            : constant Boolean := False;
-   GCC_ZCX_Support           : constant Boolean := False;
+   ZCX_By_Default            : constant Boolean := True;
+   GCC_ZCX_Support           : constant Boolean := True;
 
 end System;
diff -x '*~' -uNr gcc-4.6.1.orig/gcc/ada/system-linux-armel.ads gcc-4.6.1/gcc/ada/system-linux-armel.ads
--- gcc-4.6.1.orig/gcc/ada/system-linux-armel.ads	2010-01-22 11:55:45.000000000 +0000
+++ gcc-4.6.1/gcc/ada/system-linux-armel.ads	2011-10-08 22:29:43.000000000 +0100
@@ -147,7 +147,7 @@
    Always_Compatible_Rep     : constant Boolean := False;
    Suppress_Standard_Library : constant Boolean := False;
    Use_Ada_Main_Program_Name : constant Boolean := False;
-   ZCX_By_Default            : constant Boolean := False;
-   GCC_ZCX_Support           : constant Boolean := False;
+   ZCX_By_Default            : constant Boolean := True;
+   GCC_ZCX_Support           : constant Boolean := True;
 
 end System;

[-- Attachment #7: exc.adb --]
[-- Type: text/x-adasrc, Size: 211 bytes --]

with Ada.Text_IO; use Ada.Text_IO;

procedure exc is
   T : exception;
begin
   raise T;
exception
   when Constraint_Error =>
      Put_Line("Constraint");
   when others =>
      Put_Line("others");
end exc;


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-10-12  7:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-09 19:43 Help required re ARM EABI ZCX Ada (4.6.1) Luke A. Guest
2011-10-10  5:08 ` ARM EABI ZCX Ada (4.6.1) almost working Luke A. Guest
2011-10-10  8:45   ` Luke A. Guest
2011-10-12  7:39     ` Eric Botcazou
2011-10-12  8:12     ` Eric Botcazou
2011-10-12  8:17       ` Luke A. Guest
2011-10-12  9:34         ` Eric Botcazou
2011-10-09 20:49 Help required re ARM EABI ZCX Ada (4.6.1) Luke A. Guest

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).