From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 2AA7B93CE for ; Wed, 25 Nov 2015 18:13:54 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 25 Nov 2015 09:13:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,343,1444719600"; d="scan'208";a="859640115" Received: from irsmsx104.ger.corp.intel.com ([163.33.3.159]) by fmsmga002.fm.intel.com with ESMTP; 25 Nov 2015 09:13:52 -0800 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.203]) by IRSMSX104.ger.corp.intel.com ([169.254.5.138]) with mapi id 14.03.0248.002; Wed, 25 Nov 2015 17:13:51 +0000 From: "Ananyev, Konstantin" To: "Mrzyglod, DanielX T" Thread-Topic: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing Thread-Index: AQHRJtXlKbyCe5wuP02Xe5Mg2+ADap6rdJGggAGFEgCAAABVUA== Date: Wed, 25 Nov 2015 17:13:51 +0000 Message-ID: <2601191342CEEE43887BDE71AB97725836ACD3D6@irsmsx105.ger.corp.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> <1448382678-6060-2-git-send-email-danielx.t.mrzyglod@intel.com> <2601191342CEEE43887BDE71AB97725836ACBC89@irsmsx105.ger.corp.intel.com> <7ADD74816B4C8A45B56203CBA65FE5A61D98EAE5@IRSMSX107.ger.corp.intel.com> In-Reply-To: <7ADD74816B4C8A45B56203CBA65FE5A61D98EAE5@IRSMSX107.ger.corp.intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "dev@dpdk.org" Subject: Re: [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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2015 17:13:54 -0000 > -----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 stri= ct aliasing >=20 > If we change input buf: > xapp-gcc/include/rte_ip.h:211: error: dereferencing pointer 'u16' does br= eak strict-aliasing rules > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:204: note: initial= ized from here > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:212: error: derefe= rencing pointer '({anonymous})' does break strict-aliasing rules > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:212: note: initial= ized from here > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:213: error: derefe= rencing pointer '({anonymous})' does break strict-aliasing rules > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:213: note: initial= ized from here > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:214: error: derefe= rencing pointer '({anonymous})' does break strict-aliasing rules > /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:214: note: initial= ized from here >=20 > The change was pointed out by Michael Qiu in patch: 2b039d5f20a34016ecaf= 9b26f8f8b6c4a81bf4b6 >=20 > We can only cast void to uint8 but it would involve big endian/ little en= dian macros: >=20 > 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 =3D ((const uint8_t *)buf); > while (len >=3D (sizeof(*u8) * 8)) { > sum +=3D *(u8+1) << 8 | *(u8); > sum +=3D *(u8+3) << 8 | *(u8+2); > sum +=3D *(u8+5) << 8 | *(u8+4); > sum +=3D *(u8+7) << 8 | *(u8+6); >=20 > len -=3D sizeof(*u8) * 8; > u8 +=3D 8; > } >=20 > while (len >=3D 2*sizeof(*u8)) { > sum +=3D *u8 << 8 | *(u8+1); > len -=3D 2*sizeof(*u8); > u8 +=3D 2; > } >=20 > /* if length is in odd bytes */ > if (len =3D=3D 1) > sum +=3D *((const uint8_t *)u8); >=20 > return sum; > } So I misinterpreted gcc manual: it only allows conversion from any other ty= pe to char, not visa-versa. Sorry for wrong suggestion. >=20 > 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.= =20 Konstantin >=20 > >-----Original Message----- > >From: Ananyev, Konstantin > >Sent: Tuesday, November 24, 2015 6:58 PM > >To: Mrzyglod, DanielX T > >Cc: dev@dpdk.org > >Subject: RE: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and str= ict 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 stric= t 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 aliasin= g") > >> > >> Signed-off-by: Daniel Mrzyglod > >> --- > >> 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, uint3= 2_t > >sum) > >> { > >> /* workaround gcc strict-aliasing warning */ > >> uintptr_t ptr =3D (uintptr_t)buf; > >> - const uint16_t *u16 =3D (const uint16_t *)ptr; > >> + typedef uint16_t __attribute__((__may_alias__)) u16_p; > >> + const u16_p *u16 =3D (const u16_p *)ptr; > >> > >> while (len >=3D (sizeof(*u16) * 4)) { > >> sum +=3D u16[0]; > >> -- > >> 2.5.0