Skip to contentSkip to conversation

libbpf: Fix GCC #pragma usage in libbpf_utils.c

PATCH Applied Tony Ambardar 4 participants 5 messages Oct 2, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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".

Fixes 4a1c9e544b8d ("libbpf: remove linux/unaligned.h dependency for libbpf_sha256()")
---
 tools/lib/bpf/libbpf_utils.c | 1 +
 1 file changed, 1 insertion(+)
tools/lib/bpf/libbpf_utils.c +1 -0
index 2bae8cafc077..5d66bc6ff098 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
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()")
---
 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
index 2bae8cafc077..5d66bc6ff098 100644
@@ -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

maintainer
#2 lore raw
In reply to Tony Ambardar
Quoted 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()")
---
 tools/lib/bpf/libbpf_utils.c | 1 +
 1 file changed, 1 insertion(+)
tools/lib/bpf/libbpf_utils.c +1 -0
index 2bae8cafc077..5d66bc6ff098 100644
@@ -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
 
#3 lore raw
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()")
---
 tools/lib/bpf/libbpf_utils.c | 1 +
 1 file changed, 1 insertion(+)
tools/lib/bpf/libbpf_utils.c +1 -0
index 2bae8cafc077..5d66bc6ff098 100644
@@ -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
 
#4 lore raw
In reply to Tony Ambardar
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