libbpf: avoid inline hint definition from 'linux/stddef.h'
Subsystems (4)
PATCH 1/1 libbpf: avoid inline hint definition from 'linux/stddef.h'
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.
This change now enforces the proper definition for BPF programs regardless of the include order.
--- tools/lib/bpf/bpf_helpers.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/lib/bpf/bpf_helpers.h +5 -2
@@ -29,9 +29,12 @@*/ #define SEC (NAME ) __attribute__((section(NAME), used)) -#ifndef __always_inline +/* +* Avoid 'linux/stddef.h' definition of '__always_inline'. +*/ +#undef __always_inline#define __always_inline inline __attribute__((always_inline)) -#endif +#ifndef __noinline#define __noinline __attribute__((noinline))#endif
Signature · 1 line
2.25.1
Daniel Borkmann
maintainerQuoted 9 lines · Pedro Tammela
Linux headers might pull '
linux/stddef.h' which defines '__always_inline' as the following:#ifndef __always_inline #define __always_inline __inline__ #endifThis 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.
Quoted 13 lines
This change now enforces the proper definition for BPF programs regardless of the include order.
Signed-off-by Pedro Tammela <[email protected]>--- tools/lib/bpf/bpf_helpers.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)tools/lib/bpf/bpf_helpers.h +0
-0
tools/lib/bpf/bpf_helpers.h line 34
Quoted 7 lines
tools/lib/bpf/bpf_helpers.h +3
-1@@ -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.
Quoted 8 lines
tools/lib/bpf/bpf_helpers.h +2
-1+#undef __always_inline#define __always_inline inline __attribute__((always_inline)) -#endif +#ifndef __noinline#define __noinline __attribute__((noinline))#endif
Quoted 9 lines · Daniel Borkmann
Quoted 7 lines · Pedro Tammela
Linux headers might pull '
linux/stddef.h' which defines '__always_inline' as the following:#ifndef __always_inline #define __always_inline __inline__ #endif
Quoted 5 lines
Quoted 2 lines
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.
It's an UAPI header, so why not? Is there anything special about stddef.h that makes it unsuitable to be included?
Quoted 17 lines
Quoted 17 lines
This change now enforces the proper definition for BPF programs regardless of the include order.
Signed-off-by Pedro Tammela <[email protected]>--- tools/lib/bpf/bpf_helpers.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)tools/lib/bpf/bpf_helpers.h +0
-0@@ -29,9 +29,12 @@*/ #define SEC (NAME ) __attribute__((section(NAME), used))
Quoted 9 lines
tools/lib/bpf/bpf_helpers.h line 34
Quoted 4 lines
tools/lib/bpf/bpf_helpers.h +3
-1-#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.
So for whatever reason commit bot didn't send notification, but I've already landed this yesterday. To me, with #undef + #define it's pretty clear that we "force-define" __always_inline exactly how we want it, but we can certainly add clarifying comment in the follow up, if you think it's needed.
Quoted 10 lines
Quoted 9 lines
tools/lib/bpf/bpf_helpers.h +2
-1+#undef __always_inline#define __always_inline inline __attribute__((always_inline)) -#endif +#ifndef __noinline#define __noinline __attribute__((noinline))#endif
Daniel Borkmann
maintainerQuoted 9 lines · Andrii Nakryiko
Quoted 8 lines · Daniel Borkmann
Quoted 7 lines · Pedro Tammela
Linux headers might pull '
linux/stddef.h' which defines '__always_inline' as the following:#ifndef __always_inline #define __always_inline __inline__ #endif
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
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.It's an UAPI header, so why not? Is there anything special about
stddef.hthat makes it unsuitable to be included?
Hm, fair enough, looks like linux/types.h already pulls it in, so no. We defined our own stddef.h longer time ago, so looks like we never ran into this issue.
Quoted 26 lines
Quoted 16 lines
Quoted 16 lines
This change now enforces the proper definition for BPF programs regardless of the include order.
Signed-off-by Pedro Tammela <[email protected]>--- tools/lib/bpf/bpf_helpers.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)tools/lib/bpf/bpf_helpers.h +0
-0@@ -29,9 +29,12 @@*/ #define SEC (NAME ) __attribute__((section(NAME), used))Quoted 9 lines
tools/lib/bpf/bpf_helpers.h line 34
Quoted 4 lines
tools/lib/bpf/bpf_helpers.h +3
-1-#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.
Quoted 5 lines
So for whatever reason commit bot didn't send notification, but I've already landed this yesterday. To me, with #undef + #define it's pretty clear that we "force-define"
__always_inlineexactly how we want it, but we can certainly add clarifying comment in the follow up, if you think it's needed.
Up to you, but given you applied it it's probably not worth the trouble; missed it earlier given I didn't see the patchbot message in the thread initially. :/
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
tools/lib/bpf/bpf_helpers.h +2
-1+#undef __always_inline#define __always_inline inline __attribute__((always_inline)) -#endif +#ifndef __noinline#define __noinline __attribute__((noinline))#endif