Patchwork [alpha] : Introduce alpha_frob_update_context

login
register
mail settings
Submitter Uros Bizjak
Date Dec. 19, 2011, 10:14 p.m.
Message ID <CAFULd4YkG-0KJMUZwukyyVoujfap5YCn1BmVRF-ERFLPpjF+7A@mail.gmail.com>
Download mbox | patch
Permalink /patch/132327/
State New
Headers show

Comments

Uros Bizjak - Dec. 19, 2011, 10:14 p.m.
Hello!

This problem was uncovered by a libgo testsuite, where SIGSEGV handler
in html/template test resulted in

Program received signal SIGSEGV, Segmentation fault.
libgo_html.template.Error.pN25_libgo_html.template.Error (e=0x0) at error.go:185
185             if e.Line != 0 {

While x86_64 recovers from the exception, alpha doesn't, resulting in:

(gdb) c
Continuing.

Program received signal SIGILL, Illegal instruction.
0x0000020000b6617c in runtime_m0 () from ./libgo.so.0

The problem was that signal handler in frame 5 wasn't marked as such,
so unwinder assigned FDE of frame #5 to frame #6.

(gdb) bt
#0  _Unwind_RaiseException (exc=0xf840453300) at
../../../gcc-svn/trunk/libgcc/unwind.inc:135
#1  0x0000020000559a8c in __go_unwind_stack () at
../../../gcc-svn/trunk/libgo/runtime/go-unwind.c:175
#2  0x0000020000556d44 in __go_panic (arg=...) at
../../../gcc-svn/trunk/libgo/runtime/go-panic.c:85
#3  0x0000020000564be8 in runtime_panicstring (s=0x200007fb737
"invalid memory address or nil pointer dereference")
    at ../../../gcc-svn/trunk/libgo/runtime/runtime.c:83
#4  0x000002000055875c in sighandler (sig=<optimized out>) at
../../../gcc-svn/trunk/libgo/runtime/go-signal.c:183
#5  0x0000020002c82620 in ?? () from /lib/libc.so.6.1
#6  0x000000012001c85c in
libgo_html.template.Error.pN25_libgo_html.template.Error (e=0x0) at
error.go:184
#7  0x0000020000580cc4 in
libgo_fmt.fmt.handleMethods.pN16_libgo_fmt.fmt.pp (p=0xf840214f00,
verb=<optimized out>, plus=<optimized out>,
    goSyntax=<optimized out>, depth=<optimized out>) at
../../../gcc-svn/trunk/libgo/go/fmt/print.go:648
#8  0x000002000057efc8 in
libgo_fmt.fmt.printField.pN16_libgo_fmt.fmt.pp (p=0xf840214f00,
field=..., verb=<optimized out>,
    plus=<optimized out>, goSyntax=<optimized out>, depth=0) at
../../../gcc-svn/trunk/libgo/go/fmt/print.go:687
#9  0x000002000057fde8 in libgo_fmt.fmt.doPrintf.pN16_libgo_fmt.fmt.pp
(p=0xf840214f00, format=..., a=...)
    at ../../../gcc-svn/trunk/libgo/go/fmt/print.go:1045
#10 0x00000200005811ac in libgo_fmt.fmt.Sprintf (format=..., a=...) at
../../../gcc-svn/trunk/libgo/go/fmt/print.go:194

Attached patch that introduces MD_FROB_UPDATE_CONTEXT fixes this failure.

2011-12-19  Uros Bizjak  <ubizjak@gmail.com>

	* config/alpha/linux-unwind.h: Update copyright years.
	(MD_FROB_UPDATE_CONTEXT): New define.
	(alpha_frob_update_context): New function.

Patch was bootstrapped and regression tested on alphaev68-pc-linux-gnu
with all languages + go.

OK for mainline? What about other release branches?

