aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/meta.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-04-29 09:15:41 +0200
committerDmitry Vyukov <dvyukov@google.com>2022-04-29 16:23:27 +0200
commit44a5ca633e186c5836010366c515a4017836121b (patch)
tree326b10c295737e0af8ce69ef8cbf2dbf4ecaccba /pkg/compiler/meta.go
parente9076525f882cc932139b6e813c39f3f0043c3f5 (diff)
pkg/ast, pkg/compiler: support per-file metadata
We have a bunch of hacks in syz-extract, syz-sysgen and syz-check with respect to description files unsupported on some arches, or that must not be part of make extract. Add 2 meta attribtues to files: meta noextract Tells `make extract` to not extract constants for this file. Though, `syz-extract` can still be invoked manually on this file. meta arches["arch1", "arch2"] Restricts this file only to the given set of architectures. `make extract` and ``make generate` will not use it on other architectures. Later we can potentially use meta attributes to specify git tree/commit that must be used for extraction. Maybe something else. Fixes #2754
Diffstat (limited to 'pkg/compiler/meta.go')
-rw-r--r--pkg/compiler/meta.go88
1 files changed, 88 insertions, 0 deletions
diff --git a/pkg/compiler/meta.go b/pkg/compiler/meta.go
new file mode 100644
index 000000000..f0221d0b9
--- /dev/null
+++ b/pkg/compiler/meta.go
@@ -0,0 +1,88 @@
+// Copyright 2022 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 compiler
+
+import (
+ "path/filepath"
+
+ "github.com/google/syzkaller/pkg/ast"
+ "github.com/google/syzkaller/sys/targets"
+)
+
+type Meta struct {
+ NoExtract bool
+ Arches map[string]bool
+}
+
+func (meta *Meta) SupportsArch(arch string) bool {
+ return len(meta.Arches) == 0 || meta.Arches[arch]
+}
+
+func FileList(desc *ast.Description, OS string, eh ast.ErrorHandler) map[string]Meta {
+ // Use any target for this OS.
+ for _, target := range targets.List[OS] {
+ return createCompiler(desc, target, eh).fileList()
+ }
+ return nil
+}
+
+func (comp *compiler) fileList() map[string]Meta {
+ files := make(map[string]Meta)
+ for _, n := range comp.desc.Nodes {
+ pos, _, _ := n.Info()
+ file := filepath.Base(pos.File)
+ if file == ast.BuiltinFile {
+ continue
+ }
+ meta := files[file]
+ switch n := n.(type) {
+ case *ast.Meta:
+ errors0 := comp.errors
+ comp.checkTypeImpl(checkCtx{}, n.Value, metaTypes[n.Value.Ident], 0)
+ if errors0 != comp.errors {
+ break
+ }
+ switch n.Value.Ident {
+ case metaNoExtract.Names[0]:
+ meta.NoExtract = true
+ case metaArches.Names[0]:
+ meta.Arches = make(map[string]bool)
+ for _, arg := range n.Value.Args {
+ meta.Arches[arg.String] = true
+ }
+ }
+ }
+ files[file] = meta
+ }
+ if comp.errors != 0 {
+ return nil
+ }
+ return files
+}
+
+var metaTypes = map[string]*typeDesc{
+ metaNoExtract.Names[0]: metaNoExtract,
+ metaArches.Names[0]: metaArches,
+}
+
+var metaNoExtract = &typeDesc{
+ Names: []string{"noextract"},
+ CantBeOpt: true,
+}
+
+var metaArches = &typeDesc{
+ Names: []string{"arches"},
+ CantBeOpt: true,
+ OptArgs: 8,
+ Args: []namedArg{metaArch, metaArch, metaArch, metaArch, metaArch, metaArch, metaArch, metaArch},
+}
+
+var metaArch = namedArg{Name: "arch", Type: &typeArg{
+ Kind: kindString,
+ Check: func(comp *compiler, t *ast.Type) {
+ if targets.List[comp.target.OS][t.String] == nil {
+ comp.error(t.Pos, "unknown arch %v", t.String)
+ }
+ },
+}}