On 12/4/2014 9:35 PM, Michael Qiu wrote: > app/test-pmd/csumonly.c: In function ?get_psd_sum?: > build/include/rte_ip.h:161: error: dereferencing pointer ?u16? > does break strict-aliasing rules > build/include/rte_ip.h:157: note: initialized from here > ... > > The root cause is that, compile enable strict aliasing by default, > while in function rte_raw_cksum() try to convert 'const char *' > to 'const uint16_t *'. > > This patch is one workaround fix. > > Signed-off-by: Michael Qiu <michael.qiu at intel.com> > --- > v3 --> v2: > use uintptr_t instead of unsigned long to > save pointer. > > v2 --> v1: > Workaround solution instead of shut off the > gcc params. > > lib/librte_net/rte_ip.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h > index 61e4457..cda3436 100644 > --- a/lib/librte_net/rte_ip.h > +++ b/lib/librte_net/rte_ip.h > @@ -154,7 +154,8 @@ struct ipv4_hdr { > static inline uint16_t > rte_raw_cksum(const char *buf, size_t len) > { > - const uint16_t *u16 = (const uint16_t *)buf; > + uintptr_t ptr = (uintptr_t)buf; > + const uint16_t *u16 = (const uint16_t *)ptr; > uint32_t sum = 0; > > while (len >= (sizeof(*u16) * 4)) { This workaround is to solve the compile issue of GCC strict-aliasing(Two different type pointers should not be point to the same memory address).
For GCC 4.4.7 it will definitely occurs if flags "-fstrict-aliasing" and "-Wall" used. Thanks, Michael