]> rtime.felk.cvut.cz Git - ulut.git/commitdiff
Do not use standard defined __alignof__ for structure filed alignment determination.
authorPavel Pisa <pisa@cmp.felk.cvut.cz>
Thu, 6 Nov 2014 11:01:41 +0000 (12:01 +0100)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Thu, 6 Nov 2014 11:01:41 +0000 (12:01 +0100)
The problem is that __alignof__ returns optimal alignment for type
for performance but that can differ from actual ABI specified
alignment for structure field of respective type type.

I.e. x86_64 double structure field alignment is 4 per ABI definition
but preferred alignment for performance is 8.

Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
ulut/ul_utdefs.h

index a85614e57ad7cb9e0c3bd4ef8df2d44d540b3b9d..c49630b9a6094b8f8343f2786fd633c13ee50173 100644 (file)
@@ -66,14 +66,24 @@ extern "C" {
 #endif /*__GNUC__*/
 #endif /*UL_CONTAINEROF*/
 
-#ifndef UL_ALIGNOF
+#ifndef UL_ALIGNOF_FIELD
+#define        UL_ALIGNOF_FIELD(_type) UL_OFFSETOF(struct {char _fld0; _type _fld1;}, _fld1)
+#endif /*UL_ALIGNOF*/
+
+#ifndef UL_ALIGNOF_TYPE
 #ifdef  __GNUC__
-#define        UL_ALIGNOF(_type) __alignof__(_type)
+/* The compiler provided alignment for performance can differ from ABI struct one */
+#define        UL_ALIGNOF_TYPE(_type) __alignof__(_type)
 #else /*__GNUC__*/
-#define        UL_ALIGNOF(_type) UL_OFFSETOF(struct {char _fld0; _type _fld1;}, _fld1)
+#define UL_ALIGNOF_TYPE UL_ALIGNOF_FIELD
 #endif /*__GNUC__*/
 #endif /*UL_ALIGNOF*/
 
+#ifndef UL_ALIGNOF
+#define        UL_ALIGNOF UL_ALIGNOF_FIELD
+#endif /*UL_ALIGNOF*/
+
+
 #ifndef UL_NOPSTATEMENT
 #define UL_NOPSTATEMENT do { } while(0)
 #endif