This is the mail archive of the cygwin-apps@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[GCC 3.2] dll/exe exceptions patch


I have modified the Adriano dos Santos Fernandes  patchset somewhat so that it
can be used with both cygwin and mingw, changing "mingw" to "w32" in symbol
names and taking out changes to the mingw runtime and put in gcc runtime.
Instead of calling __w32_initialize_shared_ptr from __main, it is called by a
constructor from crtend.o so it happens at same time as registration of
eh_frame. The w32-shared-ptr.c code ends up in a startup module I have called
crts.o. 

I have put into startup module, rather than a runtime library to ease testing
without having to change the target-specific runtime.  It also adds flexibility
by allowing this code (and the crtbegin/crtend modules) to be excluded in
future by using -fno-exceptions switch in specs. 

If the initialize_shared_ptr code is to stay integrated with the gcc build, we
could changes the global int variables used to find offsets
i.e.
+const int __w32_sharedptr_terminate = 1;
+const int __w32_sharedptr_unexpected = 2;
+const int __w32_sharedptr_unseen_objects = 3;
+const int __w32_sharedptr_seen_objects = 4;
+#define SHAREDPTR_COUNT     5

into  enum, defined in a gcc config header, to allow some optimization in
determining the offsets.    

But I do need some advise on all this, particulary since the use of
Find/AddAtom may not be necessary for cygwin (see below).

One other change I have made from Adriano's initial patch is to set default
terminate and uncaught_exception handlers to abort.  This isn't quite right:
the default uncaught_exception handler should be the current std::terminate
function, but that can be fixed later.

I am happy with tests on mingw, still testing on cygwin.  I believe with cygwin
that much of this could be simplified and the global data could just be put
into cygwin1.dll, but one thing at a time.

Please review attached diff. In addition to any technical improvements to code,
I also need feedback on the larger issue of whether to make this mingw-specific
or common to cygwin and mingw.


Danny



http://digital.yahoo.com.au - Yahoo! Digital How To
- Get the best out of your PC!
gcc/ChangeLog

2002-07-29  Danny Smith  <dannysmith@users.sourceforge.net>

	config.gcc (i[34567]86-*-mingw32*): Add crts.o as extra parts.
	(i[34567]86-*-cygwin*): Likewise.
	crtstuff.c (__do_frame_init): Call __w32_sharedptr_initialize.
	config/i386/t-cygming (crts.o): Add rule to compile from
	w32-shared-ptr.c.
	* config/i386/w32-shared-ptr.c (__w32_sharedptr_initialize):
	Initialize default terminate and uncaught_exception handlers
	to abort.

2002-07-29  Adriano dos Santos Fernandes  <adrianosf@uol.com.br>

	* unwind-dw2-fde.c (unseen_objects, seen_objects): Support for
	mingw32 catch exceptions across EXE/DLLs boundaries.
	* config/i386/w32-shared-ptr.c: New file. Initialize shared
	pointers.

libstdc++-v3/ChangeLog

2002-07-29  Adriano dos Santos Fernandes  <adrianosf@uol.com.br>

	* libsupc++/unwind-cxx.h (__terminate_handler,
	 __unexpected_handler):Support for w32 catch exceptions across
	 EXE/DLLs boundaries.
	* libsupc++/eh_terminate.cc (__terminate_handler,
	__unexpected_handler): Same.


Index: gcc/gcc/config.gcc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config.gcc,v
retrieving revision 1.167.2.20.2.5
diff -u -p -r1.167.2.20.2.5 config.gcc
--- gcc/gcc/config.gcc	6 Jul 2002 03:38:20 -0000	1.167.2.20.2.5
+++ gcc/gcc/config.gcc	28 Jul 2002 00:06:05 -0000
@@ -1534,7 +1534,7 @@ i[34567]86-*-pe | i[34567]86-*-cygwin*)
 	extra_objs=winnt.o
 	c_target_objs=cygwin2.o
 	cxx_target_objs=cygwin2.o
