6729ff
From d31a18bcaaa3f3dd5f0bf8db705089c42c7ab0b3 Mon Sep 17 00:00:00 2001
6729ff
From: Andreas Schneider <asn@samba.org>
6729ff
Date: Thu, 14 Nov 2013 18:36:41 +0100
6729ff
Subject: [PATCH] util: Remove 32bit macros breaking strict aliasing.
6729ff
6729ff
BUG: https://bugzilla.samba.org/show_bug.cgi?id=10269
6729ff
6729ff
These macros might have worked but they break strict aliasing in the
6729ff
meantime and so the compiler is not able to optimize the relevant code.
6729ff
6729ff
Signed-off-by: Andreas Schneider <asn@samba.org>
6729ff
Reviewed-by: Volker Lendecke <vl@samba.org>
6729ff
6729ff
Autobuild-User(master): Volker Lendecke <vl@samba.org>
6729ff
Autobuild-Date(master): Thu Nov 14 23:16:45 CET 2013 on sn-devel-104
6729ff
6729ff
(cherry picked from commit af69cb2a78810e608ccff115b433801a58a749e4)
6729ff
Signed-off-by: Andreas Schneider <asn@samba.org>
6729ff
---
6729ff
 lib/util/byteorder.h | 52 ++--------------------------------------------------
6729ff
 1 file changed, 2 insertions(+), 50 deletions(-)
6729ff
6729ff
diff --git a/lib/util/byteorder.h b/lib/util/byteorder.h
6729ff
index 6bcf71e..58cd68a 100644
6729ff
--- a/lib/util/byteorder.h
6729ff
+++ b/lib/util/byteorder.h
6729ff
@@ -35,15 +35,6 @@ Here is a description of this file that I emailed to the samba list once:
6729ff
 
6729ff
 sure.
6729ff
 
6729ff
-The distinction between 386 and other architectures is only there as
6729ff
-an optimisation. You can take it out completely and it will make no
6729ff
-difference. The routines (macros) in byteorder.h are totally byteorder
6729ff
-independent. The 386 optimsation just takes advantage of the fact that
6729ff
-the x86 processors don't care about alignment, so we don't have to
6729ff
-align ints on int boundaries etc. If there are other processors out
6729ff
-there that aren't alignment sensitive then you could also define
6729ff
-CAREFUL_ALIGNMENT=0 on those processors as well.
6729ff
-
6729ff
 Ok, now to the macros themselves. I'll take a simple example, say we
6729ff
 want to extract a 2 byte integer from a SMB packet and put it into a
6729ff
 type called uint16_t that is in the local machines byte order, and you
6729ff
@@ -130,20 +121,6 @@ static __inline__ void st_le32(uint32_t *addr, const uint32_t val)
6729ff
 #define HAVE_ASM_BYTEORDER 0
6729ff
 #endif
6729ff
 
6729ff
-
6729ff
-
6729ff
-#undef CAREFUL_ALIGNMENT
6729ff
-
6729ff
-/* we know that the 386 can handle misalignment and has the "right" 
6729ff
-   byteorder */
6729ff
-#if defined(__i386__)
6729ff
-#define CAREFUL_ALIGNMENT 0
6729ff
-#endif
6729ff
-
6729ff
-#ifndef CAREFUL_ALIGNMENT
6729ff
-#define CAREFUL_ALIGNMENT 1
6729ff
-#endif
6729ff
-
6729ff
 #define CVAL(buf,pos) ((unsigned int)(((const uint8_t *)(buf))[pos]))
6729ff
 #define CVAL_NC(buf,pos) (((uint8_t *)(buf))[pos]) /* Non-const version of CVAL */
6729ff
 #define PVAL(buf,pos) (CVAL(buf,pos))
6729ff
@@ -161,7 +138,7 @@ static __inline__ void st_le32(uint32_t *addr, const uint32_t val)
6729ff
 #define SSVALS(buf,pos,val) SSVAL((buf),(pos),((int16_t)(val)))
6729ff
 #define SIVALS(buf,pos,val) SIVAL((buf),(pos),((int32_t)(val)))
6729ff
 
6729ff
-#elif CAREFUL_ALIGNMENT
6729ff
+#else /* not HAVE_ASM_BYTEORDER */
6729ff
 
6729ff
 #define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
6729ff
 #define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
6729ff
@@ -174,32 +151,7 @@ static __inline__ void st_le32(uint32_t *addr, const uint32_t val)
6729ff
 #define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16_t)(val)))
6729ff
 #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32_t)(val)))
6729ff
 
6729ff
-#else /* not CAREFUL_ALIGNMENT */
6729ff
-
6729ff
-/* this handles things for architectures like the 386 that can handle
6729ff
-   alignment errors */
6729ff
-/*
6729ff
-   WARNING: This section is dependent on the length of int16_t and int32_t
6729ff
-   being correct 
6729ff
-*/
6729ff
-
6729ff
-/* get single value from an SMB buffer */
6729ff
-#define SVAL(buf,pos) (*(const uint16_t *)((const char *)(buf) + (pos)))
6729ff
-#define SVAL_NC(buf,pos) (*(uint16_t *)((void *)((char *)(buf) + (pos)))) /* Non const version of above. */
6729ff
-#define IVAL(buf,pos) (*(const uint32_t *)((const char *)(buf) + (pos)))
6729ff
-#define IVAL_NC(buf,pos) (*(uint32_t *)((void *)((char *)(buf) + (pos)))) /* Non const version of above. */
6729ff
-#define SVALS(buf,pos) (*(const int16_t *)((const char *)(buf) + (pos)))
6729ff
-#define SVALS_NC(buf,pos) (*(int16_t *)((void *)((char *)(buf) + (pos)))) /* Non const version of above. */
6729ff
-#define IVALS(buf,pos) (*(const int32_t *)((const char *)(buf) + (pos)))
6729ff
-#define IVALS_NC(buf,pos) (*(int32_t *)((void *)((char *)(buf) + (pos)))) /* Non const version of above. */
6729ff
-
6729ff
-/* store single value in an SMB buffer */
6729ff
-#define SSVAL(buf,pos,val) SVAL_NC(buf,pos)=((uint16_t)(val))
6729ff
-#define SIVAL(buf,pos,val) IVAL_NC(buf,pos)=((uint32_t)(val))
6729ff
-#define SSVALS(buf,pos,val) SVALS_NC(buf,pos)=((int16_t)(val))
6729ff
-#define SIVALS(buf,pos,val) IVALS_NC(buf,pos)=((int32_t)(val))
6729ff
-
6729ff
-#endif /* not CAREFUL_ALIGNMENT */
6729ff
+#endif /* not HAVE_ASM_BYTEORDER */
6729ff
 
6729ff
 /* 64 bit macros */
6729ff
 #define BVAL(p, ofs) (IVAL(p,ofs) | (((uint64_t)IVAL(p,(ofs)+4)) << 32))
6729ff
-- 
6729ff
1.8.4
6729ff