byteorder: do not assume PowerPC is big-endian
authorDavid Disseldorp <ddiss@samba.org>
Mon, 5 May 2014 11:42:36 +0000 (13:42 +0200)
committerDavid Disseldorp <ddiss@samba.org>
Tue, 6 May 2014 16:14:13 +0000 (18:14 +0200)
byteorder.h currently uses reverse-indexing ASM instructions for little
endian multi-byte storage/retrieval on PowerPC. With Power8 this is an
incorrect assumption, as it can be big or little endian.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=10590

Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
lib/util/byteorder.h

index 58cd68abf900404faa253a16e6ea9f8f5d503283..297be52ec3b180432e62f4f8d5f382af976ad376 100644 (file)
@@ -89,10 +89,12 @@ it also defines lots of intermediate macros, just ignore those :-)
 
 
 /*
-  on powerpc we can use the magic instructions to load/store
-  in little endian
-*/
-#if (defined(__powerpc__) && defined(__GNUC__))
+ * On powerpc we can use the magic instructions to load/store in little endian.
+ * The instructions are reverse-indexing, so assume a big endian Power
+ * processor. Power8 can be big or little endian, so we need to explicitly
+ * check.
+ */
+#if (defined(__powerpc__) && defined(__GNUC__) && HAVE_BIG_ENDIAN)
 static __inline__ uint16_t ld_le16(const uint16_t *addr)
 {
        uint16_t val;