From cd293cc37ac7a85b139177455a5927bdf3b05119 Mon Sep 17 00:00:00 2001 From: James Laird-Wah Date: Mon, 8 Feb 2016 10:19:53 +1100 Subject: libgc: use __builtin_frame_address in GC_approx_sp 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. --- libgc/mark_rts.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'libgc') diff --git a/libgc/mark_rts.c b/libgc/mark_rts.c index b3e996a29c2..561333ab04d 100644 --- a/libgc/mark_rts.c +++ b/libgc/mark_rts.c @@ -368,6 +368,9 @@ 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 */ @@ -375,18 +378,12 @@ ptr_t GC_approx_sp() /* 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__ } /* -- cgit v1.2.3