-	extra_parts="crtbegin.o crtend.o"
+	extra_parts="crtbegin.o crtend.o crts.o"
 	target_cpu_default=TARGET_CPU_DEFAULT_pentium
 	if test x$enable_threads = xyes; then
 		thread_file='posix'
@@ -1548,7 +1548,7 @@ i[34567]86-*-mingw32*)
 	xm_file=i386/xm-mingw32.h
 	tmake_file="i386/t-cygming i386/t-mingw32"
 	extra_objs=winnt.o
-	extra_parts="crtbegin.o crtend.o"
+	extra_parts="crtbegin.o crtend.o crts.o"
 	target_cpu_default=TARGET_CPU_DEFAULT_pentium
 	if test x$enable_threads = xyes; then
 		thread_file='win32'
Index: gcc/gcc/crtstuff.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/crtstuff.c,v
retrieving revision 1.54.4.1
diff -u -p -r1.54.4.1 crtstuff.c
--- gcc/gcc/crtstuff.c	30 May 2002 08:43:47 -0000	1.54.4.1
+++ gcc/gcc/crtstuff.c	28 Jul 2002 00:07:04 -0000
@@ -627,6 +627,7 @@ char __EH_FRAME_BEGIN__[]
      = { };
 
 static struct object obj;
+extern  void __w32_sharedptr_initialize(void);
 
 /* These will pull in references from libgcc.a(unwind-dw2-fde.o) */
 
@@ -636,6 +637,7 @@ void __do_frame_fini (void);
 void
 __do_frame_init (void)
 {
+  __w32_sharedptr_initialize();
   __register_frame_info (__EH_FRAME_BEGIN__, &obj);
 }
 
Index: gcc/gcc/unwind-dw2-fde.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/unwind-dw2-fde.c,v
retrieving revision 1.19
diff -u -p -r1.19 unwind-dw2-fde.c
--- gcc/gcc/unwind-dw2-fde.c	21 Jan 2002 13:08:31 -0000	1.19
+++ gcc/gcc/unwind-dw2-fde.c	28 Jul 2002 00:07:06 -0000
@@ -43,8 +43,16 @@ Software Foundation, 59 Temple Place - S
    but not yet categorized in any way.  The seen_objects list has had
    it's pc_begin and count fields initialized at minimum, and is sorted
    by decreasing value of pc_begin.  */
+#if !(defined (__MINGW32__ ) || defined (__CYGWIN__))
 static struct object *unseen_objects;
 static struct object *seen_objects;
+#else
+extern void** __w32_sharedptr;
+extern int __w32_sharedptr_unseen_objects;
+extern int __w32_sharedptr_seen_objects;
+#define unseen_objects  (*(struct object**)(__w32_sharedptr + __w32_sharedptr_unseen_objects))
+#define seen_objects    (*(struct object**)(__w32_sharedptr + __w32_sharedptr_seen_objects))
+#endif
 
 #ifdef __GTHREAD_MUTEX_INIT
 static __gthread_mutex_t object_mutex = __GTHREAD_MUTEX_INIT;
Index: gcc/gcc/config/i386/cygwin.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/cygwin.h,v
retrieving revision 1.62.2.1.2.7
diff -u -p -r1.62.2.1.2.7 cygwin.h
--- gcc/gcc/config/i386/cygwin.h	15 Jul 2002 05:13:06 -0000	1.62.2.1.2.7
+++ gcc/gcc/config/i386/cygwin.h	28 Jul 2002 00:08:09 -0000
@@ -51,7 +51,7 @@ Boston, MA 02111-1307, USA.  */
 #define STARTFILE_SPEC "\
   %{shared|mdll: %{mno-cygwin:dllcrt2%O%s}}\
   %{!shared: %{!mdll: %{!mno-cygwin:crt0%O%s} %{mno-cygwin:crt2%O%s}\
-  %{pg:gcrt0%O%s}}}   crtbegin%O%s"
+  %{pg:gcrt0%O%s}}} crts%O%s crtbegin%O%s"
 
 #undef ENDFILE_SPEC
 #define ENDFILE_SPEC "crtend%O%s"
