From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 1D2BC6A95 for ; Thu, 4 Dec 2014 03:40:27 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 03 Dec 2014 18:40:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,512,1413270000"; d="scan'208";a="618314117" Received: from kmsmsx151.gar.corp.intel.com ([172.21.73.86]) by orsmga001.jf.intel.com with ESMTP; 03 Dec 2014 18:40:25 -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; Thu, 4 Dec 2014 10:38:38 +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; Thu, 4 Dec 2014 10:38:37 +0800 From: "Qiu, Michael" To: "Richardson, Bruce" Thread-Topic: [PATCH] test-pmd: Fix pointer aliasing error Thread-Index: AQHQDuxQX/2B2GdrV0OV5lPAliaykw== Date: Thu, 4 Dec 2014 02:38:35 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286C9C893@SHSMSX101.ccr.corp.intel.com> References: <1417606044-3432-1-git-send-email-michael.qiu@intel.com> <1417606099-3489-1-git-send-email-michael.qiu@intel.com> <20141203114258.GA2396@bricha3-MOBL3> <533710CFB86FA344BFBF2D6802E60286C9C531@SHSMSX101.ccr.corp.intel.com> <20141203145148.GB2396@bricha3-MOBL3> <533710CFB86FA344BFBF2D6802E60286C9C5BA@SHSMSX101.ccr.corp.intel.com> <20141203153634.GA6524@bricha3-MOBL3> 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 Cc: "dev@dpdk.org" , Michael Qiu Subject: Re: [dpdk-dev] [PATCH] 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: Thu, 04 Dec 2014 02:40:29 -0000 On 12/3/2014 11:36 PM, Richardson, Bruce wrote:=0A= > On Wed, Dec 03, 2014 at 03:19:34PM +0000, Qiu, Michael wrote:=0A= >> On 2014/12/3 22:51, Richardson, Bruce wrote:=0A= >>> On Wed, Dec 03, 2014 at 01:59:58PM +0000, Qiu, Michael wrote:=0A= >>>> On 2014/12/3 19:43, Richardson, Bruce wrote:=0A= >>>>> On Wed, Dec 03, 2014 at 07:28:19PM +0800, 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= >>>>> What compiler version is this with? Is there any other way to fix thi= s=0A= >>>>> other than disabling the compiler warnings. Turning off strict aliasi= ng may=0A= >>>>> affect performance as it reduces the number of optimizations that the= compiler=0A= >>>>> can perform.=0A= >>>> The compile version is:=0A= >>>>=0A= >>>> $ gcc -v=0A= >>>> Using built-in specs.=0A= >>>> Target: x86_64-redhat-linux=0A= >>>> ...=0A= >>>> gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)=0A= >>>>=0A= >>>>=0A= >>>> The OS is centos6.5 x86_64=0A= >>>>=0A= >>>>=0A= >>>> Actually, another possible solution is, as gcc manual shows, use union= .=0A= >>>> In function rte_raw_cksum() of lib/librte_net/rte_ip.h:=0A= >>>>=0A= >>>> static inline uint16_t=0A= >>>> rte_raw_cksum(const char *buf, size_t len){=0A= >>>> union {=0A= >>>> const char *ubuf;=0A= >>>> const uint16_t *uu16;=0A= >>>> } convert;=0A= >>>>=0A= >>>> convert.ubuf =3D buf;=0A= >>>> const uint16_t *u16 =3D convert.uu16;=0A= >>>> ...=0A= >>>> }=0A= >>>>=0A= >>>> This may be work, but not test yet.=0A= >>>>=0A= >>>> Any comments about this solution?=0A= >>> what happens if you make rte_raw_cksum take a void * (or const void *) = parameter=0A= >>> instead of "const char *"?=0A= >> "size_t len" is for type char, it is the the array size(for char array= =0A= >> is byte numbers), if we use void *, the meaning maybe confuse I think.= =0A= > That shouldn't be a big issue. We can rename it to "size" instead of "len= " if=0A= > needed.=0A= =0A= As I tested in my env just, void * is still not work, the same errors=0A= post when compile.=0A= =0A= Then the solution for DPDK should be:=0A= - As Olivier suggest, add the -Wno-strict-aliasing only for gcc 4.4 in=0A= the Makefile=0A= - As gcc manual suggest, use "union" to work around this issue.=0A= =0A= Thanks,=0A= Michael=0A= >> But it should work with other code change.=0A= >>=0A= >> Thanks,=0A= >> Michael=0A= >>> /Bruce=0A= >>>=0A= =0A=