Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Disable SEC pragma macro on GCC

It seems the gcc preprocessor breaks with pragmas when surrounding
__attribute__.

Disable these pragmas on GCC due to upstream bugs see:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90400

Fixes errors like:
error: expected identifier or '(' before '#pragma'
106 | SEC("cgroup/bind6")
| ^~~

error: expected '=', ',', ';', 'asm' or '__attribute__' before '#pragma'
114 | char _license[] SEC("license") = "GPL";
| ^~~

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220706111839.1247911-1-james.hilliard1@gmail.com

authored by

James Hilliard and committed by
Andrii Nakryiko
18410251 d1a6edec

+13
+13
tools/lib/bpf/bpf_helpers.h
··· 22 22 * To allow use of SEC() with externs (e.g., for extern .maps declarations), 23 23 * make sure __attribute__((unused)) doesn't trigger compilation warning. 24 24 */ 25 + #if __GNUC__ && !__clang__ 26 + 27 + /* 28 + * Pragma macros are broken on GCC 29 + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578 30 + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90400 31 + */ 32 + #define SEC(name) __attribute__((section(name), used)) 33 + 34 + #else 35 + 25 36 #define SEC(name) \ 26 37 _Pragma("GCC diagnostic push") \ 27 38 _Pragma("GCC diagnostic ignored \"-Wignored-attributes\"") \ 28 39 __attribute__((section(name), used)) \ 29 40 _Pragma("GCC diagnostic pop") \ 41 + 42 + #endif 30 43 31 44 /* Avoid 'linux/stddef.h' definition of '__always_inline'. */ 32 45 #undef __always_inline