libbpf: Fix GCC #pragma usage in libbpf_utils.c
PATCH 1/1 libbpf: Fix GCC #pragma usage in libbpf_utils.c
The recent sha256 patch uses a GCC pragma to suppress compile errors for a packed struct, but omits a needed pragma (see related link) and thus still raises errors: (e.g. on GCC 12.3 armhf)
libbpf_utils.c:153:29: error: packed attribute causes inefficient alignment for ‘__val’ [-Werror=attributes]
153 | struct __packed_u32 { __u32 __val; } __attribute__((packed));
| ^~~~~
Resolve by adding the GCC diagnostic pragma to ignore "-Wattributes".
--- tools/lib/bpf/libbpf_utils.c | 1 + 1 file changed, 1 insertion(+)
tools/lib/bpf/libbpf_utils.c +1 -0
@@ -150,6 +150,7 @@ const char *libbpf_errstr(int err)#pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wpacked" +#pragma GCC diagnostic ignored "-Wattributes"struct __packed_u32 {__u32 __val; } __attribute__((packed));#pragma GCC diagnostic pop
Signature · 1 line
2.34.1
Quoted 11 lines · Tony Ambardar
The recent sha256 patch uses a GCC pragma to suppress compile errors for a packed struct, but omits a needed pragma (see related link) and thus still raises errors: (e.g. on GCC 12.3 armhf)
libbpf_utils.c:153:29: error: packed attribute causes inefficient alignment for ‘__val’ [-Werror=attributes]
153 | struct__packed_u32{__u32__val; } __attribute__((packed));
| ^~~~~Resolve by adding the GCC diagnostic pragma to ignore "-Wattributes".
Quoted 7 lines
Fixes 4a1c9e544b8d ("libbpf: remove linux/unaligned.h dependency for libbpf_sha256()")Signed-off-by Tony Ambardar <[email protected]>--- tools/lib/bpf/libbpf_utils.c | 1 + 1 file changed, 1 insertion(+)
let's make compiler happy, thanks
Quoted 16 lines
tools/lib/bpf/libbpf_utils.c +1
-1@@ -150,6 +150,7 @@ const char *libbpf_errstr(int err)#pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wpacked" +#pragma GCC diagnostic ignored "-Wattributes"struct __packed_u32 {__u32 __val; } __attribute__((packed));#pragma GCC diagnostic pop --2.34.1
Eduard Zingerman
maintainerQuoted 9 lines · Tony Ambardar
The recent sha256 patch uses a GCC pragma to suppress compile errors for a packed struct, but omits a needed pragma (see related link) and thus still raises errors: (e.g. on GCC 12.3 armhf)
libbpf_utils.c:153:29: error: packed attribute causes inefficient alignment for ‘__val’ [-Werror=attributes]
153 | struct__packed_u32{__u32__val; } __attribute__((packed));
| ^~~~~Resolve by adding the GCC diagnostic pragma to ignore "-Wattributes".
Hm, I compiled this locally using GCC 15.1.1 on x86 and didn't see this warning. Is this an arm specific warning?
Quoted 20 lines
Fixes 4a1c9e544b8d ("libbpf: remove linux/unaligned.h dependency for libbpf_sha256()")Signed-off-by Tony Ambardar <[email protected]>--- tools/lib/bpf/libbpf_utils.c | 1 + 1 file changed, 1 insertion(+)tools/lib/bpf/libbpf_utils.c +1
-0@@ -150,6 +150,7 @@ const char *libbpf_errstr(int err)#pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wpacked" +#pragma GCC diagnostic ignored "-Wattributes"struct __packed_u32 {__u32 __val; } __attribute__((packed));#pragma GCC diagnostic pop
Quoted 5 lines · Eduard Zingerman
Quoted 4 lines · Tony Ambardar
The recent sha256 patch uses a GCC pragma to suppress compile errors for a packed struct, but omits a needed pragma (see related link) and thus still raises errors: (e.g. on GCC 12.3 armhf)
Quoted 9 lines
Quoted 5 lines
libbpf_utils.c:153:29: error: packed attribute causes inefficient alignment for ‘__val’ [-Werror=attributes]
153 | struct__packed_u32{__u32__val; } __attribute__((packed));
| ^~~~~Resolve by adding the GCC diagnostic pragma to ignore "-Wattributes".
Hm, I compiled this locally using GCC 15.1.1 on x86 and didn't see this warning. Is this an arm specific warning?
I also tried building with x86_64 gcc 12.3 and didn't encounter the error, so may well be a GCC/arm thing. And when I followed the thread linked below I found only expired links for the original 'perf' test artifacts, without any arch info I could find...
Quoted 20 lines
Quoted 20 lines
Fixes 4a1c9e544b8d ("libbpf: remove linux/unaligned.h dependency for libbpf_sha256()")Signed-off-by Tony Ambardar <[email protected]>--- tools/lib/bpf/libbpf_utils.c | 1 + 1 file changed, 1 insertion(+)tools/lib/bpf/libbpf_utils.c +1
-0@@ -150,6 +150,7 @@ const char *libbpf_errstr(int err)#pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wpacked" +#pragma GCC diagnostic ignored "-Wattributes"struct __packed_u32 {__u32 __val; } __attribute__((packed));#pragma GCC diagnostic pop
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Thu, 2 Oct 2025 13:31:50 -0700 you wrote:
The recent sha256 patch uses a GCC pragma to suppress compile errors for a packed struct, but omits a needed pragma (see related link) and thus still raises errors: (e.g. on GCC 12.3 armhf)
libbpf_utils.c:153:29: error: packed attribute causes inefficient alignment for ‘__val’ [-Werror=attributes]
153 | struct__packed_u32{__u32__val; } __attribute__((packed));
| ^~~~~[...]
Here is the summary with links:
- [bpf,v1] libbpf: Fix GCC #pragma usage in libbpf_utils.c
https://git.kernel.org/bpf/bpf/c/63d2247e2e37
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html