pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pkg/45665: devel/memcached-1.4.5 build fails with 'dereferencing type-punned pointer will break strict-aliasing rules' errors



>Number:         45665
>Category:       pkg
>Synopsis:       devel/memcached-1.4.5 build fails with 'dereferencing 
>type-punned pointer will break strict-aliasing rules' errors
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 28 00:35:00 +0000 2011
>Originator:     Sergey Kolchin
>Release:        NetBSD-CURRENT/amd64
>Organization:
Izh R.An.Ma
>Environment:
NetBSD  5.99.57 NetBSD 5.99.57 (GENERIC) #1: Thu Nov 24 20:44:22 MSK 2011  
ksa242@chelmno:/home/ksa242/src/netbsd-5.1/obj/sys/arch/amd64/compile/GENERIC 
amd64

>Description:
When I tried to build devel/memcached version 1.4.5 from pkgsrc-2011Q3 using 
gcc v4.5.3, the build failed with the following errors:

memcached.c: In function 'complete_incr_bin':
memcached.c:1023:16: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c:1044:13: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c:1061:17: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c: In function 'process_bin_get':
memcached.c:1193:9: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c: In function 'process_bin_update':
memcached.c:1889:5: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c:1905:5: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c: In function 'process_bin_append_prepend':
memcached.c:1949:5: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c: In function 'process_bin_delete':
memcached.c:2014:9: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c: In function 'do_store_item':
memcached.c:2127:9: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c:2127:9: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c:2144:25: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c:2145:25: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c:2158:13: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c:2160:17: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c:2160:17: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c:2202:13: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c:2214:9: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c: In function 'process_get_command':
memcached.c:2592:45: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c: In function 'process_update_command':
memcached.c:2751:5: error: dereferencing type-punned pointer will break 
strict-aliasing rules
memcached.c: In function 'do_add_delta':
memcached.c:2870:9: error: dereferencing type-punned pointer will break 
strict-aliasing rules

>How-To-Repeat:
Using gcc v4.5.3 and pkgsrc-2011Q3:

$ cd /usr/pkgsrc/devel/memcached
$ make

>Fix:
I've found the patch made by Dmitry Isaikin for memcached-1.4.0-rc1 useful.  
The patch and the issue related discussion can be found here: 
http://code.google.com/p/memcached/issues/detail?id=60

Here's the patch updated to work with memcached-1.4.5:

--- memcached.h.orig    2010-04-03 11:07:16.000000000 +0400
+++ memcached.h 2011-11-28 04:24:56.000000000 +0400
@@ -78,21 +78,21 @@

 /* warning: don't use these macros with a function, as it evals its arg twice 
*/
 #define ITEM_get_cas(i) ((uint64_t)(((i)->it_flags & ITEM_CAS) ? \
-                                    *(uint64_t*)&((i)->end[0]) : 0x0))
+                                    *(uint64_t*)((char*)(i) + sizeof(*i)) : 
0x0))
 #define ITEM_set_cas(i,v) { if ((i)->it_flags & ITEM_CAS) { \
-                          *(uint64_t*)&((i)->end[0]) = v; } }
+                          *(uint64_t*)((char*)(i) + sizeof(*i)) = v; } }
 
-#define ITEM_key(item) (((char*)&((item)->end[0])) \
+#define ITEM_key(item) ((char*)(item) + sizeof(*item) \
          + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
 
-#define ITEM_suffix(item) ((char*) &((item)->end[0]) + (item)->nkey + 1 \
+#define ITEM_suffix(item) ((char*)(item) + sizeof(*item) + (item)->nkey + 1 \
          + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
 
-#define ITEM_data(item) ((char*) &((item)->end[0]) + (item)->nkey + 1 \
+#define ITEM_data(item) ((char*)(item) + sizeof(*item) + (item)->nkey + 1 \
          + (item)->nsuffix \
          + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
 
-#define ITEM_ntotal(item) (sizeof(struct _stritem) + (item)->nkey + 1 \
+#define ITEM_ntotal(item) (sizeof(*item) + (item)->nkey + 1 \
          + (item)->nsuffix + (item)->nbytes \
          + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
 
@@ -302,7 +302,6 @@
     uint8_t         it_flags;   /* ITEM_* above */
     uint8_t         slabs_clsid;/* which slab class we're in */
     uint8_t         nkey;       /* key length, w/terminating null and padding 
*/
-    void * end[];
     /* if it_flags & ITEM_CAS we have 8 bytes CAS */
     /* then null-terminated key */
     /* then " flags length\r\n" (no terminating null) */




Home | Main Index | Thread Index | Old Index