Browse Source

xtensa: fix stack unwinding over __default_sa_restorer

For some xtensa cores generated code gets arranged so that
__default_sa_restorer immediately follows preceding function. E.g.:

   40a1b:       c03340          sub     a3, a3, a4
   40a1e:       f01d            retw.n

00040a20 <__default_sa_restorer>:
   40a20:       e1a022          movi    a2, 225
   40a23:       005000          syscall

...
Contents of the .eh_frame section:
...
000007f4 00000014 000007f8 FDE cie=00000000 pc=0004076c..00040a20
  DW_CFA_advance_loc4: 3 to 0004076f
  DW_CFA_def_cfa_offset: 48

Due to the way xtensa libgcc uw_frame_state_for calls _Unwind_Find_FDE
for non-signal frames, FDE for the previous function is found during
thread cancellation signal stack unwinding in that case. Signal stack
frame is not recognized and is not unwound properly, breaking cleanup
routines calling for cancelled thread.

Insert padding before the __default_sa_restorer so that no FDE is found
for it, MD_FALLBACK_FRAME_STATE_FOR is called by uw_frame_state_for and
the frame is correctly recognized as signal frame.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Max Filippov 8 years ago
parent
commit
c8d441345f
1 changed files with 6 additions and 0 deletions
  1. 6 0
      libc/sysdeps/linux/xtensa/sigrestorer.S

+ 6 - 0
libc/sysdeps/linux/xtensa/sigrestorer.S

@@ -11,6 +11,12 @@
 #endif
 
 	.text
+	/* This space separates __default_sa_restorer from the previous
+	 * function, so that its corresponding FDE is not mistakenly found
+	 * by the libgcc stack unwinder. This is important for correct signal
+	 * stack unwinding.
+	 */
+	.space	1
 	.align	4
 	.global	__default_sa_restorer
 	.type	__default_sa_restorer, @function