Subject: [PATCH 2/3] selftests/bpf: test_xdp_noinline.c: fix 'noinline' macro expansion

From: Sirio Balmelli <[email-masked]>
Date: Thu, 26 Apr 2018 10:31:28 +0200

Compiling with clang 7.0.0 yields:
test_xdp_noinline.c:470:24: warning: unknown attribute '__attribute__' ignored [-Wunknown-attributes]
../../../include/linux/compiler-gcc.h:24:19: note: expanded from macro 'noinline'
                        ^
test_xdp_noinline.c:494:24: error: use of undeclared identifier 'noinline'; did you mean 'inline'?
static __attribute__ ((noinline))

This appears to be the 'noinline' attribute being itself macro-expanded,
so the compiler sees '__attribute__ ((__attribute__((noinline))))'.

Fix using an #ifndef.
Homogenize function declarations.

Signed-off-by: Sirio Balmelli <[email-masked]>
---
 tools/testing/selftests/bpf/test_xdp_noinline.c | 79 +++++++++++++------------
 1 file changed, 42 insertions(+), 37 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_xdp_noinline.c b/tools/testing/selftests/bpf/test_xdp_noinline.c
index 5e4aac7..5b5f3f2 100644
--- a/tools/testing/selftests/bpf/test_xdp_noinline.c
+++ b/tools/testing/selftests/bpf/test_xdp_noinline.c
@@ -15,6 +15,11 @@
 #include <linux/udp.h>
 #include "bpf_helpers.h"
 
+/* some compiler-specific header might define this */
+#ifndef noinline
+#define noinline (__attribute__ ((noinline)))
+#endif
+
 #define bpf_printk(fmt, ...)				\
 ({							\
 	char ____fmt[] = fmt;				\
@@ -55,7 +60,7 @@ static __u32 rol32(__u32 word, unsigned int shift)
 
 typedef unsigned int u32;
 
-static __attribute__ ((noinline))
+static noinline
 u32 jhash(const void *key, u32 length, u32 initval)
 {
 	u32 a, b, c;
@@ -92,7 +97,7 @@ u32 jhash(const void *key, u32 length, u32 initval)
 	return c;
 }
 
-static __attribute__ ((noinline))
+static noinline
 u32 __jhash_nwords(u32 a, u32 b, u32 c, u32 initval)
 {
 	a += initval;
@@ -102,7 +107,7 @@ u32 __jhash_nwords(u32 a, u32 b, u32 c, u32 initval)
 	return c;
 }
 
-static __attribute__ ((noinline))
+static noinline
 u32 jhash_2words(u32 a, u32 b, u32 initval)
 {
 	return __jhash_nwords(a, b, 0, initval + JHASH_INITVAL + (2 << 2));
@@ -239,7 +244,7 @@ static inline __u64 calc_offset(bool is_ipv6, bool is_icmp)
 	return off;
 }
 
-static __attribute__ ((noinline))
+static noinline
 bool parse_udp(void *data, void *data_end,
 	       bool is_ipv6, struct packet_description *pckt)
 {
@@ -261,7 +266,7 @@ bool parse_udp(void *data, void *data_end,
 	return 1;
 }
 
-static __attribute__ ((noinline))
+static noinline
 bool parse_tcp(void *data, void *data_end,
 	       bool is_ipv6, struct packet_description *pckt)
 {
@@ -285,7 +290,7 @@ bool parse_tcp(void *data, void *data_end,
 	return 1;
 }
 
-static __attribute__ ((noinline))
+static noinline
 bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
 	      struct packet_description *pckt,
 	      struct real_definition *dst, __u32 pkt_bytes)
@@ -328,7 +333,7 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
 	return 1;
 }
 
-static __attribute__ ((noinline))
+static noinline
 bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
 	      struct packet_description *pckt,
 	      struct real_definition *dst, __u32 pkt_bytes)
@@ -382,7 +387,7 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
 	return 1;
 }
 
-static __attribute__ ((noinline))
+static noinline
 bool decap_v6(struct xdp_md *xdp, void **data, void **data_end, bool inner_v4)
 {
 	struct eth_hdr *new_eth;
@@ -403,7 +408,7 @@ bool decap_v6(struct xdp_md *xdp, void **data, void **data_end, bool inner_v4)
 	return 1;
 }
 
-static __attribute__ ((noinline))
+static noinline
 bool decap_v4(struct xdp_md *xdp, void **data, void **data_end)
 {
 	struct eth_hdr *new_eth;
@@ -421,7 +426,7 @@ bool decap_v4(struct xdp_md *xdp, void **data, void **data_end)
 	return 1;
 }
 
