This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


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

Re: Problems with exception handling in glibc and gcc.


On Tue, Jul 04, 2000 at 05:56:09PM -0700, Ulrich Drepper wrote:
> "H . J . Lu" <hjl@lucon.org> writes:
> 
> > The problem is there should be only one copy of the exception funtions
> > used in the main executable and all DSOs. If we decide that glibc 
> > will never use the exception, things may be a little easier.
> 
> This is actually something we want to use in glibc.  The exception
> handling mechanism is currently poorly (means not at all) integrated
> with the thread cleanup handling.  Also, we implement for the cleanup
> handling something similar to exception handling.
> 
> Therefore the idea is to have exceptions in C (compatible with the C++
> exceptions) and use them in the thread cleanup handling.
> 

This patch is intended for discussion only. It tries to define a libgcc
runtime ABI so that we can build a libgcc.so. Any comments?

Thanks.


H.J.
---
2000-07-05  H.J. Lu  (hjl@gnu.org)

	* runtime.h: New. The header file for the libgcc runtime ABI.

	* Makefile.in (USER_H): Add $(srcdir)/runtime.h.

	* frame.h (__register_frame): Moved to runtime.h.
	(__register_frame_table): Likewise.
	(__register_frame_table): Likewise.
	(__deregister_frame): Likewise.
	(__register_frame_info): Likewise.
	(__register_frame_info_table): Likewise.
	(__deregister_frame_info): Likewise.

	* frame.c: Include "assert.h" and "runtime.h".
	(__register_frame): Pass "struct frame_object *" instead of
	"struct object *" to __register_frame_info ().
	(__register_frame_info): Take "struct frame_object *" instead of
	"struct object *".
	(__register_frame_info_table): Likewise.

	* crtstuff.c: Include "runtime.h" instead of "frame.h".
	(__register_frame_info): Take "struct frame_object *" instead of
	"struct object *".
	(fini_dummy): Pass "struct frame_object *" instead of
	"struct object *" to __register_frame_info ().
	(__frame_dummy): Likewise.
	(__reg_frame_ctor): Likewise.

	* collect2.c (write_c_file_stat): Include "runtime.h" and pass
	"struct frame_object *" instead of "struct object *" to
	__register_frame_info_table ().
	(write_c_file_glob): Likewise.

	* libgcc2.c: Include "runtime.h" instead of "frame.h".
	(__do_global_ctors): Pass "struct frame_object *" instead of
	"struct object *" to __register_frame_info ().

Index: gcc/crtstuff.c
===================================================================
RCS file: /work/cvs/gnu/egcs/gcc/crtstuff.c,v
retrieving revision 1.1.1.16
diff -u -p -r1.1.1.16 crtstuff.c
--- gcc/crtstuff.c	2000/05/16 19:51:24	1.1.1.16
+++ gcc/crtstuff.c	2000/07/05 15:53:39
@@ -60,7 +60,7 @@ Boston, MA 02111-1307, USA.  */
 #include "tsystem.h"
 
 #include "defaults.h"
-#include "frame.h"
+#include "runtime.h"
 
 /* We do not want to add the weak attribute to the declarations of these
    routines in frame.h because that will cause the definition of these
@@ -84,7 +84,7 @@ Boston, MA 02111-1307, USA.  */
    
 /* References to __register_frame_info and __deregister_frame_info should
    be weak in this file if at all possible.  */
-extern void __register_frame_info (void *, struct object *)
+extern void __register_frame_info (void *, struct frame_object *)
 				  TARGET_ATTRIBUTE_WEAK;
 
 extern void *__deregister_frame_info (void *)
@@ -228,7 +228,7 @@ fini_dummy (void)
 static void
 frame_dummy (void)
 {
-  static struct object object;
+  static struct frame_object object;
   if (__register_frame_info)
     __register_frame_info (__EH_FRAME_BEGIN__, &object);
 }
@@ -327,7 +327,7 @@ __do_global_dtors (void)
 void
 __frame_dummy (void)
 {
-  static struct object object;
+  static struct frame_object object;
   if (__register_frame_info)
     __register_frame_info (__EH_FRAME_BEGIN__, &object);
 }
