Patchwork sparc32: Add nop before __startcontext to stop unwinding [BZ #xxxxx]

login
register
mail settings
Submitter Aurelien Jarno
Date March 3, 2018, 9:10 a.m.
Message ID <20180303091018.32019-1-aurelien@aurel32.net>
Download mbox | patch
Permalink /patch/26171/
State New
Headers show

Comments

Aurelien Jarno - March 3, 2018, 9:10 a.m.
On sparc32 tst-makecontext fails, as backtrace called within a context
created by makecontext to yield infinite backtrace.

Fix that the same way than nios2 by adding a nop just before
__startcontext. This is needed as otherwise FDE lookup just repeatedly
finds __setcontext's FDE in an infinite loop, due to the convention of
using 'address - 1' for FDE lookup.

Changelog:
	[BZ #22919]
	* sysdeps/unix/sysv/linux/sparc/sparc32/setcontext.S (__startcontext):
	Add nop before __startcontext, add explaining comments.
---
 ChangeLog                                          |  6 ++++++
 sysdeps/unix/sysv/linux/sparc/sparc32/setcontext.S | 13 +++++++++++++
 2 files changed, 19 insertions(+)
David Miller - March 7, 2018, 3:32 p.m.
From: Aurelien Jarno <aurelien@aurel32.net>
Date: Sat,  3 Mar 2018 10:10:18 +0100

> On sparc32 tst-makecontext fails, as backtrace called within a context
> created by makecontext to yield infinite backtrace.
> 
> Fix that the same way than nios2 by adding a nop just before
> __startcontext. This is needed as otherwise FDE lookup just repeatedly
> finds __setcontext's FDE in an infinite loop, due to the convention of
> using 'address - 1' for FDE lookup.
> 
> Changelog:
> 	[BZ #22919]
> 	* sysdeps/unix/sysv/linux/sparc/sparc32/setcontext.S (__startcontext):
> 	Add nop before __startcontext, add explaining comments.

Yeah this stuff is really tricky, thanks for fixing this.

Patch

diff --git a/ChangeLog b/ChangeLog
index 4b7e0a0261..6216817498 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@ 
+2018-03-03  Aurelien Jarno  <aurelien@aurel32.net>
+
+	[BZ #22919]
+	* sysdeps/unix/sysv/linux/sparc/sparc32/setcontext.S (__startcontext):
+	Add nop before __startcontext, add explaining comments.
+
 2018-03-01  Maciej W. Rozycki  <macro@mips.com>
 
 	* nptl_db/td_ta_thr_iter.c (iterate_thread_list): Remove
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/setcontext.S b/sysdeps/unix/sysv/linux/sparc/sparc32/setcontext.S
index 695f172c63..283aef1b30 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/setcontext.S
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/setcontext.S
@@ -95,6 +95,19 @@  END(__setcontext)
 
 weak_alias (__setcontext, setcontext)
 
+/* We add an NOP here to separate between __setcontext/__startcontext. The
+   wanted behavior that happens is: when unwinding from a function called
+   inside a makecontext() context, FDE lookup will use '&__startcontext - 1',
+   then returns NULL for no FDE found, and immediately ends the unwind, in
+   a normal fashion.
+
+   If this NOP word does not exist, FDE lookup just repeatedly finds
+   __setcontext's FDE in an infinite loop, due to the convention of using
+   'address - 1' for FDE lookup. Modifiying/deleting the below
+   __startcontext's FDE has no help on this.  */
+
+	nop
+
 /* This is the helper code which gets called if a function which is
    registered with 'makecontext' returns.  In this case we have to
    install the context listed in the uc_link element of the context