[dpdk-dev] examples/ip_pipeline: Fix compile issue with strict-aliasing

Message ID 1449650666-26067-1-git-send-email-michael.qiu@intel.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Michael Qiu Dec. 9, 2015, 8:44 a.m. UTC
  Compile ip_pipeline in CentOS 6.5 with kernel 2.6.32-431
GCC 4.4.7, will lead below error:

    pipeline_routing_be.c: In function ‘pipeline_routing_msg_req_arp_add_handler’:
    pipeline_routing_be.c:1817: error: dereferencing pointer ‘({anonymous})’
				does break strict-aliasing rules

This because the code break strict-aliasing rule.
The patch solve this issue.

Fixes: 0ae7275810f1 (examples/ip_pipeline: add more functions to routing pipeline)

Signed-off-by: Michael Qiu <michael.qiu@intel.com>
---
 examples/ip_pipeline/pipeline/pipeline_routing_be.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
  

Comments

Jasvinder Singh Dec. 9, 2015, 9:22 a.m. UTC | #1
> -----Original Message-----

> From: Qiu, Michael

> Sent: Wednesday, December 9, 2015 8:44 AM

> To: dev@dpdk.org

> Cc: Singh, Jasvinder; Dumitrescu, Cristian; Qiu, Michael

> Subject: [PATCH] examples/ip_pipeline: Fix compile issue with strict-aliasing

> 

> Compile ip_pipeline in CentOS 6.5 with kernel 2.6.32-431 GCC 4.4.7, will lead

> below error:

> 

>     pipeline_routing_be.c: In function

> ‘pipeline_routing_msg_req_arp_add_handler’:

>     pipeline_routing_be.c:1817: error: dereferencing pointer ‘({anonymous})’

> 				does break strict-aliasing rules

> 

> This because the code break strict-aliasing rule.

> The patch solve this issue.

> 

> Fixes: 0ae7275810f1 (examples/ip_pipeline: add more functions to routing

> pipeline)

> 

> Signed-off-by: Michael Qiu <michael.qiu@intel.com>


Acked-by: Jasvinder Singh <jasvinder.singh@intel.com>
  
Thomas Monjalon Dec. 9, 2015, 8:38 p.m. UTC | #2
> > Compile ip_pipeline in CentOS 6.5 with kernel 2.6.32-431 GCC 4.4.7, will lead
> > below error:
> > 
> >     pipeline_routing_be.c: In function
> > ‘pipeline_routing_msg_req_arp_add_handler’:
> >     pipeline_routing_be.c:1817: error: dereferencing pointer ‘({anonymous})’
> > 				does break strict-aliasing rules
> > 
> > This because the code break strict-aliasing rule.
> > The patch solve this issue.
> > 
> > Fixes: 0ae7275810f1 (examples/ip_pipeline: add more functions to routing
> > pipeline)
> > 
> > Signed-off-by: Michael Qiu <michael.qiu@intel.com>
> 
> Acked-by: Jasvinder Singh <jasvinder.singh@intel.com>

Applied, thanks
  

Patch

diff --git a/examples/ip_pipeline/pipeline/pipeline_routing_be.c b/examples/ip_pipeline/pipeline/pipeline_routing_be.c
index 4a95c7d..9baabd0 100644
--- a/examples/ip_pipeline/pipeline/pipeline_routing_be.c
+++ b/examples/ip_pipeline/pipeline/pipeline_routing_be.c
@@ -1461,8 +1461,7 @@  pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg)
 		uint64_t macaddr_dst;
 		uint64_t ethertype = ETHER_TYPE_IPv4;
 
-		*((struct ether_addr *) &macaddr_dst) =
-			req->data.ethernet.macaddr;
+		macaddr_dst = *((uint64_t *)&(req->data.ethernet.macaddr));
 		macaddr_dst = rte_bswap64(macaddr_dst << 16);
 
 		entry_arp0.slab[0] =
@@ -1503,8 +1502,7 @@  pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg)
 		uint64_t svlan = req->data.l2.qinq.svlan;
 		uint64_t cvlan = req->data.l2.qinq.cvlan;
 
-		*((struct ether_addr *) &macaddr_dst) =
-			req->data.ethernet.macaddr;
+		macaddr_dst = *((uint64_t *)&(req->data.ethernet.macaddr));
 		macaddr_dst = rte_bswap64(macaddr_dst << 16);
 
 		entry_arp0.slab[0] = rte_bswap64((svlan << 48) |
@@ -1563,8 +1561,7 @@  pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg)
 		uint64_t label3 = req->data.l2.mpls.labels[3];
 		uint32_t n_labels = req->data.l2.mpls.n_labels;
 
-		*((struct ether_addr *) &macaddr_dst) =
-			req->data.ethernet.macaddr;
+		macaddr_dst = *((uint64_t *)&(req->data.ethernet.macaddr));
 		macaddr_dst = rte_bswap64(macaddr_dst << 16);
 
 		switch (n_labels) {
@@ -1814,7 +1811,7 @@  pipeline_routing_msg_req_arp_add_handler(struct pipeline *p, void *msg)
 		return rsp;
 	}
 
-	*((struct ether_addr *) &entry.macaddr) = req->macaddr;
+	entry.macaddr = *((uint64_t *)&(req->macaddr));
 	entry.macaddr = entry.macaddr << 16;
 
 	rsp->status = rte_pipeline_table_entry_add(p->p,