aboutsummaryrefslogtreecommitdiffstats
path: root/sys/syz-sysgen
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-09-13 19:16:32 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-09-15 16:02:37 +0200
commit34bc139642b0caed49b2ba2dcb9ccff10e04c55f (patch)
tree4575a76f5c97b3ec7c7dfbfe511917123e8a020b /sys/syz-sysgen
parentb16ba6390d6b2731bf5cfa0ef04aa1299b7306cf (diff)
sys: compile all supported targets into the package
Currently we compile in only GOOS/GOARCH target. Compile in all targets so that they can be selected at runtime.
Diffstat (limited to 'sys/syz-sysgen')
-rw-r--r--sys/syz-sysgen/sysgen.go50
1 files changed, 20 insertions, 30 deletions
diff --git a/sys/syz-sysgen/sysgen.go b/sys/syz-sysgen/sysgen.go
index a5b48614d..a7b202715 100644
--- a/sys/syz-sysgen/sysgen.go
+++ b/sys/syz-sysgen/sysgen.go
@@ -20,6 +20,7 @@ import (
"github.com/google/syzkaller/pkg/ast"
"github.com/google/syzkaller/pkg/compiler"
"github.com/google/syzkaller/pkg/serializer"
+ "github.com/google/syzkaller/prog"
)
var (
@@ -63,7 +64,7 @@ func main() {
}
res.Unsupported = prog.Unsupported
- sysFile := filepath.Join("sys", "linux", "sys_"+arch.Name+".go")
+ sysFile := filepath.Join("sys", "linux", arch.Name+".go")
out := new(bytes.Buffer)
generate(arch, prog, consts, out)
writeSource(sysFile, out.Bytes())
@@ -113,49 +114,38 @@ func main() {
}
}
-func generate(arch *Arch, prog *compiler.Prog, consts map[string]uint64, out io.Writer) {
+func generate(arch *Arch, prg *compiler.Prog, consts map[string]uint64, out io.Writer) {
fmt.Fprintf(out, "// AUTOGENERATED FILE\n")
fmt.Fprintf(out, "package linux\n\n")
fmt.Fprintf(out, "import . \"github.com/google/syzkaller/prog\"\n\n")
- fmt.Fprintf(out, "var resources = ")
- serializer.Write(out, prog.Resources)
- fmt.Fprintf(out, "\n\n")
+ fmt.Fprintf(out, "func init() {\n")
+ fmt.Fprintf(out, "\tinitArch(syscalls_%v, resources_%v, structDescs_%v, consts_%v, %q, %v)\n",
+ arch.Name, arch.Name, arch.Name, arch.Name, arch.Name, arch.PtrSize)
+ fmt.Fprintf(out, "}\n\n")
- // Struct fields can refer to other structs. Go compiler won't like if
- // we refer to Structs during Structs initialization. So we do
- // it in 2 passes: on the first pass create struct types without fields,
- // on the second pass we fill in fields.
+ fmt.Fprintf(out, "var resources_%v = ", arch.Name)
+ serializer.Write(out, prg.Resources)
+ fmt.Fprintf(out, "\n\n")
- // Since structs of the same type can be fields with different names
- // of multiple other structs, we have an instance of those structs
- // for each field indexed by the name of the parent struct, field name and dir.
- fmt.Fprintf(out, "var structDescs = ")
- serializer.Write(out, prog.StructDescs)
+ fmt.Fprintf(out, "var structDescs_%v = ", arch.Name)
+ serializer.Write(out, prg.StructDescs)
fmt.Fprintf(out, "\n\n")
- fmt.Fprintf(out, "var syscalls = ")
- serializer.Write(out, prog.Syscalls)
+ fmt.Fprintf(out, "var syscalls_%v = ", arch.Name)
+ serializer.Write(out, prg.Syscalls)
fmt.Fprintf(out, "\n\n")
- type NameValue struct {
- name string
- val uint64
- }
- constArr := make([]NameValue, 0, len(consts))
+ constArr := make([]prog.ConstValue, 0, len(consts))
for name, val := range consts {
- constArr = append(constArr, NameValue{name, val})
+ constArr = append(constArr, prog.ConstValue{name, val})
}
sort.Slice(constArr, func(i, j int) bool {
- return constArr[i].name < constArr[j].name
+ return constArr[i].Name < constArr[j].Name
})
-
- fmt.Fprintf(out, "const (\n")
- fmt.Fprintf(out, "ptrSize = %v\n", arch.PtrSize)
- for _, nv := range constArr {
- fmt.Fprintf(out, "%v = %v\n", nv.name, nv.val)
- }
- fmt.Fprintf(out, ")\n")
+ fmt.Fprintf(out, "var consts_%v = ", arch.Name)
+ serializer.Write(out, constArr)
+ fmt.Fprintf(out, "\n")
}
func writeSource(file string, data []byte) {