Skip to contentSkip to conversation

xfsprogs: fix crc32 build on big endian

PATCH In review Eric Sandeen 3 participants 3 messages Oct 5, 2013 – Oct 18, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfsprogs: fix crc32 build on big endian

While kernelspace can test #ifdef __LITTLE_ENDIAN, this doesn't work in userspace. __LITTLE_ENDIAN is defined - as is __BIG_ENDIAN.

So we build on all boxes as __LITTLE_ENDIAN, and the self-test (thankfully!) fails on big endian boxes.

Fix this by testing __BYTE_ORDER values.

And add an else which should never be hit, but just in case...

---

libxfs/crc32.c +4 -2
index 1c0d958..0f847d2 100644
@@ -63,18 +63,20 @@ typedef __u32	u64;
 static inline u32
 crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256])
 {
-# ifdef __LITTLE_ENDIAN
+#if __BYTE_ORDER == __LITTLE_ENDIAN
 #  define DO_CRC(x) crc = t0[(crc ^ (x)) & 255] ^ (crc >> 8)
 #  define DO_CRC4 (t3[(q) & 255] ^ t2[(q >> 8) & 255] ^ \
 		   t1[(q >> 16) & 255] ^ t0[(q >> 24) & 255])
 #  define DO_CRC8 (t7[(q) & 255] ^ t6[(q >> 8) & 255] ^ \
 		   t5[(q >> 16) & 255] ^ t4[(q >> 24) & 255])
-# else
+# elif __BYTE_ORDER == __BIG_ENDIAN
 #  define DO_CRC(x) crc = t0[((crc >> 24) ^ (x)) & 255] ^ (crc << 8)
 #  define DO_CRC4 (t0[(q) & 255] ^ t1[(q >> 8) & 255] ^ \
 		   t2[(q >> 16) & 255] ^ t3[(q >> 24) & 255])
 #  define DO_CRC8 (t4[(q) & 255] ^ t5[(q >> 8) & 255] ^ \
 		   t6[(q >> 16) & 255] ^ t7[(q >> 24) & 255])
+# else
+#  error What endian are you?
 # endif
 	const u32 *b;
 	size_t    rem_len;

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Eric Sandeen

While kernelspace can test #ifdef __LITTLE_ENDIAN, this doesn't work in userspace. __LITTLE_ENDIAN is defined - as is __BIG_ENDIAN.

So we build on all boxes as __LITTLE_ENDIAN, and the self-test (thankfully!) fails on big endian boxes.

I'm glad I put that self test into the build now. :)

Quoted 24 lines

Fix this by testing __BYTE_ORDER values.

And add an else which should never be hit, but just in case...

---

libxfs/crc32.c +2 -2
index 1c0d958..0f847d2 100644
@@ -63,18 +63,20 @@ typedef __u32	u64;
 static inline u32
 crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256])
 {
-# ifdef __LITTLE_ENDIAN
+#if __BYTE_ORDER == __LITTLE_ENDIAN
 #  define DO_CRC(x) crc = t0[(crc ^ (x)) & 255] ^ (crc >> 8)
 #  define DO_CRC4 (t3[(q) & 255] ^ t2[(q >> 8) & 255] ^ \
 		   t1[(q >> 16) & 255] ^ t0[(q >> 24) & 255])
 #  define DO_CRC8 (t7[(q) & 255] ^ t6[(q >> 8) & 255] ^ \
 		   t5[(q >> 16) & 255] ^ t4[(q >> 24) & 255])
-# else
+# elif __BYTE_ORDER == __BIG_ENDIAN

libxfs/crc32.c typedef __u32 u64; · line 82

Quoted 10 lines
libxfs/crc32.c +2 -0
 #  define DO_CRC(x) crc = t0[((crc >> 24) ^ (x)) & 255] ^ (crc << 8)
 #  define DO_CRC4 (t0[(q) & 255] ^ t1[(q >> 8) & 255] ^ \
 		   t2[(q >> 16) & 255] ^ t3[(q >> 24) & 255])
 #  define DO_CRC8 (t4[(q) & 255] ^ t5[(q >> 8) & 255] ^ \
 		   t6[(q >> 16) & 255] ^ t7[(q >> 24) & 255])
+# else
+#  error What endian are you?
 # endif
 	const u32 *b;
 	size_t    rem_len;

Looks good - it matches the other endian checks in the code.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs