diff mbox

arm: mark __startcontext as .cantunwind

Message ID mvmtwemqkbi.fsf@hawking.suse.de
State New
Headers show

Commit Message

Andreas Schwab Aug. 15, 2016, 12:37 p.m. UTC
__startcontext marks the bottom of the call stack of the contexts created
by makecontext.

	[BZ #20435]
	* sysdeps/unix/sysv/linux/arm/setcontext.S (__startcontext): Mark
	as .cantunwind.
---
 sysdeps/unix/sysv/linux/arm/setcontext.S | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Florian Weimer Aug. 15, 2016, 12:45 p.m. UTC | #1
On 08/15/2016 02:37 PM, Andreas Schwab wrote:
> __startcontext marks the bottom of the call stack of the contexts created
> by makecontext.
>
> 	[BZ #20435]
> 	* sysdeps/unix/sysv/linux/arm/setcontext.S (__startcontext): Mark
> 	as .cantunwind.
> ---
>  sysdeps/unix/sysv/linux/arm/setcontext.S | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/sysdeps/unix/sysv/linux/arm/setcontext.S b/sysdeps/unix/sysv/linux/arm/setcontext.S
> index 603e508..d1f168f 100644
> --- a/sysdeps/unix/sysv/linux/arm/setcontext.S
> +++ b/sysdeps/unix/sysv/linux/arm/setcontext.S
> @@ -86,12 +86,19 @@ weak_alias(__setcontext, setcontext)
>
>  	/* Called when a makecontext() context returns.  Start the
>  	   context in R4 or fall through to exit().  */
> +	/* Unwind descriptors are looked up based on PC - 2, so we have to
> +	   make sure to mark the instruction preceding the __startcontext
> +	   label as .cantunwind.  */
> +	.fnstart
> +	.cantunwind
> +	nop

Why isn't the PC - 2 kludge needed for the other .cantunwind cases?

Would it be possible to add a C test case to the glibc testsuite?

Thanks,
Florian
Andreas Schwab Aug. 15, 2016, 1:02 p.m. UTC | #2
On Aug 15 2016, Florian Weimer <fweimer@redhat.com> wrote:

> Why isn't the PC - 2 kludge needed for the other .cantunwind cases?

Because the other uses have regular function calls, so they return back
to the middle of the function that is marked cantunwind.  __startcontext
doesn't contain the function call, but is the address the context
returns to.

> Would it be possible to add a C test case to the glibc testsuite?

This is difficult, because a simple call stack won't trigger the bug.

Andreas.
Florian Weimer Aug. 15, 2016, 2:25 p.m. UTC | #3
On 08/15/2016 03:02 PM, Andreas Schwab wrote:
> On Aug 15 2016, Florian Weimer <fweimer@redhat.com> wrote:
>
>> Why isn't the PC - 2 kludge needed for the other .cantunwind cases?
>
> Because the other uses have regular function calls, so they return back
> to the middle of the function that is marked cantunwind.  __startcontext
> doesn't contain the function call, but is the address the context
> returns to.
>
>> Would it be possible to add a C test case to the glibc testsuite?
>
> This is difficult, because a simple call stack won't trigger the bug.

Thanks for the explanation.  Your patch looks okay to me.

Florian
diff mbox

Patch

diff --git a/sysdeps/unix/sysv/linux/arm/setcontext.S b/sysdeps/unix/sysv/linux/arm/setcontext.S
index 603e508..d1f168f 100644
--- a/sysdeps/unix/sysv/linux/arm/setcontext.S
+++ b/sysdeps/unix/sysv/linux/arm/setcontext.S
@@ -86,12 +86,19 @@  weak_alias(__setcontext, setcontext)
 
 	/* Called when a makecontext() context returns.  Start the
 	   context in R4 or fall through to exit().  */
+	/* Unwind descriptors are looked up based on PC - 2, so we have to
+	   make sure to mark the instruction preceding the __startcontext
+	   label as .cantunwind.  */
+	.fnstart
+	.cantunwind
+	nop
 ENTRY(__startcontext)
 	movs    r0, r4
 	bne     PLTJMP(__setcontext)
 
 	@ New context was 0 - exit
 	b       PLTJMP(HIDDEN_JUMPTARGET(exit))
+	.fnend
 END(__startcontext)
 
 #ifdef PIC