Index: gcc/gcc/config/i386/mingw32.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/mingw32.h,v
retrieving revision 1.22.10.3
diff -u -p -r1.22.10.3 mingw32.h
--- gcc/gcc/config/i386/mingw32.h	6 Jul 2002 03:38:21 -0000	1.22.10.3
+++ gcc/gcc/config/i386/mingw32.h	28 Jul 2002 00:08:09 -0000
@@ -69,7 +69,7 @@ Boston, MA 02111-1307, USA.  */
 #undef STARTFILE_SPEC
 #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \
   %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \
-  crtbegin%O%s"
+  crts%O%s crtbegin%O%s"
 
 #undef ENDFILE_SPEC
 #define ENDFILE_SPEC "crtend%O%s"
Index: gcc/gcc/config/i386/t-cygming
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/Attic/t-cygming,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 t-cygming
--- gcc/gcc/config/i386/t-cygming	12 Jul 2002 05:09:51 -0000	1.1.2.2
+++ gcc/gcc/config/i386/t-cygming	28 Jul 2002 00:08:12 -0000
@@ -13,6 +13,10 @@ LIBGCC2_INCLUDES = -I$(srcdir)/../winsup
 winnt.o: $(srcdir)/config/i386/winnt.c $(RTL_H) $(TREE_H) $(CONFIG_H)
 	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/config/i386/winnt.c
 
+crts.o: $(srcdir)/config/i386/w32-shared-ptr.c $(CONFIG_H)
+	$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(INCLUDES) \
+		-c $(srcdir)/config/i386/w32-shared-ptr.c -o crts.o
+
 # Don't run fixproto
 STMP_FIXPROTO=
 STMP_FIXINC=stmp-fixinc
Index: gcc/libstdc++-v3/libsupc++/eh_terminate.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/eh_terminate.cc,v
retrieving revision 1.2
diff -u -p -r1.2 eh_terminate.cc
--- gcc/libstdc++-v3/libsupc++/eh_terminate.cc	9 Jun 2001 06:49:13 -0000	1.2
+++ gcc/libstdc++-v3/libsupc++/eh_terminate.cc	28 Jul 2002 00:11:36 -0000
@@ -36,9 +36,11 @@
 
 using namespace __cxxabiv1;
 
+#if !(defined (__MINGW32__) || defined (__CYGWIN__))
 /* The current installed user handlers.  */
 std::terminate_handler __cxxabiv1::__terminate_handler = std::abort;
 std::unexpected_handler __cxxabiv1::__unexpected_handler = std::terminate;
+#endif
 
 void
 __cxxabiv1::__terminate (std::terminate_handler handler)
