Skip to contentSkip to conversation

libbpf: Ignore warnings about "inefficient alignment"

PATCH Applied Daniel Müller 2 participants 3 messages Mar 15, 2023 – Mar 16, 2023

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

PATCH 1/1 libbpf: Ignore warnings about "inefficient alignment"

Some consumers of libbpf compile the code base with different warnings enabled. In a report for perf, for example, -Wpacked was set which caused warnings about "inefficient alignment" to be emitted on a subset of supported architectures.
With this change we silence specifically those warnings, as we intentionally worked with packed structs.

---
 tools/lib/bpf/zip.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/lib/bpf/zip.c +6 -0
index f561aa..3f26d62 100644
@@ -16,6 +16,10 @@
 #include "libbpf_internal.h"
 #include "zip.h"
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpacked"
+#pragma GCC diagnostic ignored "-Wattributes"
+
 /* Specification of ZIP file format can be found here:
  * https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
  * For a high level overview of the structure of a ZIP file see
@@ -119,6 +123,8 @@ struct local_file_header {
 	__u16 extra_field_length;
 } __attribute__((packed));
 
+#pragma GCC diagnostic pop
+
 struct zip_archive {
 	void *data;
 	__u32 size;
Signature · 1 line
2.34.1
#1 lore raw

For what it's worth, I was unable to reproduce the original issue, locally and in CI. So this is a best guess at a fix based on the suggestion provided in the linked report.

Thanks,
Daniel

Quoted 42 lines · Daniel Müller

Some consumers of libbpf compile the code base with different warnings enabled. In a report for perf, for example, -Wpacked was set which caused warnings about "inefficient alignment" to be emitted on a subset of supported architectures.
With this change we silence specifically those warnings, as we intentionally worked with packed structs.

---
 tools/lib/bpf/zip.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/lib/bpf/zip.c +6 -0
index f561aa..3f26d62 100644
@@ -16,6 +16,10 @@
 #include "libbpf_internal.h"
 #include "zip.h"
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpacked"
+#pragma GCC diagnostic ignored "-Wattributes"
+
 /* Specification of ZIP file format can be found here:
  * https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
  * For a high level overview of the structure of a ZIP file see
@@ -119,6 +123,8 @@ struct local_file_header {
 	__u16 extra_field_length;
 } __attribute__((packed));
 
+#pragma GCC diagnostic pop
+
 struct zip_archive {
 	void *data;
 	__u32 size;
Signature · 1 line
2.34.1
#2 lore raw
In reply to Daniel Müller
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 8 lines · On Wed, 15 Mar 2023 17:15:50 +0000 you wrote:

Some consumers of libbpf compile the code base with different warnings enabled. In a report for perf, for example, -Wpacked was set which caused warnings about "inefficient alignment" to be emitted on a subset of supported architectures.
With this change we silence specifically those warnings, as we intentionally worked with packed structs.

[...]

Here is the summary with links:
- [bpf-next] libbpf: Ignore warnings about "inefficient alignment"

    https://git.kernel.org/bpf/bpf-next/c/6cb9430be147

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html