Hi,

The reason for this failure is a difference
in alignment of long long for MIPS ISA and IA32.
This results that size of gu_rse structure on mips is 24,
instead of expected 20 (on ia32).

As long long is first attribute in structure,
so it is safe to use pack(4).

> struct gu_rse
> {
>     long long   time;
>     const void* heap_ptr;
>     const void* stack_ptr;
>     long        pid;
> };


I assume that this fix could be used for other architectures like:
armel, armhf, powerpc, sparc.
I did not have a chance to test it on those architectures,
so my changes affects only mips and mipsel.



Solving this issue, fallowing error appears:

> gcs/src/gcs.c:1161: undefined reference to `__sync_fetch_and_add_8'


Mips platform does not have 64-bit __sync_* operations.
To avoid this behaviuor it is needed to use
corresponding __atomic_* from libatomic library.


Patch that solves both issues for mips/mipsel is attached.

Could you please consider including this patch?


Best Regards,
Dejan




diff -uNr percona-xtradb-cluster-galera-2.x-175.orig/SConstruct percona-xtradb-cluster-galera-2.x-175/SConstruct
--- percona-xtradb-cluster-galera-2.x-175.orig/SConstruct	2014-08-13 12:17:02.000000000 +0000
+++ percona-xtradb-cluster-galera-2.x-175/SConstruct	2014-08-13 17:07:21.000000000 +0000
@@ -368,7 +368,7 @@
     print 'Not using boost'
 
 # Check to see if -latomic is need for GCC atomic built-ins.
-if conf.CheckLib(library='atomic', symbol='__sync_fetch_and_add_8'):
+if conf.CheckLib(library='atomic', symbol='__sync_fetch_and_add_8') or conf.CheckLib(library='atomic', symbol='__atomic_fetch_add_8'):
     conf.env.Append(LIBS=['atomic'])
 
 # asio
diff -uNr percona-xtradb-cluster-galera-2.x-175.orig/galerautils/src/gu_atomic.h percona-xtradb-cluster-galera-2.x-175/galerautils/src/gu_atomic.h
--- percona-xtradb-cluster-galera-2.x-175.orig/galerautils/src/gu_atomic.h	2014-05-08 01:08:52.000000000 +0000
+++ percona-xtradb-cluster-galera-2.x-175/galerautils/src/gu_atomic.h	2014-08-13 17:07:46.000000000 +0000
@@ -11,6 +11,8 @@
 
 #ifdef __GNUC__
 
+#if !defined(__mips__) || defined(__mips64)
+
 #define gu_sync_fetch_and_add  __sync_fetch_and_add
 #define gu_sync_fetch_and_sub  __sync_fetch_and_sub
 #define gu_sync_fetch_and_or   __sync_fetch_and_or
@@ -26,6 +28,28 @@
 #define gu_sync_xor_and_fetch  __sync_xor_and_fetch
 #define gu_sync_nand_and_fetch __gu_sync_nand_and_fetch
 
+#else  /* __mips__ */
+
+/* Mips platform does not have 64-bit __sync_* operations.
+ * so it is needed to use corresponding __atomic_* operations from libatomic library. */
+
+#define gu_sync_fetch_and_add(value_, x)  __atomic_fetch_add(value_, x, __ATOMIC_SEQ_CST)
+#define gu_sync_fetch_and_sub(value_, x)  __atomic_fetch_sub(value_, x, __ATOMIC_SEQ_CST)  
+#define gu_sync_fetch_and_or(value_, x)   __atomic_fetch_or(value_, x, __ATOMIC_SEQ_CST) 
+#define gu_sync_fetch_and_and(value_, x)  __atomic_fetch_and(value_, x, __ATOMIC_SEQ_CST)
+#define gu_sync_fetch_and_xor(value_, x)  __atomic_fetch_xor(value_, x, __ATOMIC_SEQ_CST)
+#define gu_sync_fetch_and_nand(value_, x) __atomic_fetch_nand(value_, x, __ATOMIC_SEQ_CST)
+
+
+#define gu_sync_add_and_fetch(value_, x)  __atomic_add_fetch(value_, x, __ATOMIC_SEQ_CST)
+#define gu_sync_sub_and_fetch(value_, x)  __atomic_sub_fetch(value_, x, __ATOMIC_SEQ_CST)
+#define gu_sync_or_and_fetch(value_, x)   __atomic_or_fetch(value_, x, __ATOMIC_SEQ_CST)   
+#define gu_sync_and_and_fetch(value_, x)  __atomic_and_fetch(value_, x, __ATOMIC_SEQ_CST)
+#define gu_sync_xor_and_fetch(value_, x)  __atomic_xor_fetch(value_, x, __ATOMIC_SEQ_CST)
+#define gu_sync_nand_and_fetch(value_, x) __atomic_nand_fetch(value_, x, __ATOMIC_SEQ_CST)
+
+#endif
+
 #else /* __GNUC__ */
 #error "Compiler not supported"
 #endif
diff -uNr percona-xtradb-cluster-galera-2.x-175.orig/galerautils/src/gu_rand.c percona-xtradb-cluster-galera-2.x-175/galerautils/src/gu_rand.c
--- percona-xtradb-cluster-galera-2.x-175.orig/galerautils/src/gu_rand.c	2014-05-08 01:08:52.000000000 +0000
+++ percona-xtradb-cluster-galera-2.x-175/galerautils/src/gu_rand.c	2014-08-13 17:07:25.000000000 +0000
@@ -16,6 +16,16 @@
 
 /*! Structure to hold entropy data.
  *  Should be at least 20 bytes on 32-bit systems and 28 bytes on 64-bit */
+
+/*  Unlike ia32, aligment of long long for MIPS ISA is 8, and size of gu_rse is 24.
+ *  As "long long" atribute is first in gu_rse structure there is no harm in use pack(4) to avoid
+ *  undexpected behavior while using gu_rse structure. */
+
+#if defined(__mips__) && !defined(__mips64__)
+#pragma pack(push)
+#pragma pack(4)
+#endif
+
 struct gu_rse
 {
     long long   time;
@@ -24,6 +34,10 @@
     long        pid;
 };
 
+#if defined(__mips__) && !defined(__mips64__)
+#pragma pack(pop)
+#endif
+
 typedef struct gu_rse gu_rse_t;
 
 long int

Reply via email to