[dpdk-dev] [PATCH v3] test-pmd: Fix pointer aliasing error

Qiu, Michael michael.qiu at intel.com
Fri Dec 12 07:49:17 CET 2014


On 2014/12/12 1:51, r k wrote:
Thomas, Michael,

Wouldn't it cause unaligned memory access (new changes as well as the previous code)? Wondering if get_unaligned/put_unaligned macros similar to the ones used in kernel be ported to user-space?


I think it will not, as all buf point to are struct udp_hdr/struct tcp_hdr/struct ipv6_psd_header/struct ipv4_psd_header, they are all aligned with uint16_t.

Thanks
Michael
Thanks,
Ravi

On Wed, Dec 10, 2014 at 4:54 PM, Thomas Monjalon <thomas.monjalon at 6wind.com<mailto:thomas.monjalon at 6wind.com>> 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 *'.
> >
> > This patch is one workaround fix.
> >
> > Signed-off-by: Michael Qiu <michael.qiu at intel.com<mailto:michael.qiu at intel.com>>
> > ---
> > v3 --> v2:
> >     use uintptr_t instead of unsigned long to
> >     save pointer.
> >
> > v2 --> v1:
> >     Workaround solution instead of shut off the
> >     gcc params.
>
> This workaround is to solve the compile issue of GCC strict-aliasing(Two
> different type pointers should not be point to the same memory address).
>
> For GCC 4.4.7 it will definitely occurs if  flags "-fstrict-aliasing"
> and "-Wall" used.

Acked-by: Thomas Monjalon <thomas.monjalon at 6wind.com<mailto:thomas.monjalon at 6wind.com>>>

Applied with a comment in the code.

Thanks
--
Thomas



More information about the dev mailing list