summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Qiu <michael.qiu@intel.com>2014-12-04 12:16:04 +0800
committerThomas Monjalon <thomas.monjalon@6wind.com>2014-12-11 01:42:02 +0100
commit2b039d5f20a34016ecaf9b26f8f8b6c4a81bf4b6 (patch)
tree64c697981214f69aefcfcedca8bfe9aec1472a2e
parent42c035e7bbfe95f26ee4ddf2559b94f574974a86 (diff)
downloaddpdk-2b039d5f20a34016ecaf9b26f8f8b6c4a81bf4b6.zip
dpdk-2b039d5f20a34016ecaf9b26f8f8b6c4a81bf4b6.tar.gz
dpdk-2b039d5f20a34016ecaf9b26f8f8b6c4a81bf4b6.tar.xz
net: fix build with gcc 4.4.7 and strict aliasing
include/rte_ip.h:161: error: dereferencing pointer ‘u16’ does break strict-aliasing rules 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 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. Signed-off-by: Michael Qiu <michael.qiu@intel.com> [Thomas: add workaround comment] Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>
-rw-r--r--lib/librte_net/rte_ip.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index 61e4457..46f0497 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -154,7 +154,9 @@ struct ipv4_hdr {
static inline uint16_t
rte_raw_cksum(const char *buf, size_t len)
{
- const uint16_t *u16 = (const uint16_t *)buf;
+ /* workaround gcc strict-aliasing warning */
+ uintptr_t ptr = (uintptr_t)buf;
+ const uint16_t *u16 = (const uint16_t *)ptr;
uint32_t sum = 0;
while (len >= (sizeof(*u16) * 4)) {