Message ID | 1448382678-6060-2-git-send-email-danielx.t.mrzyglod@intel.com (mailing list archive) |
---|---|
State | Accepted, archived |
Headers |
Return-Path: <dev-bounces@dpdk.org> X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 8ABD98E9F; Tue, 24 Nov 2015 17:33:18 +0100 (CET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id E31D18E8B for <dev@dpdk.org>; Tue, 24 Nov 2015 17:33:16 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 24 Nov 2015 08:33:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,338,1444719600"; d="scan'208";a="858501591" Received: from unknown ([10.217.248.15]) by orsmga002.jf.intel.com with SMTP; 24 Nov 2015 08:33:07 -0800 Received: by (sSMTP sendmail emulation); Tue, 24 Nov 2015 17:33:06 +0100 From: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com> To: dev@dpdk.org Date: Tue, 24 Nov 2015 17:31:18 +0100 Message-Id: <1448382678-6060-2-git-send-email-danielx.t.mrzyglod@intel.com> X-Mailer: git-send-email 2.5.3 In-Reply-To: <1448382678-6060-1-git-send-email-danielx.t.mrzyglod@intel.com> References: <1448377959-4440-1-git-send-email-danielx.t.mrzyglod@intel.com> <1448382678-6060-1-git-send-email-danielx.t.mrzyglod@intel.com> Subject: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK <dev.dpdk.org> List-Unsubscribe: <http://dpdk.org/ml/options/dev>, <mailto:dev-request@dpdk.org?subject=unsubscribe> List-Archive: <http://dpdk.org/ml/archives/dev/> List-Post: <mailto:dev@dpdk.org> List-Help: <mailto:dev-request@dpdk.org?subject=help> List-Subscribe: <http://dpdk.org/ml/listinfo/dev>, <mailto:dev-request@dpdk.org?subject=subscribe> Errors-To: dev-bounces@dpdk.org Sender: "dev" <dev-bounces@dpdk.org> |
Commit Message
Daniel Mrzyglod
Nov. 24, 2015, 4:31 p.m. UTC
This fix is for IPv6 checksum offload error on RHEL65.
Any optimalisation above -O0 provide error in IPv6 checksum
flag "-fstrict-aliasing" is default for optimalisation above -O0.
Fixes: 2b039d5f20a3 ("net: fix build with gcc 4.4.7 and strict aliasing")
Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
---
lib/librte_net/rte_ip.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
Hi Daniel, So for my own curiosity: what went wrong here? Did compiler avoid to generate a code for while {} loop? Or something else? BTW, it is an internal function, so instead of introducing new typedef, we can just change the type of buf? Let say to uint8_t *? From gcc manual page: " A character type may alias any other type." Would that work? Konstantin > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Daniel Mrzyglod > Sent: Tuesday, November 24, 2015 4:31 PM > To: dev@dpdk.org > Subject: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing > > This fix is for IPv6 checksum offload error on RHEL65. > Any optimalisation above -O0 provide error in IPv6 checksum > flag "-fstrict-aliasing" is default for optimalisation above -O0. > > Fixes: 2b039d5f20a3 ("net: fix build with gcc 4.4.7 and strict aliasing") > > Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com> > --- > 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 71c519a..5b7554a 100644 > --- a/lib/librte_net/rte_ip.h > +++ b/lib/librte_net/rte_ip.h > @@ -169,7 +169,8 @@ __rte_raw_cksum(const void *buf, size_t len, uint32_t sum) > { > /* workaround gcc strict-aliasing warning */ > uintptr_t ptr = (uintptr_t)buf; > - const uint16_t *u16 = (const uint16_t *)ptr; > + typedef uint16_t __attribute__((__may_alias__)) u16_p; > + const u16_p *u16 = (const u16_p *)ptr; > > while (len >= (sizeof(*u16) * 4)) { > sum += u16[0]; > -- > 2.5.0
If we change input buf: xapp-gcc/include/rte_ip.h:211: error: dereferencing pointer 'u16' does break strict-aliasing rules /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:204: note: initialized from here /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:212: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:212: note: initialized from here /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:213: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:213: note: initialized from here /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:214: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:214: note: initialized from here The change was pointed out by Michael Qiu in patch: 2b039d5f20a34016ecaf9b26f8f8b6c4a81bf4b6 We can only cast void to uint8 but it would involve big endian/ little endian macros: static inline uint32_t __attribute__((__may_alias__)) __rte_raw_cksum(const void *buf, size_t len, uint32_t sum) { /* workaround gcc strict-aliasing warning */ const uint8_t *u8 = ((const uint8_t *)buf); while (len >= (sizeof(*u8) * 8)) { sum += *(u8+1) << 8 | *(u8); sum += *(u8+3) << 8 | *(u8+2); sum += *(u8+5) << 8 | *(u8+4); sum += *(u8+7) << 8 | *(u8+6); len -= sizeof(*u8) * 8; u8 += 8; } while (len >= 2*sizeof(*u8)) { sum += *u8 << 8 | *(u8+1); len -= 2*sizeof(*u8); u8 += 2; } /* if length is in odd bytes */ if (len == 1) sum += *((const uint8_t *)u8); return sum; } I will research about this union usage suggested by Stephen, but for this moment local typedef & __attribute__((__may_alias__)) is the most clean solution which work under gcc(4.4.7), clang, icc. >-----Original Message----- >From: Ananyev, Konstantin >Sent: Tuesday, November 24, 2015 6:58 PM >To: Mrzyglod, DanielX T <danielx.t.mrzyglod@intel.com> >Cc: dev@dpdk.org >Subject: RE: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing > >Hi Daniel, >So for my own curiosity: what went wrong here? >Did compiler avoid to generate a code for while {} loop? >Or something else? >BTW, it is an internal function, so instead of introducing new typedef, >we can just change the type of buf? >Let say to uint8_t *? >From gcc manual page: " A character type may alias any other type." >Would that work? >Konstantin > >> -----Original Message----- >> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Daniel Mrzyglod >> Sent: Tuesday, November 24, 2015 4:31 PM >> To: dev@dpdk.org >> Subject: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing >> >> This fix is for IPv6 checksum offload error on RHEL65. >> Any optimalisation above -O0 provide error in IPv6 checksum >> flag "-fstrict-aliasing" is default for optimalisation above -O0. >> >> Fixes: 2b039d5f20a3 ("net: fix build with gcc 4.4.7 and strict aliasing") >> >> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com> >> --- >> 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 71c519a..5b7554a 100644 >> --- a/lib/librte_net/rte_ip.h >> +++ b/lib/librte_net/rte_ip.h >> @@ -169,7 +169,8 @@ __rte_raw_cksum(const void *buf, size_t len, uint32_t >sum) >> { >> /* workaround gcc strict-aliasing warning */ >> uintptr_t ptr = (uintptr_t)buf; >> - const uint16_t *u16 = (const uint16_t *)ptr; >> + typedef uint16_t __attribute__((__may_alias__)) u16_p; >> + const u16_p *u16 = (const u16_p *)ptr; >> >> while (len >= (sizeof(*u16) * 4)) { >> sum += u16[0]; >> -- >> 2.5.0
> -----Original Message----- > From: Mrzyglod, DanielX T > Sent: Wednesday, November 25, 2015 5:07 PM > To: Ananyev, Konstantin > Cc: dev@dpdk.org > Subject: RE: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing > > If we change input buf: > xapp-gcc/include/rte_ip.h:211: error: dereferencing pointer 'u16' does break strict-aliasing rules > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:204: note: initialized from here > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:212: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:212: note: initialized from here > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:213: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:213: note: initialized from here > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:214: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:214: note: initialized from here > > The change was pointed out by Michael Qiu in patch: 2b039d5f20a34016ecaf9b26f8f8b6c4a81bf4b6 > > We can only cast void to uint8 but it would involve big endian/ little endian macros: > > static inline uint32_t __attribute__((__may_alias__)) > __rte_raw_cksum(const void *buf, size_t len, uint32_t sum) > { > /* workaround gcc strict-aliasing warning */ > const uint8_t *u8 = ((const uint8_t *)buf); > while (len >= (sizeof(*u8) * 8)) { > sum += *(u8+1) << 8 | *(u8); > sum += *(u8+3) << 8 | *(u8+2); > sum += *(u8+5) << 8 | *(u8+4); > sum += *(u8+7) << 8 | *(u8+6); > > len -= sizeof(*u8) * 8; > u8 += 8; > } > > while (len >= 2*sizeof(*u8)) { > sum += *u8 << 8 | *(u8+1); > len -= 2*sizeof(*u8); > u8 += 2; > } > > /* if length is in odd bytes */ > if (len == 1) > sum += *((const uint8_t *)u8); > > return sum; > } So I misinterpreted gcc manual: it only allows conversion from any other type to char, not visa-versa. Sorry for wrong suggestion. > > I will research about this union usage suggested by Stephen, but for this moment local typedef & __attribute__((__may_alias__)) is the > most clean solution which work under gcc(4.4.7), clang, icc. Ok, if there is no other known way - let's stick with your original patch. Konstantin > > >-----Original Message----- > >From: Ananyev, Konstantin > >Sent: Tuesday, November 24, 2015 6:58 PM > >To: Mrzyglod, DanielX T <danielx.t.mrzyglod@intel.com> > >Cc: dev@dpdk.org > >Subject: RE: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing > > > >Hi Daniel, > >So for my own curiosity: what went wrong here? > >Did compiler avoid to generate a code for while {} loop? > >Or something else? > >BTW, it is an internal function, so instead of introducing new typedef, > >we can just change the type of buf? > >Let say to uint8_t *? > >From gcc manual page: " A character type may alias any other type." > >Would that work? > >Konstantin > > > >> -----Original Message----- > >> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Daniel Mrzyglod > >> Sent: Tuesday, November 24, 2015 4:31 PM > >> To: dev@dpdk.org > >> Subject: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing > >> > >> This fix is for IPv6 checksum offload error on RHEL65. > >> Any optimalisation above -O0 provide error in IPv6 checksum > >> flag "-fstrict-aliasing" is default for optimalisation above -O0. > >> > >> Fixes: 2b039d5f20a3 ("net: fix build with gcc 4.4.7 and strict aliasing") > >> > >> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com> > >> --- > >> 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 71c519a..5b7554a 100644 > >> --- a/lib/librte_net/rte_ip.h > >> +++ b/lib/librte_net/rte_ip.h > >> @@ -169,7 +169,8 @@ __rte_raw_cksum(const void *buf, size_t len, uint32_t > >sum) > >> { > >> /* workaround gcc strict-aliasing warning */ > >> uintptr_t ptr = (uintptr_t)buf; > >> - const uint16_t *u16 = (const uint16_t *)ptr; > >> + typedef uint16_t __attribute__((__may_alias__)) u16_p; > >> + const u16_p *u16 = (const u16_p *)ptr; > >> > >> while (len >= (sizeof(*u16) * 4)) { > >> sum += u16[0]; > >> -- > >> 2.5.0
diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h index 71c519a..5b7554a 100644 --- a/lib/librte_net/rte_ip.h +++ b/lib/librte_net/rte_ip.h @@ -169,7 +169,8 @@ __rte_raw_cksum(const void *buf, size_t len, uint32_t sum) { /* workaround gcc strict-aliasing warning */ uintptr_t ptr = (uintptr_t)buf; - const uint16_t *u16 = (const uint16_t *)ptr; + typedef uint16_t __attribute__((__may_alias__)) u16_p; + const u16_p *u16 = (const u16_p *)ptr; while (len >= (sizeof(*u16) * 4)) { sum += u16[0];