Index: gcc/libstdc++-v3/libsupc++/unwind-cxx.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/unwind-cxx.h,v
retrieving revision 1.3
diff -u -p -r1.3 unwind-cxx.h
--- gcc/libstdc++-v3/libsupc++/unwind-cxx.h	18 Nov 2001 02:09:23 -0000	1.3
+++ gcc/libstdc++-v3/libsupc++/unwind-cxx.h	28 Jul 2002 00:11:36 -0000
@@ -126,8 +126,16 @@ extern void __terminate(std::terminate_h
 extern void __unexpected(std::unexpected_handler) __attribute__((noreturn));
 
 // The current installed user handlers.
+#if defined  (__MINGW32__) || defined (__CYGWIN__)
+extern "C" void** __w32_sharedptr;
+extern "C" int __w32_sharedptr_terminate;
+extern "C" int __w32_sharedptr_unexpected;
+#define __terminate_handler     (*(std::terminate_handler*)(__w32_sharedptr + __w32_sharedptr_terminate))
+#define __unexpected_handler    (*(std::unexpected_handler*)(__w32_sharedptr + __w32_sharedptr_unexpected))
+#else
 extern std::terminate_handler __terminate_handler;
 extern std::unexpected_handler __unexpected_handler;
+#endif
 
 // These are explicitly GNU C++ specific.
 
--- /dev/null	Sun Jul 28 12:20:26 2002
+++ gcc/gcc/config/i386/w32-shared-ptr.c	Sat Jul 27 16:13:22 2002
@@ -0,0 +1,118 @@
+/*
+ * crts.c
+ *
+ * Share informations between EXE/DLLs without using an
+ * additional DLL.
+ *
+ * Contributors:
+ *  Created by Adriano dos Santos Fernandes <adrianosf@uol.com.br>
+ *
+ *  THIS SOFTWARE IS NOT COPYRIGHTED
+ *
+ *  This source code is offered for use in the public domain. You may
+ *  use, modify or distribute it freely.
+ *
+ *  This code is distributed in the hope that it will be useful but
+ *  WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
+ *  DISCLAMED. This includes but is not limited to warrenties of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+
+
+#define SHAREDPTR_LETTER0   'a'
+#define SHAREDPTR_LETTER1   'A'
+
+void** __w32_sharedptr = NULL;
+
+const int __w32_sharedptr_terminate = 1;
+const int __w32_sharedptr_unexpected = 2;
+const int __w32_sharedptr_unseen_objects = 3;
+const int __w32_sharedptr_seen_objects = 4;
+#define SHAREDPTR_COUNT     5
+
+/* cygwin doesn't have ultoa, so you use a custom version
+   for this specific job */
+static int  __ultobstr (unsigned long val, char *buf)
+{
+  char temp[sizeof(unsigned long) * 8 + 1];
+  char* p = temp;
+  int len = 0;
+  if (val == 0)
+    *p++ = '0';
+  else
+    /* convert to bin digits, in reversed order*/
+    for (; val > 0; val /= 2)
+      *p++ = (char)(val % 2) + '0';
+
+  /* reverse copy */  
+  while(p > temp)
+  {
+    *buf++ = *--p;
+    len++;	
+  }
+  *buf = '\0';
+  return len;
+}
+
+void __w32_sharedptr_initialize(void) 
+{
+  char s[sizeof(void*) * 8 + 1];
+  ATOM atom;
+  int i;
+
+  if (__w32_sharedptr)
+     return;
+
+  memset(s, SHAREDPTR_LETTER0, sizeof(void*) * 8);
+  s[sizeof(void*) * 8] = '\0';
+
+  atom = FindAtom(s);
+
+  if (atom == 0) {
+    char s0[sizeof(s)];
+    int len;
+
+    __w32_sharedptr = (void**)malloc(sizeof(void*) * SHAREDPTR_COUNT);
+    memset(__w32_sharedptr, 0, sizeof(void*) * SHAREDPTR_COUNT);
+
+    /* initialize to default handlers */
+    *(__w32_sharedptr + __w32_sharedptr_terminate) = abort;
+    *(__w32_sharedptr + __w32_sharedptr_unexpected) = abort;
+
+    len = __ultobstr ((unsigned long)__w32_sharedptr, s0);
+    
+    memset(s, SHAREDPTR_LETTER0, (sizeof(s) - 1) - len);
+
+    for (i = 0; i < len; i++)
+      s[sizeof(s) - 1 - len + i] =
+	 (s0[i] == '0' ? SHAREDPTR_LETTER0 : SHAREDPTR_LETTER1);
+
+    s[sizeof(s) - 1] = '\0';
+
+#ifdef DEBUG
+    printf ("%s: initialize sharedptr: (0x%x):%s\n",
+             __FUNCTION__, __w32_sharedptr, s0);
+#endif
+
+    AddAtom(s);
+  }
+  else {
+    GetAtomName(atom, s, sizeof(s));
+
+    for (i = 0; i < sizeof(s) - 1; i++)
+       s[i] = (s[i] == SHAREDPTR_LETTER0 ? '0' : '1');
+
+    __w32_sharedptr = (void*)strtoul(s, NULL, 2);
+
+#ifdef DEBUG
+    printf ("%s: got sharedptr (0x%x): %s\n",
+	    __FUNCTION__, __w32_sharedptr, s);
+#endif
+
+  }
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]