Skip to content

Commit

Permalink
libgc: use __builtin_frame_address in GC_approx_sp
Browse files Browse the repository at this point in the history
With GCC 5.x, the compiler optimises away the dummy load used to
estimate the stack pointer address in GC_approx_sp; it returns
zero. This leads to segfaults when embedding Mono.

Instead, use __builtin_frame_address, which GCC's libgc uses for
the same purpose.
  • Loading branch information
James Laird-Wah committed Feb 7, 2016
1 parent a1d805a commit cd293cc
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions libgc/mark_rts.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,25 +368,22 @@ ptr_t p;

ptr_t GC_approx_sp()
{
#if defined(__GNUC__)
return __builtin_frame_address(0);
#else
VOLATILE word dummy;

dummy = 42; /* Force stack to grow if necessary. Otherwise the */
/* later accesses might cause the kernel to think we're */
/* doing something wrong. */
# ifdef _MSC_VER
# pragma warning(disable:4172)
# endif
# if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 408)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wreturn-local-addr"
# endif
return((ptr_t)(&dummy));
# if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 408)
# pragma GCC diagnostic pop
# endif
# ifdef _MSC_VER
# pragma warning(default:4172)
# endif
#endif // __GNUC__
}

/*
Expand Down

0 comments on commit cd293cc

Please sign in to comment.