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]

Re: RFA: Use _Unwind_Ptr (Was: Re: RFC / RFA: dwarf2 unwinding for targets with call-part-clobbered registers)


I'm corrently testing this patch i686-pc-linux-gnu X sh64-elf and
i686-pc-linux-gnu native, together with the
expand_builtin_init_dwarf_reg_sizes and assorted sh target patches.

2003-07-10  J"orn Rennecke <joern.rennecke@superh.com>

	* unwind-dw2.c (_Unwind_GetGR): Use dwarf_reg_size_table
	to decide if to access a _Unwind_Ptr or a _Unwind_Word.
	(_Unwind_SetGR): Likewise.
	(_Unwind_GetPtr, _Unwind_SetSpColumn): New functions.
	(Unwind_SpTmp): New typedef.
	(uw_update_context_1): Use _Unwind_SetSpColumn and _Unwind_GetPtr.
	(uw_update_context): Use _Unwind_GetPtr.
	(init_dwarf_reg_size_table): Move above uw_init_context_1.
	(uw_init_context_1): Initialize dwarf_reg_size_table if necessary.
	Use _Unwind_SetSpColumn.
	(uw_install_context_1): Don't initialize dwarf_reg_size_table.
	Use _Unwind_GetPtr.

Index: unwind-dw2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/unwind-dw2.c,v
retrieving revision 1.32
diff -p -r1.32 unwind-dw2.c
*** unwind-dw2.c	13 May 2003 06:49:46 -0000	1.32
--- unwind-dw2.c	10 Jul 2003 19:36:33 -0000
*************** read_8s (const void *p) { const union un
*** 168,176 ****
  inline _Unwind_Word
  _Unwind_GetGR (struct _Unwind_Context *context, int index)
  {
    index = DWARF_REG_TO_UNWIND_COLUMN (index);
    /* This will segfault if the register hasn't been saved.  */
!   return * (_Unwind_Word *) context->reg[index];
  }
  
  /* Get the value of the CFA as saved in CONTEXT.  */
--- 168,194 ----
  inline _Unwind_Word
  _Unwind_GetGR (struct _Unwind_Context *context, int index)
  {
+   int size;
+   void *ptr;
+ 
    index = DWARF_REG_TO_UNWIND_COLUMN (index);
+   size = dwarf_reg_size_table[index];
+   ptr = context->reg[index];
+ 
    /* This will segfault if the register hasn't been saved.  */
!   if (size == sizeof(_Unwind_Ptr))
!     return * (_Unwind_Ptr *) ptr;
! 
!   if (size == sizeof(_Unwind_Word))
!     return * (_Unwind_Word *) ptr;
! 
!   abort ();
! }
! 
! static inline void *
! _Unwind_GetPtr (struct _Unwind_Context *context, int index)
! {
!   return (void *)(_Unwind_Ptr) _Unwind_GetGR (context, index);
  }
  
  /* Get the value of the CFA as saved in CONTEXT.  */
*************** _Unwind_GetCFA (struct _Unwind_Context *
*** 186,193 ****
  inline void
  _Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
  {
    index = DWARF_REG_TO_UNWIND_COLUMN (index);
!   * (_Unwind_Word *) context->reg[index] = val;
  }
  
  /* Get the pointer to a register INDEX as saved in CONTEXT.  */
--- 204,222 ----
  inline void
  _Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
  {
+   int size;
+   void *ptr;
+ 
    index = DWARF_REG_TO_UNWIND_COLUMN (index);
!   size = dwarf_reg_size_table[index];
!   ptr = context->reg[index];
! 
!   if (size == sizeof(_Unwind_Ptr))
!     * (_Unwind_Ptr *) ptr = val;
!   else if (size == sizeof(_Unwind_Word))
!     * (_Unwind_Word *) ptr = val;
!   else
!     abort ();
  }
  
  /* Get the pointer to a register INDEX as saved in CONTEXT.  */
*************** __frame_state_for (void *pc_target, stru
*** 1072,1077 ****
--- 1101,1123 ----
    return state_in;
  }
  
+ typedef union { _Unwind_Ptr ptr; _Unwind_Word word; } _Unwind_SpTmp;
+ 
+ static inline void
+ _Unwind_SetSpColumn (struct _Unwind_Context *context, void *cfa,
+                      _Unwind_SpTmp *tmp_sp)
+ {
+   int size = dwarf_reg_size_table[__builtin_dwarf_sp_column ()];
+   
+   if (size == sizeof(_Unwind_Ptr))
+     tmp_sp->ptr = (_Unwind_Ptr) cfa;
+   else if (size == sizeof(_Unwind_Word))
+     tmp_sp->word = (_Unwind_Ptr) cfa;
+   else
+     abort ();
+   _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), tmp_sp);
+ }
+ 
  static void
  uw_update_context_1 (struct _Unwind_Context *context, _Unwind_FrameState *fs)
  {
*************** uw_update_context_1 (struct _Unwind_Cont
*** 1095,1107 ****
       Always zap the saved stack pointer value for the next frame; carrying
       the value over from one frame to another doesn't make sense.  */
  
!   _Unwind_Word tmp_sp;
  
    if (!_Unwind_GetGRPtr (&orig_context, __builtin_dwarf_sp_column ()))
!     {
!       tmp_sp = (_Unwind_Ptr) context->cfa;
!       _Unwind_SetGRPtr (&orig_context, __builtin_dwarf_sp_column (), &tmp_sp);
!     }
    _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), NULL);
  #endif
  
--- 1141,1150 ----
       Always zap the saved stack pointer value for the next frame; carrying
       the value over from one frame to another doesn't make sense.  */
  
!   _Unwind_SpTmp tmp_sp;
  
    if (!_Unwind_GetGRPtr (&orig_context, __builtin_dwarf_sp_column ()))
