From: "Ananyev, Konstantin" <konstantin.ananyev@intel.com>
To: "Mrzyglod, DanielX T" <danielx.t.mrzyglod@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing
Date: Wed, 25 Nov 2015 17:13:51 +0000 [thread overview]
Message-ID: <2601191342CEEE43887BDE71AB97725836ACD3D6@irsmsx105.ger.corp.intel.com> (raw)
In-Reply-To: <7ADD74816B4C8A45B56203CBA65FE5A61D98EAE5@IRSMSX107.ger.corp.intel.com>
> -----Original Message-----
> From: Mrzyglod, DanielX T
> Sent: Wednesday, November 25, 2015 5:07 PM
> To: Ananyev, Konstantin
> Cc: dev@dpdk.org
> Subject: RE: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing
>
> If we change input buf:
> xapp-gcc/include/rte_ip.h:211: error: dereferencing pointer 'u16' does break strict-aliasing rules
> /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:204: note: initialized from here
> /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:212: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules
> /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:212: note: initialized from here
> /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:213: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules
> /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:213: note: initialized from here
> /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:214: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules
> /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_ip.h:214: note: initialized from here
>
> The change was pointed out by Michael Qiu in patch: 2b039d5f20a34016ecaf9b26f8f8b6c4a81bf4b6
>
> We can only cast void to uint8 but it would involve big endian/ little endian macros:
>
> static inline uint32_t __attribute__((__may_alias__))
> __rte_raw_cksum(const void *buf, size_t len, uint32_t sum)
> {
> /* workaround gcc strict-aliasing warning */
> const uint8_t *u8 = ((const uint8_t *)buf);
> while (len >= (sizeof(*u8) * 8)) {
> sum += *(u8+1) << 8 | *(u8);
> sum += *(u8+3) << 8 | *(u8+2);
> sum += *(u8+5) << 8 | *(u8+4);
> sum += *(u8+7) << 8 | *(u8+6);
>
> len -= sizeof(*u8) * 8;
> u8 += 8;
> }
>
> while (len >= 2*sizeof(*u8)) {
> sum += *u8 << 8 | *(u8+1);
> len -= 2*sizeof(*u8);
> u8 += 2;
> }
>
> /* if length is in odd bytes */
> if (len == 1)
> sum += *((const uint8_t *)u8);
>
> return sum;
> }
So I misinterpreted gcc manual: it only allows conversion from any other type to char, not visa-versa.
Sorry for wrong suggestion.
>
> I will research about this union usage suggested by Stephen, but for this moment local typedef & __attribute__((__may_alias__)) is the
> most clean solution which work under gcc(4.4.7), clang, icc.
Ok, if there is no other known way - let's stick with your original patch.
Konstantin
>
> >-----Original Message-----
> >From: Ananyev, Konstantin
> >Sent: Tuesday, November 24, 2015 6:58 PM
> >To: Mrzyglod, DanielX T <danielx.t.mrzyglod@intel.com>
> >Cc: dev@dpdk.org
> >Subject: RE: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing
> >
> >Hi Daniel,
> >So for my own curiosity: what went wrong here?
> >Did compiler avoid to generate a code for while {} loop?
> >Or something else?
> >BTW, it is an internal function, so instead of introducing new typedef,
> >we can just change the type of buf?
> >Let say to uint8_t *?
> >From gcc manual page: " A character type may alias any other type."
> >Would that work?
> >Konstantin
> >
> >> -----Original Message-----
> >> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Daniel Mrzyglod
> >> Sent: Tuesday, November 24, 2015 4:31 PM
> >> To: dev@dpdk.org
> >> Subject: [dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing
> >>
> >> This fix is for IPv6 checksum offload error on RHEL65.
> >> Any optimalisation above -O0 provide error in IPv6 checksum
> >> flag "-fstrict-aliasing" is default for optimalisation above -O0.
> >>
> >> Fixes: 2b039d5f20a3 ("net: fix build with gcc 4.4.7 and strict aliasing")
> >>
> >> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> >> ---
> >> lib/librte_net/rte_ip.h | 3 ++-
> >> 1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
> >> index 71c519a..5b7554a 100644
> >> --- a/lib/librte_net/rte_ip.h
> >> +++ b/lib/librte_net/rte_ip.h
> >> @@ -169,7 +169,8 @@ __rte_raw_cksum(const void *buf, size_t len, uint32_t
> >sum)
> >> {
> >> /* workaround gcc strict-aliasing warning */
> >> uintptr_t ptr = (uintptr_t)buf;
> >> - const uint16_t *u16 = (const uint16_t *)ptr;
> >> + typedef uint16_t __attribute__((__may_alias__)) u16_p;
> >> + const u16_p *u16 = (const u16_p *)ptr;
> >>
> >> while (len >= (sizeof(*u16) * 4)) {
> >> sum += u16[0];
> >> --
> >> 2.5.0
next prev parent reply other threads:[~2015-11-25 17:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-24 15:12 [dpdk-dev] [PATCH] " Daniel Mrzyglod
2015-11-24 15:47 ` Mrzyglod, DanielX T
2015-11-24 15:49 ` Bruce Richardson
2015-11-24 16:31 ` [dpdk-dev] [PATCH v2] " Daniel Mrzyglod
2015-11-24 16:31 ` Daniel Mrzyglod
2015-11-24 17:58 ` Ananyev, Konstantin
2015-11-25 17:06 ` Mrzyglod, DanielX T
2015-11-25 17:13 ` Ananyev, Konstantin [this message]
2015-11-24 22:42 ` Stephen Hemminger
2015-11-25 18:00 ` [dpdk-dev] [PATCH] " Ananyev, Konstantin
2015-11-25 20:58 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2601191342CEEE43887BDE71AB97725836ACD3D6@irsmsx105.ger.corp.intel.com \
--to=konstantin.ananyev@intel.com \
--cc=danielx.t.mrzyglod@intel.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).