[dpdk-dev] [PATCH] A fix to work around strict-aliasing rules breaking

Wang, Zhihong zhihong.wang at intel.com
Wed Mar 4 06:57:36 CET 2015



> -----Original Message-----
> From: Wodkowski, PawelX
> Sent: Monday, March 02, 2015 8:32 PM
> To: Richardson, Bruce; Wang, Zhihong
> Cc: dev at dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] A fix to work around strict-aliasing rules
> breaking
> 
> On 2015-03-02 11:32, Bruce Richardson wrote:
> > On Mon, Mar 02, 2015 at 05:03:50PM +0800, zhihong.wang at intel.com
> wrote:
> >> Fixed strict-aliasing rules breaking errors for some GCC version.
> >>
> >
> > This looks messy. Also, I believe the definition of memcpy should
> > include the "restrict" keyword to indicate that source and dest can't
> > overlap. Might that help fix the issue?
> >
> 
> Is this error related with overlapping or casting 'void *' to 'uintXX_t *' that
> make compiler report aliasing rule breaking?
> 
> >
> >> Signed-off-by: Zhihong Wang <zhihong.wang at intel.com>
> >> ---
> >>   .../common/include/arch/x86/rte_memcpy.h           | 44 ++++++++++++--
> --------
> >>   1 file changed, 24 insertions(+), 20 deletions(-)
> >>
> >> diff --git a/lib/librte_eal/common/include/arch/x86/rte_memcpy.h
> >> b/lib/librte_eal/common/include/arch/x86/rte_memcpy.h
> >> index 69a5c6f..f412099 100644
> >> --- a/lib/librte_eal/common/include/arch/x86/rte_memcpy.h
> >> +++ b/lib/librte_eal/common/include/arch/x86/rte_memcpy.h
> >> @@ -195,6 +195,8 @@ rte_mov256blocks(uint8_t *dst, const uint8_t *src,
> size_t n)
> >>   static inline void *
> >>   rte_memcpy(void *dst, const void *src, size_t n)
> >>   {
> >> +	uintptr_t dstu = (uintptr_t)dst;
> >> +	uintptr_t srcu = (uintptr_t)src;
> 
> If so maybe using union here would be good solution or 'char *'.

Pawel,

Thanks for the suggestion! But I don't think union can work around this --- already tried in CentOS release 6.5.
Anyway this is for compiler ethics only, the assembly code generated will be the same no matter what kind of method is used.

Zhihong (John)

> 
> --
> Pawel


More information about the dev mailing list