!     _Unwind_SetSpColumn (&orig_context, context->cfa, &tmp_sp);
    _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), NULL);
  #endif
  
*************** uw_update_context_1 (struct _Unwind_Cont
*** 1109,1115 ****
    switch (fs->cfa_how)
      {
      case CFA_REG_OFFSET:
!       cfa = (void *) (_Unwind_Ptr) _Unwind_GetGR (&orig_context, fs->cfa_reg);
        cfa += fs->cfa_offset;
        break;
  
--- 1152,1158 ----
    switch (fs->cfa_how)
      {
      case CFA_REG_OFFSET:
!       cfa = _Unwind_GetPtr (&orig_context, fs->cfa_reg);
        cfa += fs->cfa_offset;
        break;
  
*************** uw_update_context (struct _Unwind_Contex
*** 1175,1181 ****
    /* Compute the return address now, since the return address column
       can change from frame to frame.  */
    context->ra = __builtin_extract_return_addr
!     ((void *) (_Unwind_Ptr) _Unwind_GetGR (context, fs->retaddr_column));
  }
  
  /* Fill in CONTEXT for top-of-stack.  The only valid registers at this
--- 1218,1224 ----
    /* Compute the return address now, since the return address column
       can change from frame to frame.  */
    context->ra = __builtin_extract_return_addr
!     (_Unwind_GetPtr (context, fs->retaddr_column));
  }
  
  /* Fill in CONTEXT for top-of-stack.  The only valid registers at this
*************** uw_update_context (struct _Unwind_Contex
*** 1192,1204 ****
      }									   \
    while (0)
  
  static void
  uw_init_context_1 (struct _Unwind_Context *context,
  		   void *outer_cfa, void *outer_ra)
  {
    void *ra = __builtin_extract_return_addr (__builtin_return_address (0));
    _Unwind_FrameState fs;
!   _Unwind_Word sp_slot;
  
    memset (context, 0, sizeof (struct _Unwind_Context));
    context->ra = ra;
--- 1235,1253 ----
      }									   \
    while (0)
  
+ static inline void
+ init_dwarf_reg_size_table (void)
+ {
+   __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table);
+ }
+ 
  static void
  uw_init_context_1 (struct _Unwind_Context *context,
  		   void *outer_cfa, void *outer_ra)
  {
    void *ra = __builtin_extract_return_addr (__builtin_return_address (0));
    _Unwind_FrameState fs;
!   _Unwind_SpTmp sp_slot;
  
    memset (context, 0, sizeof (struct _Unwind_Context));
    context->ra = ra;
*************** uw_init_context_1 (struct _Unwind_Contex
*** 1206,1214 ****
    if (uw_frame_state_for (context, &fs) != _URC_NO_REASON)
      abort ();
  
    /* Force the frame state to use the known cfa value.  */
!   sp_slot = (_Unwind_Ptr) outer_cfa;
!   _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), &sp_slot);
    fs.cfa_how = CFA_REG_OFFSET;
    fs.cfa_reg = __builtin_dwarf_sp_column ();
    fs.cfa_offset = 0;
--- 1255,1274 ----
    if (uw_frame_state_for (context, &fs) != _URC_NO_REASON)
      abort ();
  
+ #if __GTHREADS
+   {
+     static __gthread_once_t once_regsizes = __GTHREAD_ONCE_INIT;
+     if (__gthread_once (&once_regsizes, init_dwarf_reg_size_table) != 0
+ 	|| dwarf_reg_size_table[0] == 0)
+       init_dwarf_reg_size_table ();
+   }
+ #else
+   if (dwarf_reg_size_table[0] == 0)
+     init_dwarf_reg_size_table ();
+ #endif
+ 
    /* Force the frame state to use the known cfa value.  */
!   _Unwind_SetSpColumn (context, outer_cfa, &sp_slot);
    fs.cfa_how = CFA_REG_OFFSET;
    fs.cfa_reg = __builtin_dwarf_sp_column ();
    fs.cfa_offset = 0;
*************** uw_init_context_1 (struct _Unwind_Contex
*** 1235,1264 ****
      }									 \
    while (0)
  
- static inline void
- init_dwarf_reg_size_table (void)
- {
-   __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table);
- }
- 
  static long
  uw_install_context_1 (struct _Unwind_Context *current,
  		      struct _Unwind_Context *target)
  {
    long i;
  
- #if __GTHREADS
-   {
-     static __gthread_once_t once_regsizes = __GTHREAD_ONCE_INIT;
-     if (__gthread_once (&once_regsizes, init_dwarf_reg_size_table) != 0
- 	|| dwarf_reg_size_table[0] == 0)
-       init_dwarf_reg_size_table ();
-   }
- #else
-   if (dwarf_reg_size_table[0] == 0)
-     init_dwarf_reg_size_table ();
- #endif
- 
    for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
      {
        void *c = current->reg[i];
--- 1295,1306 ----
*************** uw_install_context_1 (struct _Unwind_Con
*** 1274,1281 ****
  
      /* If the last frame records a saved stack pointer, use it.  */
      if (_Unwind_GetGRPtr (target, __builtin_dwarf_sp_column ()))
!       target_cfa = (void *)(_Unwind_Ptr)
!         _Unwind_GetGR (target, __builtin_dwarf_sp_column ());
      else
        target_cfa = target->cfa;
  
--- 1316,1322 ----
  
      /* If the last frame records a saved stack pointer, use it.  */
      if (_Unwind_GetGRPtr (target, __builtin_dwarf_sp_column ()))
!       target_cfa = _Unwind_GetPtr (target, __builtin_dwarf_sp_column ());
      else
        target_cfa = target->cfa;
  


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