-static __attribute__ ((noinline))
+static noinline
 int swap_mac_and_send(void *data, void *data_end)
 {
 	unsigned char tmp_mac[6];
@@ -434,7 +439,7 @@ int swap_mac_and_send(void *data, void *data_end)
 	return XDP_TX;
 }
 
-static __attribute__ ((noinline))
+static noinline
 int send_icmp_reply(void *data, void *data_end)
 {
 	struct icmphdr *icmp_hdr;
@@ -467,7 +472,7 @@ int send_icmp_reply(void *data, void *data_end)
 	return swap_mac_and_send(data, data_end);
 }
 
-static __attribute__ ((noinline))
+static noinline
 int send_icmp6_reply(void *data, void *data_end)
 {
 	struct icmp6hdr *icmp_hdr;
@@ -491,7 +496,7 @@ int send_icmp6_reply(void *data, void *data_end)
 	return swap_mac_and_send(data, data_end);
 }
 
-static __attribute__ ((noinline))
+static noinline
 int parse_icmpv6(void *data, void *data_end, __u64 off,
 		 struct packet_description *pckt)
 {
@@ -516,7 +521,7 @@ int parse_icmpv6(void *data, void *data_end, __u64 off,
 	return -1;
 }
 
-static __attribute__ ((noinline))
+static noinline
 int parse_icmp(void *data, void *data_end, __u64 off,
 	       struct packet_description *pckt)
 {
@@ -543,7 +548,7 @@ int parse_icmp(void *data, void *data_end, __u64 off,
 	return -1;
 }
 
-static __attribute__ ((noinline))
+static noinline
 __u32 get_packet_hash(struct packet_description *pckt,
 		      bool hash_16bytes)
 {
@@ -555,11 +560,11 @@ __u32 get_packet_hash(struct packet_description *pckt,
 				    24);
 }
 
-__attribute__ ((noinline))
-static bool get_packet_dst(struct real_definition **real,
-			   struct packet_description *pckt,
-			   struct vip_meta *vip_info,
-			   bool is_ipv6, void *lru_map)
+static noinline
+bool get_packet_dst(struct real_definition **real,
+		    struct packet_description *pckt,
+		    struct vip_meta *vip_info,
+		    bool is_ipv6, void *lru_map)
 {
 	struct real_pos_lru new_dst_lru = { };
 	bool hash_16bytes = is_ipv6;
@@ -608,10 +613,10 @@ static bool get_packet_dst(struct real_definition **real,
 	return 1;
 }
 
-__attribute__ ((noinline))
-static void connection_table_lookup(struct real_definition **real,
-				    struct packet_description *pckt,
-				    void *lru_map)
+static noinline
+void connection_table_lookup(struct real_definition **real,
+			     struct packet_description *pckt,
+			     void *lru_map)
 {
 
 	struct real_pos_lru *dst_lru;
@@ -635,11 +640,11 @@ static void connection_table_lookup(struct real_definition **real,
  * below function has 6 arguments whereas bpf and llvm allow maximum of 5
  * but since it's _static_ llvm can optimize one argument away
  */
-__attribute__ ((noinline))
-static int process_l3_headers_v6(struct packet_description *pckt,
-				 __u8 *protocol, __u64 off,
-				 __u16 *pkt_bytes, void *data,
-				 void *data_end)
+static noinline
+int process_l3_headers_v6(struct packet_description *pckt,
+			  __u8 *protocol, __u64 off,
+			  __u16 *pkt_bytes, void *data,
+			  void *data_end)
 {
 	struct ipv6hdr *ip6h;
 	__u64 iph_len;
@@ -666,11 +671,11 @@ static int process_l3_headers_v6(struct packet_description *pckt,
 	return -1;
 }
 
-__attribute__ ((noinline))
-static int process_l3_headers_v4(struct packet_description *pckt,
-				 __u8 *protocol, __u64 off,
-				 __u16 *pkt_bytes, void *data,
-				 void *data_end)
+static noinline
+int process_l3_headers_v4(struct packet_description *pckt,
+			  __u8 *protocol, __u64 off,
+			  __u16 *pkt_bytes, void *data,
+			  void *data_end)
 {
 	struct iphdr *iph;
 	__u64 iph_len;
@@ -698,9 +703,9 @@ static int process_l3_headers_v4(struct packet_description *pckt,
 	return -1;
 }
 
-__attribute__ ((noinline))
-static int process_packet(void *data, __u64 off, void *data_end,
-			  bool is_ipv6, struct xdp_md *xdp)
+static inline
+int process_packet(void *data, __u64 off, void *data_end,
+		   bool is_ipv6, struct xdp_md *xdp)
 {
 
 	struct real_definition *dst = NULL;
-- 
2.7.4