aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-declextract
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2025-01-17 10:39:49 +0100
committerDmitry Vyukov <dvyukov@google.com>2025-01-20 13:30:27 +0000
commit6e87cfa299c98d36e79e8b8718a4126899a3ba2f (patch)
tree471099bb5efb7421704429e59a2e2134bde2842b /tools/syz-declextract
parent520f8c5e11ccf2569cdfb02597c3782ce0760b90 (diff)
pkg/compiler: fix struct layout bug
Currently we have a bug in struct layout that affects some corner cases that involve recursive structs. The result of this bug is that we use wrong alignment 1 (not yet calculated) for some structs when calculating layout of other structs. The root cause of this bug is that we calculate struct alignment too early in typeStruct.Gen when structs are not yet laid out. For this reason we moved struct size calculation to the later phase (after compiler.layoutStruct). Move alignment calculation from typeStruct.Gen to compiler.layoutStruct to fix this.
Diffstat (limited to 'tools/syz-declextract')
-rw-r--r--tools/syz-declextract/testdata/types.c3
-rw-r--r--tools/syz-declextract/testdata/types.c.json12
-rw-r--r--tools/syz-declextract/testdata/types.c.txt6
3 files changed, 17 insertions, 4 deletions
diff --git a/tools/syz-declextract/testdata/types.c b/tools/syz-declextract/testdata/types.c
index 014318d42..7a98394c1 100644
--- a/tools/syz-declextract/testdata/types.c
+++ b/tools/syz-declextract/testdata/types.c
@@ -46,8 +46,7 @@ struct various {
};
struct recursive {
- // This is not handled properly yet.
- // struct various various;
+ struct various various;
};
SYSCALL_DEFINE1(types_syscall, struct anon_struct* p, struct empty_struct* y,
diff --git a/tools/syz-declextract/testdata/types.c.json b/tools/syz-declextract/testdata/types.c.json
index 99d0adc2b..6c479dffb 100644
--- a/tools/syz-declextract/testdata/types.c.json
+++ b/tools/syz-declextract/testdata/types.c.json
@@ -758,7 +758,17 @@
},
{
"name": "recursive",
- "align": 1
+ "byte_size": 64,
+ "align": 32,
+ "fields": [
+ {
+ "name": "various",
+ "counted_by": -1,
+ "type": {
+ "struct": "various"
+ }
+ }
+ ]
},
{
"name": "various",
diff --git a/tools/syz-declextract/testdata/types.c.txt b/tools/syz-declextract/testdata/types.c.txt
index ea95b4bb5..085aee017 100644
--- a/tools/syz-declextract/testdata/types.c.txt
+++ b/tools/syz-declextract/testdata/types.c.txt
@@ -97,9 +97,13 @@ packed_t$auto {
y int32
} [packed, align[32]]
+recursive$auto {
+ various various$auto
+}
+
various$auto {
recursive ptr[inout, various$auto, opt]
- next ptr[inout, auto_aligner[1], opt]
+ next ptr[inout, recursive$auto, opt]
packed packed_t$auto
}