[llvm-commits] [llvm-gcc-4.2] r123110 - in /llvm-gcc-4.2/trunk/gcc/config/arm: libunwind.S unwind-arm.c unwind-arm.h

Anton Korobeynikov asl at math.spbu.ru
Sun Jan 9 01:40:11 PST 2011


Author: asl
Date: Sun Jan  9 03:40:11 2011
New Revision: 123110

URL: http://llvm.org/viewvc/llvm-project?rev=123110&view=rev
Log:
Backport the implementation of _Unwind_Backtrace from mainline gcc
(GPLv2 variant). This allows ARM binaries to be statically linked
with glibc built via CodeSourcery toolchain.

Modified:
    llvm-gcc-4.2/trunk/gcc/config/arm/libunwind.S
    llvm-gcc-4.2/trunk/gcc/config/arm/unwind-arm.c
    llvm-gcc-4.2/trunk/gcc/config/arm/unwind-arm.h

Modified: llvm-gcc-4.2/trunk/gcc/config/arm/libunwind.S
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/arm/libunwind.S?rev=123110&r1=123109&r2=123110&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/arm/libunwind.S (original)
+++ llvm-gcc-4.2/trunk/gcc/config/arm/libunwind.S Sun Jan  9 03:40:11 2011
@@ -248,5 +248,7 @@
 UNWIND_WRAPPER _Unwind_Resume 1
 UNWIND_WRAPPER _Unwind_Resume_or_Rethrow 1
 UNWIND_WRAPPER _Unwind_ForcedUnwind 3
+/* LLVM LOCAL mainline */
+UNWIND_WRAPPER _Unwind_Backtrace 2
 
 #endif  /* __symbian__ */

Modified: llvm-gcc-4.2/trunk/gcc/config/arm/unwind-arm.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/arm/unwind-arm.c?rev=123110&r1=123109&r2=123110&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/arm/unwind-arm.c (original)
+++ llvm-gcc-4.2/trunk/gcc/config/arm/unwind-arm.c Sun Jan  9 03:40:11 2011
@@ -975,6 +975,68 @@
 }
 
 
+/* LLVM LOCAL begin mainline */
+/* Perform stack backtrace through unwind data.  */
+_Unwind_Reason_Code
+__gnu_Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument,
+		       phase2_vrs * entry_vrs);
+_Unwind_Reason_Code
+__gnu_Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument,
+		       phase2_vrs * entry_vrs)
+{
+  phase1_vrs saved_vrs;
+  _Unwind_Reason_Code code;
+
+  _Unwind_Control_Block ucb;
+  _Unwind_Control_Block *ucbp = &ucb;
+
+  /* Set the pc to the call site.  */
+  entry_vrs->core.r[R_PC] = entry_vrs->core.r[R_LR];
+
+  /* Save the core registers.  */
+  saved_vrs.core = entry_vrs->core;
+  /* Set demand-save flags.  */
+  saved_vrs.demand_save_flags = ~(_uw) 0;
+  
+  do
+    {
+      /* Find the entry for this routine.  */
+      if (get_eit_entry (ucbp, saved_vrs.core.r[R_PC]) != _URC_OK)
+	{
+	  code = _URC_FAILURE;
+	  break;
+	}
+
+      /* 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.  */
+      _Unwind_SetGR((_Unwind_Context *)&saved_vrs, 12, (_Unwind_Ptr) ucbp);
+
+      /* Call trace function.  */
+      if ((*trace) ((_Unwind_Context *) &saved_vrs, trace_argument) 
+	  != _URC_NO_REASON)
+	{
+	  code = _URC_FAILURE;
+	  break;
+	}
+
+      /* Call the pr to decide what to do.  */
+      code = ((personality_routine) UCB_PR_ADDR (ucbp))
+	(_US_VIRTUAL_UNWIND_FRAME | _US_FORCE_UNWIND, 
+	 ucbp, (void *) &saved_vrs);
+    }
+  while (code != _URC_END_OF_STACK
+	 && code != _URC_FAILURE);
+
+ finish:
+  restore_non_core_regs (&saved_vrs);
+  return code;
+}
+/* LLVM LOCAL end mainline */
+
+
 /* Common implementation for ARM ABI defined personality routines.
    ID is the index of the personality routine, other arguments are as defined
    by __aeabi_unwind_cpp_pr{0,1,2}.  */

Modified: llvm-gcc-4.2/trunk/gcc/config/arm/unwind-arm.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/arm/unwind-arm.h?rev=123110&r1=123109&r2=123110&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/arm/unwind-arm.h (original)
+++ llvm-gcc-4.2/trunk/gcc/config/arm/unwind-arm.h Sun Jan  9 03:40:11 2011
@@ -205,6 +205,14 @@
 	_Unwind_Control_Block *, struct _Unwind_Context *, void *);
   _Unwind_Reason_Code _Unwind_ForcedUnwind (_Unwind_Control_Block *,
 					    _Unwind_Stop_Fn, void *);
+  /* LLVM LOCAL begin mainline */
+  /* @@@ Use unwind data to perform a stack backtrace.  The trace callback
+     is called for every stack frame in the call chain, but no cleanup
+     actions are performed.  */
+  typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (_Unwind_Context *, void *);
+  _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn,
+					void*);
+/* LLVM LOCAL end mainline */
   _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
   void _Unwind_Complete(_Unwind_Control_Block *ucbp);
   void _Unwind_DeleteException (_Unwind_Exception *);





More information about the llvm-commits mailing list