Subject: Re: bug#30855: 25.3; temacs fails with bus error during garbage collection

From: Paul Eggert <[email-masked]>
Date: Tue, 20 Mar 2018 09:58:12 -0700

Even with the fix the code assumes that Lisp_Object is aligned at least 
as strictly as void *; this should be verified. Plus, if the alignments 
are the same Emacs can avoid a runtime check each time through the loop, 
which should help branch prediction. I installed the attached into 
master; if it fixes Ulrich's problem I think this should be backported 
to emacs-26. Thanks to Ulrich, Eli, and Andreas for reporting this and 
suggesting the fix.
>From 59abd64e9a448bbc5e375a9238d55074d3c9ba11 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Tue, 20 Mar 2018 09:54:20 -0700
Subject: [PATCH] Port to 32-bit sparc64

Problem reported by Ulrich Mueller; fix suggested by Eli Zaretskii
and Andreas Schwab (Bug#30855).
* src/alloc.c (mark_memory): Call mark_maybe_object only on
pointers that are properly aligned for Lisp_Object.
---
 src/alloc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/alloc.c b/src/alloc.c
index f97b99c0f3..da01173fba 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -4981,7 +4981,11 @@ mark_memory (void *start, void *end)
   for (pp = start; (void *) pp < end; pp += GC_POINTER_ALIGNMENT)
     {
       mark_maybe_pointer (*(void **) pp);
-      mark_maybe_object (*(Lisp_Object *) pp);
+
+      verify (alignof (Lisp_Object) % GC_POINTER_ALIGNMENT == 0);
+      if (alignof (Lisp_Object) == GC_POINTER_ALIGNMENT
+	  || (uintptr_t) pp % alignof (Lisp_Object) == 0)
+	mark_maybe_object (*(Lisp_Object *) pp);
     }
 }
 
-- 
2.14.3