aboutsummaryrefslogtreecommitdiffstats
path: root/prog/prog.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-01-05 20:05:11 +0100
committerDmitry Vyukov <dvyukov@google.com>2022-01-11 16:30:08 +0100
commit2cfe62f82077ba012aef55db5288985bc0c426d9 (patch)
tree501d83deb358a230d157c9d7efc6fc393e239472 /prog/prog.go
parent16e21d13ea26a631e9b3a30c94635b1d565fd78f (diff)
pkg/compiler: add out_overlay field attribute
Diffstat (limited to 'prog/prog.go')
-rw-r--r--prog/prog.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/prog/prog.go b/prog/prog.go
index 86e424299..87b9998b8 100644
--- a/prog/prog.go
+++ b/prog/prog.go
@@ -223,12 +223,21 @@ func (arg *GroupArg) Size() uint64 {
}
switch typ := typ0.(type) {
case *StructType:
- var size uint64
- for _, fld := range arg.Inner {
- size += fld.Size()
- }
- if typ.AlignAttr != 0 && size%typ.AlignAttr != 0 {
- size += typ.AlignAttr - size%typ.AlignAttr
+ var size, offset uint64
+ for i, fld := range arg.Inner {
+ if i == typ.OverlayField {
+ offset = 0
+ }
+ offset += fld.Size()
+ // Add dynamic alignment at the end and before the overlay part.
+ if i+1 == len(arg.Inner) || i+1 == typ.OverlayField {
+ if typ.AlignAttr != 0 && offset%typ.AlignAttr != 0 {
+ offset += typ.AlignAttr - offset%typ.AlignAttr
+ }
+ }
+ if size < offset {
+ size = offset
+ }
}
return size
case *ArrayType: