aboutsummaryrefslogtreecommitdiffstats
path: root/prog/size.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/size.go
parent16e21d13ea26a631e9b3a30c94635b1d565fd78f (diff)
pkg/compiler: add out_overlay field attribute
Diffstat (limited to 'prog/size.go')
-rw-r--r--prog/size.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/prog/size.go b/prog/size.go
index 6eccec50f..1a0b9dcb6 100644
--- a/prog/size.go
+++ b/prog/size.go
@@ -15,7 +15,7 @@ const (
)
func (target *Target) assignSizes(args []Arg, fields []Field, parentsMap map[Arg]Arg,
- syscallArgs []Arg, syscallFields []Field, autos map[Arg]bool) {
+ syscallArgs []Arg, syscallFields []Field, autos map[Arg]bool, overlayField int) {
for _, arg := range args {
if arg = InnerArg(arg); arg == nil {
continue // Pointer to optional len field, no need to fill in value.
@@ -32,9 +32,9 @@ func (target *Target) assignSizes(args []Arg, fields []Field, parentsMap map[Arg
}
a := arg.(*ConstArg)
if typ.Path[0] == SyscallRef {
- target.assignSize(a, nil, typ.Path[1:], syscallArgs, syscallFields, parentsMap)
+ target.assignSize(a, nil, typ.Path[1:], syscallArgs, syscallFields, parentsMap, 0)
} else {
- target.assignSize(a, a, typ.Path, args, fields, parentsMap)
+ target.assignSize(a, a, typ.Path, args, fields, parentsMap, overlayField)
}
}
}
@@ -42,15 +42,18 @@ func (target *Target) assignSizes(args []Arg, fields []Field, parentsMap map[Arg
func (target *Target) assignSizeStruct(dst *ConstArg, buf Arg, path []string, parentsMap map[Arg]Arg) {
arg := buf.(*GroupArg)
typ := arg.Type().(*StructType)
- target.assignSize(dst, buf, path, arg.Inner, typ.Fields, parentsMap)
+ target.assignSize(dst, buf, path, arg.Inner, typ.Fields, parentsMap, typ.OverlayField)
}
func (target *Target) assignSize(dst *ConstArg, pos Arg, path []string, args []Arg,
- fields []Field, parentsMap map[Arg]Arg) {
+ fields []Field, parentsMap map[Arg]Arg, overlayField int) {
elem := path[0]
path = path[1:]
var offset uint64
for i, buf := range args {
+ if i == overlayField {
+ offset = 0
+ }
if elem != fields[i].Name {
offset += buf.Size()
continue
@@ -140,11 +143,11 @@ func (target *Target) assignSizesArray(args []Arg, fields []Field, autos map[Arg
}
})
}
- target.assignSizes(args, fields, parentsMap, args, fields, autos)
+ target.assignSizes(args, fields, parentsMap, args, fields, autos, 0)
for _, arg := range args {
ForeachSubArg(arg, func(arg Arg, _ *ArgCtx) {
if typ, ok := arg.Type().(*StructType); ok {
- target.assignSizes(arg.(*GroupArg).Inner, typ.Fields, parentsMap, args, fields, autos)
+ target.assignSizes(arg.(*GroupArg).Inner, typ.Fields, parentsMap, args, fields, autos, typ.OverlayField)
}
})
}