From 79910ad71b16dbf22e70717166c21361b5cf9bf0 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 23 Jan 2025 09:31:50 +0100 Subject: sys/syz-sysgen: serialize descriptions as gob and embed Instead of generating Go files with descriptions serialize them as gob and compress with flate. This significantly reduces build time, go vet time, and solves scalability problems with some static analysis tools. Reference times (all after rm -rf ~/.cache/go-build) before: TIME="%e %P %M" time go install ./syz-manager 48.29 577% 4824820 TIME="%e %P %M" time go test -c ./prog 56.28 380% 6973292 After: TIME="%e %P %M" time go install ./syz-manager 22.81 865% 859788 TIME="%e %P %M" time go test -c ./prog 12.74 565% 267760 syz-manager size before/after: 194712597 -> 83418407 -57% even provided we now embed all descriptions instead of just a single arch. Deflate/decoding time for a single Linux arch is ~330ms. Fixes #5542 --- prog/any.go | 2 +- prog/target.go | 17 ++++++++--------- prog/test/fuzz.go | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) (limited to 'prog') diff --git a/prog/any.go b/prog/any.go index c43d8dd8d..cb49f3494 100644 --- a/prog/any.go +++ b/prog/any.go @@ -24,7 +24,7 @@ type anyTypes struct { func (target *Target) initAnyTypes() { var anyPtrs *UnionType - for _, typ := range target.types { + for _, typ := range target.Types { if typ.Name() == "ANYPTRS" { anyPtrs = typ.(*UnionType) break diff --git a/prog/target.go b/prog/target.go index 50fcecdbc..11127046b 100644 --- a/prog/target.go +++ b/prog/target.go @@ -30,6 +30,7 @@ type Target struct { Resources []*ResourceDesc Consts []ConstValue Flags []FlagDesc + Types []Type // MakeDataMmap creates calls that mmaps target data memory range. MakeDataMmap func() []*Call @@ -70,8 +71,8 @@ type Target struct { FlagsMap map[string][]string init sync.Once + fillArch func(target *Target) initArch func(target *Target) - types []Type resourceMap map[string]*ResourceDesc // Maps resource name to a list of calls that can create the resource. resourceCtors map[string][]ResourceCtor @@ -86,20 +87,17 @@ const maxSpecialPointers = 16 var targets = make(map[string]*Target) -func RegisterTarget(target *Target, types []Type, initArch func(target *Target)) { +func RegisterTarget(target *Target, fill, init func(target *Target)) { key := target.OS + "/" + target.Arch if targets[key] != nil { panic(fmt.Sprintf("duplicate target %v", key)) } - target.initArch = initArch - target.types = types + target.fillArch = fill + target.initArch = init targets[key] = target } func GetTarget(OS, arch string) (*Target, error) { - if OS == "android" { - OS = "linux" - } key := OS + "/" + arch target := targets[key] if target == nil { @@ -132,6 +130,7 @@ func AllTargets() []*Target { func (target *Target) lazyInit() { target.Neutralize = func(c *Call, fixStructure bool) error { return nil } target.AnnotateCall = func(c ExecCall) string { return "" } + target.fillArch(target) target.initTarget() target.initUselessHints() target.initRelatedFields() @@ -155,7 +154,7 @@ func (target *Target) lazyInit() { } } // These are used only during lazyInit. - target.types = nil + target.Types = nil } func (target *Target) initTarget() { @@ -165,7 +164,7 @@ func (target *Target) initTarget() { target.ConstMap[c.Name] = c.Value } - target.resourceMap = restoreLinks(target.Syscalls, target.Resources, target.types) + target.resourceMap = restoreLinks(target.Syscalls, target.Resources, target.Types) target.initAnyTypes() target.SyscallMap = make(map[string]*Syscall) diff --git a/prog/test/fuzz.go b/prog/test/fuzz.go index 9b47234b3..98582a818 100644 --- a/prog/test/fuzz.go +++ b/prog/test/fuzz.go @@ -9,8 +9,8 @@ import ( "math/rand" "github.com/google/syzkaller/prog" + _ "github.com/google/syzkaller/sys" "github.com/google/syzkaller/sys/targets" - _ "github.com/google/syzkaller/sys/test/gen" // import the target we use for fuzzing ) func FuzzDeserialize(data []byte) int { -- cgit mrf-deployment