From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 3A59ADE0 for ; Wed, 10 Dec 2014 04:44:30 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 09 Dec 2014 19:42:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,691,1406617200"; d="scan'208";a="496417585" Received: from kmsmsx151.gar.corp.intel.com ([172.21.73.86]) by orsmga003.jf.intel.com with ESMTP; 09 Dec 2014 19:40:43 -0800 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by KMSMSX151.gar.corp.intel.com (172.21.73.86) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 10 Dec 2014 11:44:27 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.110]) by shsmsx102.ccr.corp.intel.com ([169.254.2.216]) with mapi id 14.03.0195.001; Wed, 10 Dec 2014 11:44:25 +0800 From: "Qiu, Michael" To: Michael Qiu , "dev@dpdk.org" , "Thomas.monjalon@6wind.com" Thread-Topic: [dpdk-dev] [PATCH v3] test-pmd: Fix pointer aliasing error Thread-Index: AQHQD8cg6//kKikCHUuP3ggaMBczHg== Date: Wed, 10 Dec 2014 03:44:25 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286C9E52D@SHSMSX101.ccr.corp.intel.com> References: <1417663711-19576-1-git-send-email-michael.qiu@intel.com> <1417666564-19950-1-git-send-email-michael.qiu@intel.com> <533710CFB86FA344BFBF2D6802E60286C9D683@SHSMSX101.ccr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v3] test-pmd: Fix pointer aliasing error 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, 10 Dec 2014 03:44:30 -0000 Hi Thomas,=0A= =0A= What's going on with this patch?=0A= =0A= I really do not have other better solution.=0A= =0A= Thanks,=0A= Michael=0A= On 12/8/2014 9:30 AM, Qiu, Michael wrote:=0A= > On 12/4/2014 9:35 PM, Michael Qiu wrote:=0A= >> app/test-pmd/csumonly.c: In function =91get_psd_sum=92:=0A= >> build/include/rte_ip.h:161: error: dereferencing pointer =91u16=92=0A= >> does break strict-aliasing rules=0A= >> build/include/rte_ip.h:157: note: initialized from here=0A= >> ...=0A= >>=0A= >> The root cause is that, compile enable strict aliasing by default,=0A= >> while in function rte_raw_cksum() try to convert 'const char *'=0A= >> to 'const uint16_t *'.=0A= >>=0A= >> This patch is one workaround fix.=0A= >>=0A= >> Signed-off-by: Michael Qiu =0A= >> ---=0A= >> v3 --> v2:=0A= >> use uintptr_t instead of unsigned long to=0A= >> save pointer.=0A= >>=0A= >> v2 --> v1:=0A= >> Workaround solution instead of shut off the=0A= >> gcc params.=0A= >>=0A= >> lib/librte_net/rte_ip.h | 3 ++-=0A= >> 1 file changed, 2 insertions(+), 1 deletion(-)=0A= >>=0A= >> diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h=0A= >> index 61e4457..cda3436 100644=0A= >> --- a/lib/librte_net/rte_ip.h=0A= >> +++ b/lib/librte_net/rte_ip.h=0A= >> @@ -154,7 +154,8 @@ struct ipv4_hdr {=0A= >> static inline uint16_t=0A= >> rte_raw_cksum(const char *buf, size_t len)=0A= >> {=0A= >> - const uint16_t *u16 =3D (const uint16_t *)buf;=0A= >> + uintptr_t ptr =3D (uintptr_t)buf;=0A= >> + const uint16_t *u16 =3D (const uint16_t *)ptr;=0A= >> uint32_t sum =3D 0;=0A= >> =0A= >> while (len >=3D (sizeof(*u16) * 4)) {=0A= > This workaround is to solve the compile issue of GCC strict-aliasing(Two= =0A= > different type pointers should not be point to the same memory address).= =0A= >=0A= > For GCC 4.4.7 it will definitely occurs if flags "-fstrict-aliasing"=0A= > and "-Wall" used.=0A= >=0A= > Thanks,=0A= > Michael=0A= >=0A= =0A=