mailing list of musl libc
 help / color / mirror / code / Atom feed
* _Unwind_Backtrace crashes
@ 2015-08-27 18:55 Andy Lutomirski
  2015-08-27 19:14 ` Rich Felker
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andy Lutomirski @ 2015-08-27 18:55 UTC (permalink / raw)
  To: musl

This works on glibc.  It aborts on musl on i386 using the latest git version.

I suspect it's because whatever calls main isn't properly annotated,
but I don't know how to debug this without rebuilding gcc, which is
kind of a mess.

#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unwind.h>
#include <err.h>
#include <string.h>

static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
               int flags)
{
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_sigaction = handler;
    sa.sa_flags = SA_SIGINFO | flags;
    sigemptyset(&sa.sa_mask);
    if (sigaction(sig, &sa, 0))
        err(1, "sigaction");
}

_Unwind_Reason_Code trace_fn(struct _Unwind_Context * ctx, void *opaque)
{
    return _URC_NO_REASON;
}

static void sigusr1(int sig, siginfo_t *info, void *ctx_void)
{
    printf("In signal handler.  Trying to unwind.\n");
    _Unwind_Backtrace(trace_fn, 0);
}

int main()
{
    printf("Unwind directly\n");
    _Unwind_Backtrace(trace_fn, 0);

    printf("Unwind from signal handler\n");
    sethandler(SIGUSR1, sigusr1, 0);
    raise(SIGUSR1);

    printf("OK\n");
}


-- 
Andy Lutomirski
AMA Capital Management, LLC


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: _Unwind_Backtrace crashes
  2015-08-27 18:55 _Unwind_Backtrace crashes Andy Lutomirski
@ 2015-08-27 19:14 ` Rich Felker
  2015-08-27 20:00 ` Szabolcs Nagy
  2015-08-28 13:21 ` Alexander Monakov
  2 siblings, 0 replies; 6+ messages in thread
From: Rich Felker @ 2015-08-27 19:14 UTC (permalink / raw)
  To: musl

On Thu, Aug 27, 2015 at 11:55:24AM -0700, Andy Lutomirski wrote:
> This works on glibc.  It aborts on musl on i386 using the latest git version.
> 
> I suspect it's because whatever calls main isn't properly annotated,
> but I don't know how to debug this without rebuilding gcc, which is
> kind of a mess.

I can't reproduce the crash. The program runs and produces the output:

Unwind directly
Unwind from signal handler
In signal handler.  Trying to unwind.
OK

I tried pre-CFI-patch and post-CFI-patch musl git, static and dynamic
linking. Perhaps it's GCC version-specific? I'm using 4.7.3 on my i386
system.

Rich


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: _Unwind_Backtrace crashes
  2015-08-27 18:55 _Unwind_Backtrace crashes Andy Lutomirski
  2015-08-27 19:14 ` Rich Felker
@ 2015-08-27 20:00 ` Szabolcs Nagy
  2015-08-28 13:21 ` Alexander Monakov
  2 siblings, 0 replies; 6+ messages in thread
From: Szabolcs Nagy @ 2015-08-27 20:00 UTC (permalink / raw)
  To: musl

* Andy Lutomirski <luto@amacapital.net> [2015-08-27 11:55:24 -0700]:
> This works on glibc.  It aborts on musl on i386 using the latest git version.
> 
> I suspect it's because whatever calls main isn't properly annotated,
> but I don't know how to debug this without rebuilding gcc, which is
> kind of a mess.
> 
> #define _GNU_SOURCE
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <signal.h>
> #include <unwind.h>
> #include <err.h>
> #include <string.h>
> 
> static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
>                int flags)
> {
>     struct sigaction sa;
>     memset(&sa, 0, sizeof(sa));
>     sa.sa_sigaction = handler;
>     sa.sa_flags = SA_SIGINFO | flags;
>     sigemptyset(&sa.sa_mask);
>     if (sigaction(sig, &sa, 0))
>         err(1, "sigaction");
> }
> 
> _Unwind_Reason_Code trace_fn(struct _Unwind_Context * ctx, void *opaque)
> {

you might want to add

	dprintf(1, "ip: %16p  cfa: %16p\n", (void*)_Unwind_GetIP(ctx), (void*)_Unwind_GetCFA(ctx));

here, so you see if trace_fn is called at all
(and s/printf/dprintf/g so you see what is printed before the crash)

>     return _URC_NO_REASON;
> }
> 
> static void sigusr1(int sig, siginfo_t *info, void *ctx_void)
> {
>     printf("In signal handler.  Trying to unwind.\n");
>     _Unwind_Backtrace(trace_fn, 0);
> }
> 
> int main()
> {
>     printf("Unwind directly\n");
>     _Unwind_Backtrace(trace_fn, 0);
> 
>     printf("Unwind from signal handler\n");
>     sethandler(SIGUSR1, sigusr1, 0);
>     raise(SIGUSR1);
> 
>     printf("OK\n");
> }
> 
> 
> -- 
> Andy Lutomirski
> AMA Capital Management, LLC


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: _Unwind_Backtrace crashes
  2015-08-27 18:55 _Unwind_Backtrace crashes Andy Lutomirski
  2015-08-27 19:14 ` Rich Felker
  2015-08-27 20:00 ` Szabolcs Nagy
@ 2015-08-28 13:21 ` Alexander Monakov
  2015-08-28 14:16   ` Szabolcs Nagy
  2 siblings, 1 reply; 6+ messages in thread
From: Alexander Monakov @ 2015-08-28 13:21 UTC (permalink / raw)
  To: musl

I was able to reproduce this using the musl-gcc wrapper on a glibc-based
system.  I tracked it down to dl_iterate_phdr callback in libgcc failing to
find PT_GNU_EH_FRAME header in this loop:

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/unwind-dw2-fde-dip.c;h=137dced8d558b9f786d935c8e4ab73200fb6409d;hb=HEAD#l267

And indeed adding -Wl,--eh-frame-hdr to the musl-gcc command line fixes it.

Normally this ld option is present in built-in specs, but musl-gcc's specs
don't set it.

Alexander



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: _Unwind_Backtrace crashes
  2015-08-28 13:21 ` Alexander Monakov