Uros.
Richard Henderson - Dec. 19, 2011, 10:21 p.m.
On 12/19/2011 02:14 PM, Uros Bizjak wrote:
> (gdb) bt
> #0  _Unwind_RaiseException (exc=0xf840453300) at
> ../../../gcc-svn/trunk/libgcc/unwind.inc:135
> #1  0x0000020000559a8c in __go_unwind_stack () at
> ../../../gcc-svn/trunk/libgo/runtime/go-unwind.c:175
> #2  0x0000020000556d44 in __go_panic (arg=...) at
> ../../../gcc-svn/trunk/libgo/runtime/go-panic.c:85
> #3  0x0000020000564be8 in runtime_panicstring (s=0x200007fb737
> "invalid memory address or nil pointer dereference")
>     at ../../../gcc-svn/trunk/libgo/runtime/runtime.c:83
> #4  0x000002000055875c in sighandler (sig=<optimized out>) at
> ../../../gcc-svn/trunk/libgo/runtime/go-signal.c:183
> #5  0x0000020002c82620 in ?? () from /lib/libc.so.6.1

Note that this is in libc, not a DSO (which the linux alpha kernel never creates).

And how old is your glibc that it doesn't have "S" set in the frame?

Otherwise I suppose the patch is ok with an update to the comment.


r~
Uros Bizjak - Dec. 19, 2011, 10:38 p.m.
On Mon, Dec 19, 2011 at 11:21 PM, Richard Henderson <rth@redhat.com> wrote:
> On 12/19/2011 02:14 PM, Uros Bizjak wrote:
>> (gdb) bt
>> #0  _Unwind_RaiseException (exc=0xf840453300) at
>> ../../../gcc-svn/trunk/libgcc/unwind.inc:135
>> #1  0x0000020000559a8c in __go_unwind_stack () at
>> ../../../gcc-svn/trunk/libgo/runtime/go-unwind.c:175
>> #2  0x0000020000556d44 in __go_panic (arg=...) at
>> ../../../gcc-svn/trunk/libgo/runtime/go-panic.c:85
>> #3  0x0000020000564be8 in runtime_panicstring (s=0x200007fb737
>> "invalid memory address or nil pointer dereference")
>>     at ../../../gcc-svn/trunk/libgo/runtime/runtime.c:83
>> #4  0x000002000055875c in sighandler (sig=<optimized out>) at
>> ../../../gcc-svn/trunk/libgo/runtime/go-signal.c:183
>> #5  0x0000020002c82620 in ?? () from /lib/libc.so.6.1
>
> Note that this is in libc, not a DSO (which the linux alpha kernel never creates).

Indeed...

> And how old is your glibc that it doesn't have "S" set in the frame?

It is 2.13:

GNU C Library stable release version 2.13, by Roland McGrath et al.
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.4.5.
Compiled on a Linux 2.6.39 system on 2011-10-04.
Available extensions:
        C stubs add-on version 2.1.2
        crypt add-on version 2.1 by Michael Glad and others
        Gentoo patchset 8
        GNU Libidn by Simon Josefsson
        Native POSIX Threads Library by Ulrich Drepper et al
        Support for some architectures added on, not maintained in glibc core.
        BIND-8.2.3-T5B
        software FPU emulation by Richard Henderson, Jakub Jelinek and others
libc ABIs: UNIQUE
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

> Otherwise I suppose the patch is ok with an update to the comment.

I guess that something like this would fit:

/* Fix up for signal handlers that don't have S flag set.  */

Thanks,
Uros.

Patch

Index: config/alpha/linux-unwind.h
===================================================================
--- config/alpha/linux-unwind.h	(revision 182430)
+++ config/alpha/linux-unwind.h	(working copy)
@@ -1,5 +1,5 @@ 
 /* DWARF2 EH unwinding support for Alpha Linux.
-   Copyright (C) 2004, 2005, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2009, 2011 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -78,3 +80,20 @@ 
 
   return _URC_NO_REASON;
 }
+
+#define MD_FROB_UPDATE_CONTEXT alpha_frob_update_context
+
+/* Fix up for kernels that have vDSO, but don't have S flag in it.  */
+
+static void
+alpha_frob_update_context (struct _Unwind_Context *context,
+			   _Unwind_FrameState *fs ATTRIBUTE_UNUSED)
+{
+  unsigned int *pc = context->ra;
+
+  if (pc[0] == 0x47fe0410		/* mov $30,$16 */
+      && pc[2] == 0x00000083		/* callsys */
+      && (pc[1] == 0x201f0067		/* lda $0,NR_sigreturn */
+	  || pc[1] == 0x201f015f))	/* lda $0,NR_rt_sigreturn */
+    _Unwind_SetSignalFrame (context, 1);
+}