This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

revised gcc/libunwind patch


It turns out that a couple of typos sneaked past my testing in the
last patch because some of the files didn't get recompiled.  The patch
below fixes those.

Thanks to Tom Tromey for pointing out that the cvsutils package has a
"cvsdo add" command which doesn't require write permission.  This way,
the patch below should hopefully be complete and apply without any
problems.

	--david

2002-10-02  David Mosberger-Tang  <David.Mosberger@acm.org>

	* config/t-libunwind: Mention unwind-sjlj.c; it provides the fallback
	unwinder if the libunwind-based one can't be used for some reason.

	* unwind-libunwind.c: Change #ifdef __USING_LIBUNWIND_EXCEPTIONS__
	to #ifndef __USING_SJLJ_EXCEPTIONS__.

2002-10-01  David Mosberger-Tang  <David.Mosberger@acm.org>

	* configure.in: Move sjlj-exceptions and --enable-libunwind-exceptions
	before inclusion of config.gcc, but after configuring the compiler etc.
	Determine default value for --enable-libunwind-exceptions based on
	whether the host has a libunwind library (not guaranteed to be correct,
	but it's a reasonable first guess and can always be overridden with an
	explicit --enable/disable-libunwind-exceptions.

	* config.gcc: For target ia64*-*-linux*, mention t-libunwind as a
	tmake_file when $use_libunwind_exceptions is enabled.

	* Makefile.in: Update comment: LIB2ADDEH is updated not just by
	ia64 (e.g., config/t-linux also updates it).

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

	* unwind-libunwind.c: New file.

	* config/t-libunwind: Ditto.

Index: Makefile.in
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.949
diff -u -r1.949 Makefile.in
--- Makefile.in	26 Sep 2002 19:29:29 -0000	1.949
+++ Makefile.in	3 Oct 2002 04:52:56 -0000
@@ -393,7 +393,7 @@
   -finhibit-size-directive -fno-inline-functions -fno-exceptions \
   -fno-zero-initialized-in-bss
 
-# Additional sources to handle exceptions; overridden on ia64.
+# Additional sources to handle exceptions; overridden by targets as needed.
 LIB2ADDEH = $(srcdir)/unwind-dw2.c $(srcdir)/unwind-dw2-fde.c \
   $(srcdir)/unwind-sjlj.c
 LIB2ADDEHDEP = unwind.inc unwind-dw2-fde.h
Index: config.gcc
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config.gcc,v
retrieving revision 1.251
diff -u -r1.251 config.gcc
--- config.gcc	1 Oct 2002 20:16:02 -0000	1.251
+++ config.gcc	3 Oct 2002 04:52:58 -0000
@@ -1396,6 +1396,9 @@
 	tmake_file="t-slibgcc-elf-ver t-linux ia64/t-ia64 ia64/t-glibc"
 	target_cpu_default="MASK_GNU_AS|MASK_GNU_LD"
 	extra_parts="crtbegin.o crtend.o crtbeginS.o crtendS.o crtfastmath.o"
+	if test x"$use_libunwind_exceptions" = xyes; then
+	  tmake_file="$tmake_file t-libunwind"
+	fi
 	;;
 ia64*-*-hpux*)
 	tm_file="${tm_file} dbxelf.h elfos.h svr4.h ia64/sysv4.h ia64/hpux.h ia64/hpux_longdouble.h"
Index: configure.in
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/configure.in,v
retrieving revision 1.619
diff -u -r1.619 configure.in
--- configure.in	6 Sep 2002 12:00:11 -0000	1.619
+++ configure.in	3 Oct 2002 04:53:14 -0000
@@ -756,6 +756,25 @@
 AC_SUBST(manext)
 AC_SUBST(objext)
 
+# With Setjmp/Longjmp based exception handling.
+AC_ARG_ENABLE(sjlj-exceptions,
+[  --enable-sjlj-exceptions
+                          arrange to use setjmp/longjmp exception handling],
+[sjlj=`if test $enableval = yes; then echo 1; else echo 0; fi`
+AC_DEFINE_UNQUOTED(CONFIG_SJLJ_EXCEPTIONS, $sjlj,
+  [Define 0/1 to force the choice for exception handling model.])])
+
+AC_CHECK_LIB(unwind, main, use_libunwind_default=yes, use_libunwind_default=no)
+# Use libunwind based exception handling.
+AC_ARG_ENABLE(libunwind-exceptions,
+[  --enable-libunwind-exceptions  force use libunwind for exceptions],
+use_libunwind_exceptions=$enableval,
+use_libunwind_exceptions=$use_libunwind_default)
+if test x"$use_libunwind_exceptions" = xyes; then
+   AC_DEFINE(USE_LIBUNWIND_EXCEPTIONS, 1,
+	[Define if gcc should use -lunwind.])
+fi
+
 target_gtfiles=
 build_xm_file=
 build_xm_defines=
@@ -2403,24 +2422,6 @@
   MAINT='#'
 fi
 AC_SUBST(MAINT)dnl
-
-# With Setjmp/Longjmp based exception handling.
-AC_ARG_ENABLE(sjlj-exceptions,
-[  --enable-sjlj-exceptions
-                          arrange to use setjmp/longjmp exception handling],
-[sjlj=`if test $enableval = yes; then echo 1; else echo 0; fi`
-AC_DEFINE_UNQUOTED(CONFIG_SJLJ_EXCEPTIONS, $sjlj,
-  [Define 0/1 to force the choice for exception handling model.])])
-
-# Use libunwind based exception handling.
-AC_ARG_ENABLE(libunwind-exceptions,
-[  --enable-libunwind-exceptions  force use libunwind for exceptions],
-use_libunwind_exceptions=$enableval,
-use_libunwind_exceptions=no)
-if test x"$use_libunwind_exceptions" = xyes; then
-   AC_DEFINE(USE_LIBUNWIND_EXCEPTIONS, 1,
-	[Define if gcc should use -lunwind.])
-fi
 
 # Make empty files to contain the specs and options for each language.
 # Then add #include lines to for a compiler that has specs and/or options.
