Subject: Re: bug#22065: core dumped during compilation (emacs-25 branch on FreeBSD 9)

From: Paul Eggert <[email-masked]>
Date: Sun, 14 Feb 2016 11:47:57 -0800

Wolfgang Jenkner wrote:
> So, perhaps, the FreeBSD 9 default base cc (a patched gcc 4.2.1) has
> some stack-related optimization bug, even on amd64?

Thanks for the detective work. It inspired me to search GCC bug reports, where I 
found a couple that appear to be directly relevant. The corresponding bug was 
fixed in 2008 but GCC 4.2.1 predates the fix. I installed the attached patch 
into the emacs-25 branch, and I hope it works around the compiler bug with 
stack-allocated Lisp objects on FreeBSD 9. Please give it a try.
diff --git a/src/lisp.h b/src/lisp.h
index af73c4b..8eab38b 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4522,6 +4522,12 @@ extern void *record_xmalloc (size_t) ATTRIBUTE_ALLOC_SIZE ((1));
    This feature is experimental and requires careful debugging.
    Build with CPPFLAGS='-DUSE_STACK_LISP_OBJECTS=0' to disable it.  */
 
+#if (!defined USE_STACK_LISP_OBJECTS \
+     && defined __GNUC__ && !defined __clang__ \
+     && !(4 < __GNUC__ + (3 < __GNUC_MINOR__ + (2 <= __GNUC_PATCHLEVEL__))))
+  /* Work around GCC bugs 36584 and 35271, which were fixed in GCC 4.3.2.  */
+# define USE_STACK_LISP_OBJECTS false
+#endif
 #ifndef USE_STACK_LISP_OBJECTS
 # define USE_STACK_LISP_OBJECTS true
 #endif