diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-09-19 16:49:52 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2023-10-04 09:27:33 +0000 |
| commit | b7d7ff54b601447c0eaf6fbd20eb6fd03192aeaf (patch) | |
| tree | 05cb7c1c1ed3cfa2ecb48b53df8cbbdf5239e1fa | |
| parent | 8144982a26c6b8e5f0f5401c2a2de99e4ced04cd (diff) | |
sys/syz-sysgen: fail on undefined consts
Ensure that every const mentioned in the description is defined for at
least one architecture.
We cannot do it inside pkg/compiler as it deals with only one arch at a
time. Also, we cannot do it inside syz-check as it's not supposed to be
called every time and may also include non-actionable warnings.
So let's do it inside syz-sysgen, which is invoked all the time and has
all the necessary data.
| -rw-r--r-- | sys/syz-sysgen/check.go | 26 | ||||
| -rw-r--r-- | sys/syz-sysgen/sysgen.go | 7 |
2 files changed, 32 insertions, 1 deletions
diff --git a/sys/syz-sysgen/check.go b/sys/syz-sysgen/check.go new file mode 100644 index 000000000..aee850a9a --- /dev/null +++ b/sys/syz-sysgen/check.go @@ -0,0 +1,26 @@ +// Copyright 2023 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package main + +import ( + "fmt" + + "github.com/google/syzkaller/pkg/ast" + "github.com/google/syzkaller/pkg/compiler" +) + +// constsAreAllDefined() ensures that for every const there's at least one arch that defines it. +func constsAreAllDefined(consts *compiler.ConstFile, constInfo map[string]*compiler.ConstInfo, + eh ast.ErrorHandler) { + // We cannot perform this check inside pkg/compiler because it's + // given a const slice for only one architecture. + for _, info := range constInfo { + for _, def := range info.Consts { + if consts.ExistsAny(def.Name) { + continue + } + eh(def.Pos, fmt.Sprintf("%s is defined for none of the arches", def.Name)) + } + } +} diff --git a/sys/syz-sysgen/sysgen.go b/sys/syz-sysgen/sysgen.go index 70b38fee5..2ab6cdbab 100644 --- a/sys/syz-sysgen/sysgen.go +++ b/sys/syz-sysgen/sysgen.go @@ -202,7 +202,12 @@ func processJob(job *Job, descriptions *ast.Description, constFile *compiler.Con // Don't print warnings, they are printed in syz-check. job.Errors = nil - job.OK = true + // But let's fail on always actionable errors. + if job.Target.OS != targets.Fuchsia { + // There are too many broken consts on Fuchsia. + constsAreAllDefined(constFile, job.ConstInfo, eh) + } + job.OK = len(job.Errors) == 0 } func generate(target *targets.Target, prg *compiler.Prog, consts map[string]uint64, out io.Writer) { |
