On Mon, Jan 23, 2017 at 10:15 AM, Ian Lance Taylor <i...@golang.org> wrote:
> I committed a patch to the Go frontend and libgo to fix alignment
> issues on m68k.  This fixes PR 79037.  Bootstrapped and ran Go tests
> on x86_64-pc-linux-gnu.  Tested by John Paul Adrian Glaubitz on
> m68k-linux-gnu.  Committed to mainline.

Now also committed to GCC 6 branch, as follows.

Ian
Index: gcc/go/gofrontend/types.cc
===================================================================
--- gcc/go/gofrontend/types.cc  (revision 245107)
+++ gcc/go/gofrontend/types.cc  (working copy)
@@ -2175,11 +2175,26 @@
       is_common = true;
     }
 
+  // The current garbage collector requires that the GC symbol be
+  // aligned to at least a four byte boundary.  See the use of PRECISE
+  // and LOOP in libgo/runtime/mgc0.c.
+  int64_t align;
+  if (!sym_init->type()->backend_type_align(gogo, &align))
+    go_assert(saw_errors());
+  if (align < 4)
+    align = 4;
+  else
+    {
+      // Use default alignment.
+      align = 0;
+    }
+
   // Since we are building the GC symbol in this package, we must create the
   // variable before converting the initializer to its backend representation
   // because the initializer may refer to the GC symbol for this type.
   this->gc_symbol_var_ =
-    gogo->backend()->implicit_variable(sym_name, sym_btype, false, true, 
is_common, 0);
+    gogo->backend()->implicit_variable(sym_name, sym_btype, false, true,
+                                       is_common, align);
   if (phash != NULL)
     *phash = this->gc_symbol_var_;
 
Index: libgo/runtime/go-unsafe-pointer.c
===================================================================
--- libgo/runtime/go-unsafe-pointer.c   (revision 245107)
+++ libgo/runtime/go-unsafe-pointer.c   (working copy)
@@ -36,7 +36,8 @@
   sizeof REFLECTION - 1
 };
 
-const uintptr unsafe_Pointer_gc[] = {sizeof(void*), GC_APTR, 0, GC_END};
+const uintptr unsafe_Pointer_gc[] __attribute__((aligned(4))) =
+  {sizeof(void*), GC_APTR, 0, GC_END};
 
 const struct __go_type_descriptor unsafe_Pointer =
 {
Index: libgo/runtime/parfor.c
===================================================================
--- libgo/runtime/parfor.c      (revision 245107)
+++ libgo/runtime/parfor.c      (working copy)
@@ -10,7 +10,7 @@
 struct ParForThread
 {
        // the thread's iteration space [32lsb, 32msb)
-       uint64 pos;
+       uint64 pos __attribute__((aligned(8)));
        // stats
        uint64 nsteal;
        uint64 nstealcnt;
Index: libgo/runtime/runtime.h
===================================================================
--- libgo/runtime/runtime.h     (revision 245109)
+++ libgo/runtime/runtime.h     (working copy)
@@ -431,7 +431,7 @@
                                        // otherwise parfor may return while 
other threads are still working
        ParForThread *thr;              // array of thread descriptors
        // stats
-       uint64 nsteal;
+       uint64 nsteal __attribute__((aligned(8))); // force alignment for m68k
        uint64 nstealcnt;
        uint64 nprocyield;
        uint64 nosyield;

Reply via email to