From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 9080ACE7 for ; Mon, 8 Dec 2014 02:30:18 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 07 Dec 2014 17:29:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,535,1413270000"; d="scan'208";a="650003022" Received: from pgsmsx105.gar.corp.intel.com ([10.221.44.96]) by orsmga002.jf.intel.com with ESMTP; 07 Dec 2014 17:30:15 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by pgsmsx105.gar.corp.intel.com (10.221.44.96) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 8 Dec 2014 09:30:14 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.110]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.182]) with mapi id 14.03.0195.001; Mon, 8 Dec 2014 09:30:14 +0800 From: "Qiu, Michael" To: Michael Qiu , "dev@dpdk.org" Thread-Topic: [PATCH v3] test-pmd: Fix pointer aliasing error Thread-Index: AQHQD8cg6//kKikCHUuP3ggaMBczHg== Date: Mon, 8 Dec 2014 01:30:12 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286C9D683@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> 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: Mon, 08 Dec 2014 01:30:19 -0000 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=