@@ -552,7 +552,7 @@ static void __reg_frame_ctor (void) __at
 static void
 __reg_frame_ctor (void)
 {
-  static struct object object;
+  static struct frame_object object;
   const struct section *eh_frame;
 
   eh_frame = getsectbynamefromheader (&_mh_execute_header,
Index: gcc/collect2.c
===================================================================
RCS file: /work/cvs/gnu/egcs/gcc/collect2.c,v
retrieving revision 1.1.1.44
diff -u -p -r1.1.1.44 collect2.c
--- gcc/collect2.c	2000/06/25 15:56:00	1.1.1.44
+++ gcc/collect2.c	2000/07/05 15:56:59
@@ -1945,21 +1945,10 @@ write_c_file_stat (stream, name)
       write_list (stream, "\t\t&", frame_tables.first);
       fprintf (stream, "\t0\n};\n");
 
-      /* This must match what's in frame.h.  */
-      fprintf (stream, "struct object {\n");
-      fprintf (stream, "  void *pc_begin;\n");
-      fprintf (stream, "  void *pc_end;\n");
-      fprintf (stream, "  void *fde_begin;\n");
-      fprintf (stream, "  void *fde_array;\n");
-      fprintf (stream, "  __SIZE_TYPE__ count;\n");
-      fprintf (stream, "  struct object *next;\n");
-      fprintf (stream, "};\n");
+      fprintf (stream, "#include <runtime.h>\n");
 
-      fprintf (stream, "extern void __register_frame_info_table (void *, struct object *);\n");
-      fprintf (stream, "extern void *__deregister_frame_info (void *);\n");
-
       fprintf (stream, "static void reg_frame () {\n");
-      fprintf (stream, "\tstatic struct object ob;\n");
+      fprintf (stream, "\tstatic struct frame_object ob;\n");
       fprintf (stream, "\t__register_frame_info_table (frame_table, &ob);\n");
       fprintf (stream, "\t}\n");
 
@@ -2031,22 +2020,11 @@ write_c_file_glob (stream, name)
       fprintf (stream, "\tstatic void *frame_table[] = {\n");
       write_list (stream, "\t\t&", frame_tables.first);
       fprintf (stream, "\t0\n};\n");
-
-      /* This must match what's in frame.h.  */
-      fprintf (stream, "struct object {\n");
-      fprintf (stream, "  void *pc_begin;\n");
-      fprintf (stream, "  void *pc_end;\n");
-      fprintf (stream, "  void *fde_begin;\n");
-      fprintf (stream, "  void *fde_array;\n");
-      fprintf (stream, "  __SIZE_TYPE__ count;\n");
-      fprintf (stream, "  struct object *next;\n");
-      fprintf (stream, "};\n");
 
-      fprintf (stream, "extern void __register_frame_info_table (void *, struct object *);\n");
-      fprintf (stream, "extern void *__deregister_frame_info (void *);\n");
+      fprintf (stream, "#include <runtime.h>\n");
 
       fprintf (stream, "static void reg_frame () {\n");
-      fprintf (stream, "\tstatic struct object ob;\n");
+      fprintf (stream, "\tstatic struct frame_object ob;\n");
       fprintf (stream, "\t__register_frame_info_table (frame_table, &ob);\n");
       fprintf (stream, "\t}\n");
 
Index: gcc/libgcc2.c
===================================================================
RCS file: /work/cvs/gnu/egcs/gcc/libgcc2.c,v
retrieving revision 1.1.1.45
diff -u -p -r1.1.1.45 libgcc2.c
--- gcc/libgcc2.c	2000/06/27 14:39:04	1.1.1.45
+++ gcc/libgcc2.c	2000/07/05 15:59:36
@@ -2794,7 +2794,7 @@ cacheflush (char *beg, int size, int fla
    code to run constructors.  In that case, we need to handle EH here, too.  */
 
 #ifdef EH_FRAME_SECTION
-#include "frame.h"
+#include "runtime.h"
 extern unsigned char __EH_FRAME_BEGIN__[];
 #endif
 
@@ -2834,7 +2834,7 @@ __do_global_ctors (void)
 {
 #ifdef EH_FRAME_SECTION
   {
-    static struct object object;
+    static struct frame_object object;
     __register_frame_info (__EH_FRAME_BEGIN__, &object);
   }
 #endif
Index: gcc/frame.h
===================================================================
RCS file: /work/cvs/gnu/egcs/gcc/frame.h,v
retrieving revision 1.1.1.9
diff -u -p -r1.1.1.9 frame.h
--- gcc/frame.h	2000/07/04 18:56:08	1.1.1.9
+++ gcc/frame.h	2000/07/05 16:07:24
@@ -66,29 +66,6 @@ struct object {
   struct object *next;
 };
 
-/* Note the following routines are exported interfaces from libgcc; do not
-   change these interfaces.  Instead create new interfaces.  Also note
-   references to these functions may be made weak in files where they
-   are referenced.  */
-
-extern void __register_frame (void * );
-extern void __register_frame_table (void *);
-extern void __deregister_frame (void *);
-
-/* Called either from crtbegin.o or a static constructor to register the
-   unwind info for an object or translation unit, respectively.  */
-
-extern void __register_frame_info (void *, struct object *);
-
-/* Similar, but BEGIN is actually a pointer to a table of unwind entries
-   for different translation units.  Called from the file generated by
-   collect2.  */
-extern void __register_frame_info_table (void *, struct object *);
-
-/* Called from crtend.o to deregister the unwind info for an object.  */
-
-extern void *__deregister_frame_info (void *);
-
 /* Called from __throw to find the registers to restore for a given
    PC_TARGET.  The caller should allocate a local variable of `struct
    frame_state' (declared in frame.h) and pass its address to STATE_IN.
Index: gcc/frame.c
===================================================================
RCS file: /work/cvs/gnu/egcs/gcc/frame.c,v
retrieving revision 1.1.1.20
diff -u -p -r1.1.1.20 frame.c
--- gcc/frame.c	2000/06/08 23:24:44	1.1.1.20
+++ gcc/frame.c	2000/07/05 16:08:30
@@ -29,6 +29,9 @@ along with GNU CC; see the file COPYING.
 the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#include "runtime.h"
+#include "assert.h"
+
 /* Sorting an array of FDEs by address.
    (Ideally we would have the linker sort the FDEs so we don't have to do
    it at run time. But the linkers are not yet prepared for this.)  */
@@ -244,8 +247,12 @@ end_fde_sort (fde_accumulator *accu, siz
 /* Called from crtbegin.o to register the unwind info for an object.  */
 
 void
-__register_frame_info (void *begin, struct object *ob)
+__register_frame_info (void *begin, struct frame_object *o)
 {
+  struct object *ob = (struct object *) o;
+
+  assert (sizeof (struct frame_object) >= sizeof (struct object));
+
   ob->fde_begin = begin;
 
   ob->pc_begin = ob->pc_end = 0;
@@ -264,7 +271,8 @@ __register_frame_info (void *begin, stru
 void
 __register_frame (void *begin)
 {
-  struct object *ob = (struct object *) malloc (sizeof (struct object));
+  struct frame_object *ob =
+    (struct frame_object *) malloc (sizeof (struct frame_object));
   __register_frame_info (begin, ob);                       
 }
 
@@ -273,8 +281,12 @@ __register_frame (void *begin)
    collect2.  */
 
 void
-__register_frame_info_table (void *begin, struct object *ob)
+__register_frame_info_table (void *begin, struct frame_object *o)
 {
+  struct object *ob = (struct object *) o;
+
+  assert (sizeof (struct frame_object) >= sizeof (struct object));
+
   ob->fde_begin = begin;
   ob->fde_array = begin;
 
--- /dev/null	Tue May  5 13:32:27 1998
+++ gcc/runtime.h	Wed Jul  5 09:08:42 2000
@@ -0,0 +1,34 @@
+#ifndef __RUNTIME_H
+#define __RUNTIME_H 1
+
+struct frame_object
+{
+  /* It should be large enough for future expansion. */
+  void * dummy [16];
+};
+
+/* Note the following routines are exported interfaces from libgcc; do
+   not change these interfaces.  Instead create new interfaces.  Also
+   note references to these functions may be made weak in files where
+   they are referenced.  */
+
+extern void __register_frame (void * );
+extern void __register_frame_table (void *);
+extern void __deregister_frame (void *);
+
+/* Called either from crtbegin.o or a static constructor to register the
+   unwind info for an object or translation unit, respectively.  */
+
+extern void __register_frame_info (void *, struct frame_object *);
+
+/* Similar, but BEGIN is actually a pointer to a table of unwind
+   entries for different translation units.  Called from the file
+   generated by collect2.  */
+
+extern void __register_frame_info_table (void *, struct frame_object *);
+
+/* Called from crtend.o to deregister the unwind info for an object.  */
+
+extern void *__deregister_frame_info (void *);
+
+#endif /* __RUNTIME_H */
--- gcc/Makefile.in.runtime	Wed Jul  5 09:10:43 2000
+++ gcc/Makefile.in	Wed Jul  5 09:11:41 2000
@@ -153,6 +153,7 @@ INSTALL_HEADERS_DIR = @build_install_hea
 USER_H = $(srcdir)/ginclude/stdarg.h $(srcdir)/ginclude/stddef.h \
     $(srcdir)/ginclude/varargs.h $(srcdir)/ginclude/proto.h \
     $(srcdir)/ginclude/stdbool.h $(srcdir)/ginclude/iso646.h \
+    $(srcdir)/runtime.h \
     $(EXTRA_HEADERS) $(LANG_EXTRA_HEADERS)
 
 # Target to use whe installing assert.h.  Some systems may

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