Skip to contentSkip to conversation

libbpf: Add explicit padding to btf_dump_emit_type_decl_opts

PATCH New KP Singh 1 participant 1 message Mar 19, 2021

Subsystems (2)
lore
Share & tools
lore

KP Singh

author
#0 lore raw

PATCH 1/1 libbpf: Add explicit padding to btf_dump_emit_type_decl_opts

Similar to
https://lore.kernel.org/bpf/[email protected]/

When DECLARE_LIBBPF_OPTS is used with inline field initialization, e.g:

DCLARE_LIBBPF_OPTS(btf_dump_emit_type_decl_opts, opts,
.field_name = var_ident,
.indent_level = 2,
.strip_mods = strip_mods,
);

and compiled in debug mode, the compiler generates code which leaves the padding uninitialized and triggers errors within libbpf APIs which require strict zero initialization of OPTS structs.

Adding anonymous padding field fixes the issue.

Fixes 9f81654eebe8 ("libbpf: Expose BTF-to-C type declaration emitting API")
---
 tools/lib/bpf/btf.h | 1 +
 1 file changed, 1 insertion(+)
tools/lib/bpf/btf.h +1 -0
index 3b0b17ba94a1..b54f1c3ebd57 100644
@@ -176,6 +176,7 @@ struct btf_dump_emit_type_decl_opts {
 	int indent_level;
 	/* strip all the const/volatile/restrict mods */
 	bool strip_mods;
+	size_t :0;
 };
 #define btf_dump_emit_type_decl_opts__last_field strip_mods
 
Signature · 1 line
2.31.0.rc2.261.g7f71774620-goog