[patch] libunwind-based exception-handling for gcc (2nd version)

David Mosberger davidm@napali.hpl.hp.com
Mon Sep 30 22:07:00 GMT 2002


Below is a second, greatly simplified, version of the patch to add
libunwind support to gcc.  libunwind is intended to be a
platform-independent unwind API, though at the moment it's implemented
for ia64 linux only.  Taking advantage of libunwind avoids code
duplication in gcc and thereby reduces maintenance efforts.

The patch should be safe to apply because for now it is still
necessary to use configure option --enable-libunwind-exceptions to use
libunwind.  Otherwise, gcc will fall back on the existing unwinder.

If it looks OK, I'd appreciate it if someone could check it in.  (note
that the patch for except.h may look big, but that's mostly due to
indentation changes; the real change is trivial.)

Thanks,

	--david

2002-09-30  David Mosberger-Tang  <David.Mosberger@acm.org>

	* gcc.c (init_spec) [USE_LIBUNWIND_EXCEPTIONS]: Mention -lunwind
	along with the shared version of libgcc since the latter requires
	the former.

	* config/ia64/unwind-ia64.c [__USING_LIBUNWIND_EXCEPTIONS__]:
	Include "unwind-libunwind.c".

	* except.h [USE_LIBUNWIND_EXCEPTIONS]:
	Define USING_LIBUNWIND_EXCEPTIONS as 1, USING_SJLJ_EXCEPTIONS as 0.
	[!USE_LIBUNWIND_EXCEPTIONS]: Define USING_LIBUNWIND_EXCEPTIONS as 0.

	* c-common.c (cb_register_builtins): If USING_LIBUNWIND_EXCEPTIONS,
	define macro __USING_LIBUNWIND_EXCEPTIONS__.

	* unwind-libunwind.c: New file.

Index: c-common.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.385
diff -u -r1.385 c-common.c
--- c-common.c	27 Sep 2002 13:30:05 -0000	1.385
+++ c-common.c	1 Oct 2002 04:55:27 -0000
@@ -4905,6 +4905,8 @@
   /* libgcc needs to know this.  */
   if (USING_SJLJ_EXCEPTIONS)
     cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__");
+  if (USING_LIBUNWIND_EXCEPTIONS)
+    cpp_define (pfile, "__USING_LIBUNWIND_EXCEPTIONS__");
 
   /* stddef.h needs to know these.  */
   builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
Index: except.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/except.h,v
retrieving revision 1.65
diff -u -r1.65 except.h
--- except.h	25 Aug 2002 05:21:10 -0000	1.65
+++ except.h	1 Oct 2002 04:55:27 -0000
@@ -159,25 +159,31 @@
 #define MUST_USE_SJLJ_EXCEPTIONS	0
 #endif
 
-#ifdef CONFIG_SJLJ_EXCEPTIONS
-# if CONFIG_SJLJ_EXCEPTIONS == 1
-#  define USING_SJLJ_EXCEPTIONS		1
-# endif
-# if CONFIG_SJLJ_EXCEPTIONS == 0
-#  define USING_SJLJ_EXCEPTIONS		0
-#  ifndef EH_RETURN_DATA_REGNO
-    #error "EH_RETURN_DATA_REGNO required"
-#  endif
-#  ifndef EH_RETURN_STACKADJ_RTX
-    #error "EH_RETURN_STACKADJ_RTX required"
-#  endif
-#  if !defined(EH_RETURN_HANDLER_RTX) && !defined(HAVE_eh_return)
-    #error "EH_RETURN_HANDLER_RTX or eh_return required"
+#ifdef USE_LIBUNWIND_EXCEPTIONS
+# define USING_LIBUNWIND_EXCEPTIONS	1
+# define USING_SJLJ_EXCEPTIONS		0
+#else
+# define USING_LIBUNWIND_EXCEPTIONS	0
+# ifdef CONFIG_SJLJ_EXCEPTIONS
+#  if CONFIG_SJLJ_EXCEPTIONS == 1
+#   define USING_SJLJ_EXCEPTIONS		1
 #  endif
-#  if !defined(DWARF2_UNWIND_INFO) && !defined(IA64_UNWIND_INFO)
-    #error "{DWARF2,IA64}_UNWIND_INFO required"
+#  if CONFIG_SJLJ_EXCEPTIONS == 0
+#   define USING_SJLJ_EXCEPTIONS		0
+#   ifndef EH_RETURN_DATA_REGNO
+     #error "EH_RETURN_DATA_REGNO required"
+#   endif
+#   ifndef EH_RETURN_STACKADJ_RTX
+     #error "EH_RETURN_STACKADJ_RTX required"
+#   endif
+#   if !defined(EH_RETURN_HANDLER_RTX) && !defined(HAVE_eh_return)
+     #error "EH_RETURN_HANDLER_RTX or eh_return required"
+#   endif
+#   if !defined(DWARF2_UNWIND_INFO) && !defined(IA64_UNWIND_INFO)
+     #error "{DWARF2,IA64}_UNWIND_INFO required"
+#   endif
 #  endif
+# else
+#  define USING_SJLJ_EXCEPTIONS		MUST_USE_SJLJ_EXCEPTIONS
 # endif
-#else
-# define USING_SJLJ_EXCEPTIONS		MUST_USE_SJLJ_EXCEPTIONS
 #endif
Index: gcc.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.337
diff -u -r1.337 gcc.c
--- gcc.c	22 Sep 2002 14:09:33 -0000	1.337
+++ gcc.c	1 Oct 2002 04:55:33 -0000
@@ -1531,6 +1531,9 @@
 #else
 			    "-lgcc_s%M"
 #endif
+#ifdef USE_LIBUNWIND_EXCEPTIONS
+			    " -lunwind"
+#endif
 			    ,
 			    "-lgcc",
 			    "-lgcc_eh");
Index: config/ia64/unwind-ia64.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/ia64/unwind-ia64.c,v
retrieving revision 1.11
diff -u -r1.11 unwind-ia64.c
--- config/ia64/unwind-ia64.c	28 Sep 2002 15:29:41 -0000	1.11
+++ config/ia64/unwind-ia64.c	1 Oct 2002 04:55:37 -0000
@@ -41,6 +41,9 @@
 #undef ENABLE_MALLOC_CHECKING
 
 #ifndef __USING_SJLJ_EXCEPTIONS__
+# ifdef __USING_LIBUNWIND_EXCEPTIONS__
+#  include "unwind-libunwind.c"
+# else /* !__USING_LIBUNWIND_EXCEPTIONS__ */
 #define UNW_VER(x)		((x) >> 48)
 #define UNW_FLAG_MASK		0x0000ffff00000000
 #define UNW_FLAG_OSMASK		0x0000f00000000000
@@ -2238,4 +2241,5 @@
 }
 
 #include "unwind.inc"
+# endif /* !__USING_LIBUNWIND_EXCEPTIONS__ */
 #endif



More information about the Gcc-patches mailing list