Re: [PATCH] libbpf: avoid inline hint definition from 'linux/stddef.h'

From: Daniel Borkmann
Date: Tue Mar 16 2021 - 17:02:47 EST


On 3/14/21 6:38 PM, Pedro Tammela wrote:
Linux headers might pull 'linux/stddef.h' which defines
'__always_inline' as the following:

#ifndef __always_inline
#define __always_inline __inline__
#endif

This becomes an issue if the program picks up the 'linux/stddef.h'
definition as the macro now just hints inline to clang.

How did the program end up including linux/stddef.h ? Would be good to
also have some more details on how we got here for the commit desc.

This change now enforces the proper definition for BPF programs
regardless of the include order.

Signed-off-by: Pedro Tammela <pctammela@xxxxxxxxx>
---
tools/lib/bpf/bpf_helpers.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h
index ae6c975e0b87..5fa483c0b508 100644
--- a/tools/lib/bpf/bpf_helpers.h
+++ b/tools/lib/bpf/bpf_helpers.h
@@ -29,9 +29,12 @@
*/
#define SEC(NAME) __attribute__((section(NAME), used))
-#ifndef __always_inline
+/*
+ * Avoid 'linux/stddef.h' definition of '__always_inline'.
+ */

I think the comment should have more details on 'why' we undef it as in
few months looking at it again, the next question to dig into would be
what was wrong with linux/stddef.h. Providing a better rationale would
be nice for readers here.

+#undef __always_inline
#define __always_inline inline __attribute__((always_inline))
-#endif
+
#ifndef __noinline
#define __noinline __attribute__((noinline))
#endif