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 956B1559C for ; Wed, 3 Dec 2014 20:44:22 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 03 Dec 2014 08:45:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,508,1413270000"; d="scan'208";a="617946210" Received: from bricha3-mobl3.ger.corp.intel.com ([10.243.20.33]) by orsmga001.jf.intel.com with SMTP; 03 Dec 2014 06:51:49 -0800 Received: by (sSMTP sendmail emulation); Wed, 03 Dec 2014 14:51:48 +0025 Date: Wed, 3 Dec 2014 14:51:48 +0000 From: Bruce Richardson To: "Qiu, Michael" Message-ID: <20141203145148.GB2396@bricha3-MOBL3> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <533710CFB86FA344BFBF2D6802E60286C9C531@SHSMSX101.ccr.corp.intel.com> Organization: Intel Shannon Ltd. User-Agent: Mutt/1.5.23 (2014-03-12) 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: Wed, 03 Dec 2014 19:44:24 -0000 On Wed, Dec 03, 2014 at 01:59:58PM +0000, Qiu, Michael wrote: > On 2014/12/3 19:43, Richardson, Bruce wrote: > > On Wed, Dec 03, 2014 at 07:28:19PM +0800, Michael Qiu wrote: > >> app/test-pmd/csumonly.c: In function ‘get_psd_sum’: > >> build/include/rte_ip.h:161: error: dereferencing pointer ‘u16’ > >> does break strict-aliasing rules > >> build/include/rte_ip.h:157: note: initialized from here > >> ... > >> > >> The root cause is that, compile enable strict aliasing by default, > >> while in function rte_raw_cksum() try to convert 'const char *' > >> to 'const uint16_t *'. > >> > > What compiler version is this with? Is there any other way to fix this > > other than disabling the compiler warnings. Turning off strict aliasing may > > affect performance as it reduces the number of optimizations that the compiler > > can perform. > > The compile version is: > > $ gcc -v > Using built-in specs. > Target: x86_64-redhat-linux > ... > gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) > > > The OS is centos6.5 x86_64 > > > Actually, another possible solution is, as gcc manual shows, use union. > In function rte_raw_cksum() of lib/librte_net/rte_ip.h: > > static inline uint16_t > rte_raw_cksum(const char *buf, size_t len){ > union { > const char *ubuf; > const uint16_t *uu16; > } convert; > > convert.ubuf = buf; > const uint16_t *u16 = convert.uu16; > ... > } > > This may be work, but not test yet. > > Any comments about this solution? what happens if you make rte_raw_cksum take a void * (or const void *) parameter instead of "const char *"? /Bruce