@ 2015-08-28 14:16   ` Szabolcs Nagy
  2015-08-28 14:46     ` Alexander Monakov
  0 siblings, 1 reply; 6+ messages in thread
From: Szabolcs Nagy @ 2015-08-28 14:16 UTC (permalink / raw)
  To: musl

* Alexander Monakov <amonakov@ispras.ru> [2015-08-28 16:21:08 +0300]:
> I was able to reproduce this using the musl-gcc wrapper on a glibc-based
> system.  I tracked it down to dl_iterate_phdr callback in libgcc failing to
> find PT_GNU_EH_FRAME header in this loop:
> 
> https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/unwind-dw2-fde-dip.c;h=137dced8d558b9f786d935c8e4ab73200fb6409d;hb=HEAD#l267
> 
> And indeed adding -Wl,--eh-frame-hdr to the musl-gcc command line fixes it.
> 

here the test works even without .eh_frame_hdr with gcc-5.1 (alpine, musl based toolchain).

but i see the same failure with gcc-4.9.2 (debian, glibc based) and then --eh-frame-hdr fixes it.

> Normally this ld option is present in built-in specs, but musl-gcc's specs
> don't set it.
> 
> Alexander


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: _Unwind_Backtrace crashes
  2015-08-28 14:16   ` Szabolcs Nagy
@ 2015-08-28 14:46     ` Alexander Monakov
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Monakov @ 2015-08-28 14:46 UTC (permalink / raw)
  To: musl



On Fri, 28 Aug 2015, Szabolcs Nagy wrote:

> * Alexander Monakov <amonakov@ispras.ru> [2015-08-28 16:21:08 +0300]:
> > I was able to reproduce this using the musl-gcc wrapper on a glibc-based
> > system.  I tracked it down to dl_iterate_phdr callback in libgcc failing to
> > find PT_GNU_EH_FRAME header in this loop:
> > 
> > https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/unwind-dw2-fde-dip.c;h=137dced8d558b9f786d935c8e4ab73200fb6409d;hb=HEAD#l267
> > 
> > And indeed adding -Wl,--eh-frame-hdr to the musl-gcc command line fixes it.
> > 
> 
> here the test works even without .eh_frame_hdr with gcc-5.1 (alpine, musl based toolchain).

You probably need -static-libgcc together with absence of .eh_frame_hdr to
trigger the crash.

Alexander


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-08-28 14:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-27 18:55 _Unwind_Backtrace crashes Andy Lutomirski
2015-08-27 19:14 ` Rich Felker
2015-08-27 20:00 ` Szabolcs Nagy
2015-08-28 13:21 ` Alexander Monakov
2015-08-28 14:16   ` Szabolcs Nagy
2015-08-28 14:46     ` Alexander Monakov

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).