From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id BA21F93A8 for ; Wed, 25 Nov 2015 18:07:47 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 25 Nov 2015 09:06:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,343,1444719600"; d="scan'208";a="607023708" Received: from irsmsx109.ger.corp.intel.com ([163.33.3.23]) by FMSMGA003.fm.intel.com with ESMTP; 25 Nov 2015 09:06:43 -0800 Received: from irsmsx107.ger.corp.intel.com ([169.254.10.132]) by IRSMSX109.ger.corp.intel.com ([169.254.13.96]) with mapi id 14.03.0248.002; Wed, 25 Nov 2015 17:06:43 +0000 From: "Mrzyglod, DanielX T" To: "Ananyev, Konstantin" Thread-Topic: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing Thread-Index: AQHRJtXj0jQ5L6bslEaF3kXjDAfZr56rdbUAgAGCvIA= Date: Wed, 25 Nov 2015 17:06:42 +0000 Message-ID: <7ADD74816B4C8A45B56203CBA65FE5A61D98EAE5@IRSMSX107.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> In-Reply-To: <2601191342CEEE43887BDE71AB97725836ACBC89@irsmsx105.ger.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] 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:07:48 -0000 If we change input buf: xapp-gcc/include/rte_ip.h:211: error: dereferencing pointer 'u16' does brea= k strict-aliasing rules /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:204: note: initializ= ed from here /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:212: error: derefere= ncing pointer '({anonymous})' does break strict-aliasing rules /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:212: note: initializ= ed from here /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:213: error: derefere= ncing pointer '({anonymous})' does break strict-aliasing rules /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:213: note: initializ= ed from here /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:214: error: derefere= ncing pointer '({anonymous})' does break strict-aliasing rules /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:214: note: initializ= ed from here The change was pointed out by Michael Qiu in patch: 2b039d5f20a34016ecaf9b= 26f8f8b6c4a81bf4b6 We can only cast void to uint8 but it would involve big endian/ little endi= an 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 =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); len -=3D sizeof(*u8) * 8; u8 +=3D 8; } while (len >=3D 2*sizeof(*u8)) { sum +=3D *u8 << 8 | *(u8+1); len -=3D 2*sizeof(*u8); u8 +=3D 2; } /* if length is in odd bytes */ if (len =3D=3D 1) sum +=3D *((const uint8_t *)u8); return sum; } I will research about this union usage suggested by Stephen, but for this m= oment local typedef & __attribute__((__may_alias__)) is the most clean sol= ution 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 >Cc: dev@dpdk.org >Subject: RE: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and stric= t 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 >> --- >> 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 =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