From b7d7ff54b601447c0eaf6fbd20eb6fd03192aeaf Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 19 Sep 2023 16:49:52 +0200 Subject: 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. --- sys/syz-sysgen/check.go | 26 ++++++++++++++++++++++++++ sys/syz-sysgen/sysgen.go | 7 ++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 sys/syz-sysgen/check.go 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) { -- cgit mrf-deployment