From fc15f3fae967da43165801fda900b7faa5666058 Mon Sep 17 00:00:00 2001 From: zhang-mingyi66 Date: Sun, 26 Feb 2023 01:06:28 +0800 Subject: [PATCH] [Patch]libbpf:Disable SEC pragma macro on GCC (cherry picked from commit b9924081fdf6335ab9a5d47db17256c1d6521d64) --- ...bbpf-Disable-SEC-pragma-macro-on-GCC.patch | 61 +++++++++++++++++++ libbpf.spec | 6 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 backport-libbpf-Disable-SEC-pragma-macro-on-GCC.patch diff --git a/backport-libbpf-Disable-SEC-pragma-macro-on-GCC.patch b/backport-libbpf-Disable-SEC-pragma-macro-on-GCC.patch new file mode 100644 index 0000000..cb6ab76 --- /dev/null +++ b/backport-libbpf-Disable-SEC-pragma-macro-on-GCC.patch @@ -0,0 +1,61 @@ +From b31ca3fa0e62fde6aa66f855136e29e088ad9dde Mon Sep 17 00:00:00 2001 +From: James Hilliard +Date: Wed, 6 Jul 2022 05:18:38 -0600 +Subject: [PATCH] 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 +Signed-off-by: Andrii Nakryiko +Link: https://lore.kernel.org/bpf/20220706111839.1247911-1-james.hilliard1@gmail.com +--- + src/bpf_helpers.h | 13 +++++++++++++ + 1 file changed, 13 insertions(+) + +diff --git a/src/bpf_helpers.h b/src/bpf_helpers.h +index fb04eaf..7349b16 100644 +--- a/src/bpf_helpers.h ++++ b/src/bpf_helpers.h +@@ -22,12 +22,25 @@ + * To allow use of SEC() with externs (e.g., for extern .maps declarations), + * make sure __attribute__((unused)) doesn't trigger compilation warning. + */ ++#if __GNUC__ && !__clang__ ++ ++/* ++ * Pragma macros are broken on GCC ++ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578 ++ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90400 ++ */ ++#define SEC(name) __attribute__((section(name), used)) ++ ++#else ++ + #define SEC(name) \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wignored-attributes\"") \ + __attribute__((section(name), used)) \ + _Pragma("GCC diagnostic pop") \ + ++#endif ++ + /* Avoid 'linux/stddef.h' definition of '__always_inline'. */ + #undef __always_inline + #define __always_inline inline __attribute__((always_inline)) +-- +2.33.0 + diff --git a/libbpf.spec b/libbpf.spec index b4bf454..c31417b 100644 --- a/libbpf.spec +++ b/libbpf.spec @@ -4,7 +4,7 @@ Name: %{githubname} Version: %{githubver} -Release: 3 +Release: 4 Summary: Libbpf library License: LGPLv2 or BSD @@ -16,6 +16,7 @@ Patch0000: backport-libbpf-Fix-determine_ptr_size-guessing.patch Patch0001: backport-libbpf-preserve-errno-across-pr_warn-pr_info-pr_debug.patch Patch0002: backport-libbpf-Ensure-functions-with-always_inline-attribute-are-inline.patch Patch0003: backport-libbpf-Fix-the-name-of-a-reused-map.patch +Patch0004: backport-libbpf-Disable-SEC-pragma-macro-on-GCC.patch # This package supersedes libbpf from kernel-tools, # which has default Epoch: 0. By having Epoch: 1 # this libbpf will take over smoothly @@ -67,6 +68,9 @@ developing applications that use %{name} %{_libdir}/libbpf.a %changelog +* Thu Mar 2 2023 zhangmingyi - 2:0.8.1-4 +- backporting: backport-libbpf-Disable-SEC-pragma-macro-on-GCC.patch + * Fri Jan 6 2023 zhangmingyi - 2:0.8.1-3 -- backporting: backport-libbpf-Ensure-functions-with-always_inline-attribute-are-inline.patch backport-libbpf-Fix-the-name-of-a-reused-map.patch -- Gitee