Index: gcc.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.338
diff -u -r1.338 gcc.c
--- gcc.c	1 Oct 2002 18:10:04 -0000	1.338
+++ gcc.c	3 Oct 2002 04:53:19 -0000
@@ -1531,6 +1531,9 @@
 #else
 			    "-lgcc_s%M"
 #endif
+#ifdef USE_LIBUNWIND_EXCEPTIONS
+			    " -lunwind"
+#endif
 			    ,
 			    "-lgcc",
 			    "-lgcc_eh");
Index: unwind-libunwind.c
===================================================================
RCS file: unwind-libunwind.c
diff -N unwind-libunwind.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ unwind-libunwind.c	3 Oct 2002 04:53:19 -0000
@@ -0,0 +1,157 @@
+/* Subroutines needed for unwinding stack frames via the libunwind API.
+   Copyright (C) 2002
+   Free Software Foundation, Inc.
+   Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+
+   This file is part of GNU CC.
+
+   GNU CC is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   GNU CC is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU CC; see the file COPYING.  If not, write to
+   the Free Software Foundation, 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+/* As a special exception, if you link this library with other files,
+   some of which are compiled with GCC, to produce an executable,
+   this library does not by itself cause the resulting executable
+   to be covered by the GNU General Public License.
+   This exception does not however invalidate any other reasons why
+   the executable file might be covered by the GNU General Public License.  */
+
+#include "tconfig.h"
+#include "tsystem.h"
+#include "unwind.h"
+
+#ifndef __USING_SJLJ_EXCEPTIONS__
+
+#define UNW_LOCAL_ONLY
+
+#include <libunwind.h>
+
+typedef struct {
+  _Unwind_Personality_Fn personality;
+} _Unwind_FrameState;
+
+struct _Unwind_Context {
+  unw_cursor_t cursor;
+};
+
+
+/* First come the helper-routines that are needed by unwind.inc.  */
+
+static _Unwind_Reason_Code
+uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
+{
+  unw_word_t handler;
+
+  if (unw_step (&context->cursor) <= 0)
+    return _URC_END_OF_STACK;
+
+  unw_get_reg (&context->cursor, UNW_REG_HANDLER, &handler);
+  fs->personality = (_Unwind_Personality_Fn) handler;
+
+  return _URC_NO_REASON;
+}
+
+#define uw_update_context(context,fs)	do { ; } while (0)
+
+static inline _Unwind_Ptr
+uw_identify_context (struct _Unwind_Context *context)
+{
+  unw_word_t ip;
+  unw_get_reg (&context->cursor, UNW_REG_IP, &ip);
+  return (_Unwind_Ptr) ip;
+}
+
+#define uw_init_context(context)		\
+do						\
+  {						\
+    unw_context_t uc;				\
+    unw_getcontext (&uc);			\
+    unw_init_local (&(context)->cursor, &uc);	\
+  }						\
+while (0)
+
+static inline void __attribute__ ((noreturn))
+uw_install_context (struct _Unwind_Context *current __attribute__ ((unused)),
+		    struct _Unwind_Context *target)
+{
+  unw_resume (&(target)->cursor);
+  abort ();
+}
+
+
+/* Now come the helper-routines which may be called from an exception
+   handler.  The interface for these routines are defined by the C++
+   ABI.  See: http://www.codesourcery.com/cxx-abi/abi-eh.html */
+
+_Unwind_Word
+_Unwind_GetGR (struct _Unwind_Context *context, int index)
+{
+  unw_word_t ret;
+
+  /* Note: here we depend on the fact that general registers are
+     expected to start with register number 0!  */
+  unw_get_reg (&context->cursor, index, &ret);
+  return ret;
+}
+
+/* Overwrite the saved value for register REG in CONTEXT with VAL.  */
+
+void
+_Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
+{
+  /* Note: here we depend on the fact that general registers are
+     expected to start with register number 0!  */
+  unw_set_reg (&context->cursor, index, val);
+}
+
+/* Retrieve the return address for CONTEXT.  */
+
+inline _Unwind_Ptr
+_Unwind_GetIP (struct _Unwind_Context *context)
+{
+  unw_word_t ret;
+
+  unw_get_reg (&context->cursor, UNW_REG_IP, &ret);
+  return ret;
+}
+
+/* Overwrite the return address for CONTEXT with VAL.  */
+
+inline void
+_Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
+{
+  unw_set_reg (&context->cursor, UNW_REG_IP, val);
+}
+
+void *
+_Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
+{
+  unw_word_t ret;
+
+  unw_get_reg (&context->cursor, UNW_REG_LSDA, &ret);
+  return (void *) ret;
+}
+
+_Unwind_Ptr
+_Unwind_GetRegionStart (struct _Unwind_Context *context)
+{
+  unw_word_t ret;
+
+  unw_get_reg (&context->cursor, UNW_REG_PROC_START, &ret);
+  return (_Unwind_Ptr) ret;
+}
+
+#include "unwind.inc"
+
+#endif /* !__USING_SJLJ_EXCEPTIONS__ */
Index: config/t-libunwind
===================================================================
RCS file: config/t-libunwind
diff -N config/t-libunwind
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ config/t-libunwind	3 Oct 2002 04:53:21 -0000
@@ -0,0 +1 @@
+LIB2ADDEH = $(srcdir)/unwind-libunwind.c $(srcdir)/unwind-sjlj.c


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