From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bruce Richardson Subject: Re: [PATCH] test-pmd: Fix pointer aliasing error Date: Wed, 3 Dec 2014 15:36:35 +0000 Message-ID: <20141203153634.GA6524@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> <20141203145148.GB2396@bricha3-MOBL3> <533710CFB86FA344BFBF2D6802E60286C9C5BA@SHSMSX101.ccr.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: "dev-VfR2kkLFssw@public.gmane.org" , Michael Qiu To: "Qiu, Michael" Return-path: Content-Disposition: inline In-Reply-To: <533710CFB86FA344BFBF2D6802E60286C9C5BA-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" On Wed, Dec 03, 2014 at 03:19:34PM +0000, Qiu, Michael wrote: > On 2014/12/3 22:51, Richardson, Bruce wrote: > > 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 =E2=80=98get_psd_sum=E2=80=99= : > >>>> build/include/rte_ip.h:161: error: dereferencing pointer =E2=80=98= u16=E2=80=99 > >>>> 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 t= his > >>> other than disabling the compiler warnings. Turning off strict alia= sing may > >>> affect performance as it reduces the number of optimizations that t= he 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 uni= on. > >> 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 =3D buf; > >> const uint16_t *u16 =3D 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 *"? >=20 > "size_t len" is for type char, it is the the array size(for char array > is byte numbers), if we use void *, the meaning maybe confuse I think. That shouldn't be a big issue. We can rename it to "size" instead of "len= " if needed. > But it should work with other code change. >=20 > Thanks, > Michael > > > > /Bruce > > >=20