From 2b76b86c449fff4c26410164052c32f3b9cf56fe Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 17 Jan 2025 10:39:47 +0100 Subject: tools/syz-declextract: fix empty structs and arrays This fixes 2 bugs: 1. We completly remove empty structs, but they can have effect on parent struct layout if they have >1 alignment. Replace empty structs with a special auto_aligner type that preserves alignment. 2. Arrays of 0 size are currently emitted as dynamically-sized (we assume 0 size means "this is not a const-size array"). Add separate IsConstSize flag for arrays that marks const-size arrays. Additionally cross-check that generated structs have exactly the same size/alignment as the corresponding C structs. This allows to catch the above bugs. --- pkg/declextract/entity.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'pkg/declextract/entity.go') diff --git a/pkg/declextract/entity.go b/pkg/declextract/entity.go index 8167d8b99..83f56ba52 100644 --- a/pkg/declextract/entity.go +++ b/pkg/declextract/entity.go @@ -111,12 +111,13 @@ type NetlinkAttr struct { } type Struct struct { - Name string `json:"name,omitempty"` - ByteSize int `json:"byte_size,omitempty"` - IsUnion bool `json:"is_union,omitempty"` - IsPacked bool `json:"is_packed,omitempty"` - Align int `json:"align,omitempty"` - Fields []*Field `json:"fields,omitempty"` + Name string `json:"name,omitempty"` + ByteSize int `json:"byte_size,omitempty"` + Align int `json:"align,omitempty"` + IsUnion bool `json:"is_union,omitempty"` + IsPacked bool `json:"is_packed,omitempty"` + AlignAttr int `json:"align_attr,omitempty"` + Fields []*Field `json:"fields,omitempty"` } type Enum struct { @@ -150,9 +151,11 @@ type PtrType struct { } type ArrayType struct { - Elem *Type `json:"elem,omitempty"` - MinSize int `json:"min_size,omitempty"` - MaxSize int `json:"max_size,omitempty"` + Elem *Type `json:"elem,omitempty"` + MinSize int `json:"min_size,omitempty"` + MaxSize int `json:"max_size,omitempty"` + Align int `json:"align,omitempty"` + IsConstSize bool `json:"is_const_size,omitempty"` } type BufferType struct { -- cgit mrf-deployment