* [PATCH] xfsprogs: fix crc32 build on big endian
@ 2013-10-05 2:20 Eric Sandeen
2013-10-05 3:54 ` Dave Chinner
2013-10-18 17:19 ` Rich Johnston
0 siblings, 2 replies; 3+ messages in thread
From: Eric Sandeen @ 2013-10-05 2:20 UTC (permalink / raw)
To: xfs-oss
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...
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/libxfs/crc32.c b/libxfs/crc32.c
index 1c0d958..0f847d2 100644
--- a/libxfs/crc32.c
+++ b/libxfs/crc32.c
@@ -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
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] xfsprogs: fix crc32 build on big endian
2013-10-05 2:20 [PATCH] xfsprogs: fix crc32 build on big endian Eric Sandeen
@ 2013-10-05 3:54 ` Dave Chinner
2013-10-18 17:19 ` Rich Johnston
1 sibling, 0 replies; 3+ messages in thread
From: Dave Chinner @ 2013-10-05 3:54 UTC (permalink / raw)
To: Eric Sandeen; +Cc: xfs-oss
On Fri, Oct 04, 2013 at 09:20:03PM -0500, Eric Sandeen wrote:
> 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. :)
> Fix this by testing __BYTE_ORDER values.
>
> And add an else which should never be hit, but just in case...
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
>
> diff --git a/libxfs/crc32.c b/libxfs/crc32.c
> index 1c0d958..0f847d2 100644
> --- a/libxfs/crc32.c
> +++ b/libxfs/crc32.c
> @@ -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;
Looks good - it matches the other endian checks in the code.
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] xfsprogs: fix crc32 build on big endian
2013-10-05 2:20 [PATCH] xfsprogs: fix crc32 build on big endian Eric Sandeen
2013-10-05 3:54 ` Dave Chinner
@ 2013-10-18 17:19 ` Rich Johnston
1 sibling, 0 replies; 3+ messages in thread
From: Rich Johnston @ 2013-10-18 17:19 UTC (permalink / raw)
To: Eric Sandeen, xfs-oss
This has been committed.
Thanks
--Rich
commit b2dbd6a9a2df5099882bdfc068caa76cf334c99a
Author: Eric Sandeen <sandeen@redhat.com>
Date: Sat Oct 5 02:20:03 2013 +0000
xfsprogs: fix crc32 build on big endian
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-10-18 17:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-05 2:20 [PATCH] xfsprogs: fix crc32 build on big endian Eric Sandeen
2013-10-05 3:54 ` Dave Chinner
2013-10-18 17:19 ` Rich Johnston
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox