aboutsummaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-09-15 15:56:48 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-09-15 16:02:37 +0200
commitda1873aaddc53805f845e21dd4e10cb6f9148b1d (patch)
tree4e3858ff4cb6e7bf8a7d64cb46d7d3622394a032 /sys
parent66393d1884cb6a6d36dcbe5ad772ae9cf8f2adad (diff)
sys/targets: move targets from sys package
This breaks circular dependency between: sysgen -> sys/linux -> sys -> sysgen With this circular dependency it is very difficult to update format of generated descriptions because sysgen does not build.
Diffstat (limited to 'sys')
-rw-r--r--sys/sys.go70
-rw-r--r--sys/syz-extract/extract.go8
-rw-r--r--sys/syz-extract/fetch.go6
-rw-r--r--sys/syz-sysgen/sysgen.go10
-rw-r--r--sys/targets/targets.go74
5 files changed, 86 insertions, 82 deletions
diff --git a/sys/sys.go b/sys/sys.go
index 45d5b28c2..33718510c 100644
--- a/sys/sys.go
+++ b/sys/sys.go
@@ -7,75 +7,5 @@ import (
_ "github.com/google/syzkaller/sys/linux"
)
-type Target struct {
- OS string
- Arch string
- PtrSize uint64
- CArch []string
- CFlags []string
- CrossCFlags []string
- CCompilerPrefix string
- KernelArch string
- KernelHeaderArch string
- KernelCrossCompile string
-}
-
-var Targets = map[string]map[string]*Target{
- "linux": map[string]*Target{
- "amd64": {
- PtrSize: 8,
- CArch: []string{"__x86_64__"},
- CFlags: []string{"-m64"},
- CrossCFlags: []string{"-m64"},
- CCompilerPrefix: "x86_64-linux-gnu-",
- KernelArch: "x86_64",
- KernelHeaderArch: "x86",
- },
- "386": {
- PtrSize: 4,
- CArch: []string{"__i386__"},
- CFlags: []string{"-m32"},
- CrossCFlags: []string{"-m32"},
- CCompilerPrefix: "x86_64-linux-gnu-",
- KernelArch: "i386",
- KernelHeaderArch: "x86",
- },
- "arm64": {
- PtrSize: 8,
- CArch: []string{"__aarch64__"},
- CCompilerPrefix: "aarch64-linux-gnu-",
- KernelArch: "arm64",
- KernelHeaderArch: "arm64",
- },
- "arm": {
- PtrSize: 4,
- CArch: []string{"__arm__"},
- CFlags: []string{"-D__LINUX_ARM_ARCH__=6", "-m32"},
- CrossCFlags: []string{"-D__LINUX_ARM_ARCH__=6", "-march=armv6t2"},
- CCompilerPrefix: "arm-linux-gnueabihf-",
- KernelArch: "arm",
- KernelHeaderArch: "arm",
- },
- "ppc64le": {
- PtrSize: 8,
- CArch: []string{"__ppc64__", "__PPC64__", "__powerpc64__"},
- CFlags: []string{"-D__powerpc64__"},
- CrossCFlags: []string{"-D__powerpc64__"},
- CCompilerPrefix: "powerpc64le-linux-gnu-",
- KernelArch: "powerpc",
- KernelHeaderArch: "powerpc",
- },
- },
-}
-
-func init() {
- for OS, archs := range Targets {
- for arch, target := range archs {
- target.OS = OS
- target.Arch = arch
- }
- }
-}
-
// Emitted by Makefile.
var GitRevision string
diff --git a/sys/syz-extract/extract.go b/sys/syz-extract/extract.go
index 52a0ae7f0..764dcb0da 100644
--- a/sys/syz-extract/extract.go
+++ b/sys/syz-extract/extract.go
@@ -19,7 +19,7 @@ import (
"github.com/google/syzkaller/pkg/ast"
"github.com/google/syzkaller/pkg/compiler"
"github.com/google/syzkaller/pkg/osutil"
- "github.com/google/syzkaller/sys"
+ "github.com/google/syzkaller/sys/targets"
)
var (
@@ -30,7 +30,7 @@ var (
)
type Arch struct {
- target *sys.Target
+ target *targets.Target
kernelDir string
buildDir string
build bool
@@ -68,7 +68,7 @@ func main() {
if *flagArch != "" {
archArray = strings.Split(*flagArch, ",")
} else {
- for arch := range sys.Targets[OS] {
+ for arch := range targets.List[OS] {
archArray = append(archArray, arch)
}
sort.Strings(archArray)
@@ -105,7 +105,7 @@ func main() {
buildDir = *flagLinux
}
- target := sys.Targets[OS][archStr]
+ target := targets.List[OS][archStr]
if target == nil {
failf("unknown arch: %v", archStr)
}
diff --git a/sys/syz-extract/fetch.go b/sys/syz-extract/fetch.go
index 5def165b5..4fcbbcda5 100644
--- a/sys/syz-extract/fetch.go
+++ b/sys/syz-extract/fetch.go
@@ -12,13 +12,13 @@ import (
"strconv"
"strings"
- "github.com/google/syzkaller/sys"
+ "github.com/google/syzkaller/sys/targets"
)
// fetchValues converts literal constants (e.g. O_APPEND) or any other C expressions
// into their respective numeric values. It does so by builting and executing a C program
// that prints values of the provided expressions.
-func fetchValues(target *sys.Target, kernelDir, buildDir string,
+func fetchValues(target *targets.Target, kernelDir, buildDir string,
vals, includes, incdirs []string, defines map[string]string) (
map[string]uint64, map[string]bool, error) {
bin, out, err := runCompiler(target, kernelDir, buildDir, nil, includes, incdirs, nil, nil)
@@ -87,7 +87,7 @@ func fetchValues(target *sys.Target, kernelDir, buildDir string,
return res, undeclared, nil
}
-func runCompiler(target *sys.Target, kernelDir, buildDir string, vals, includes, incdirs []string, defines map[string]string, undeclared map[string]bool) (bin string, out []byte, err error) {
+func runCompiler(target *targets.Target, kernelDir, buildDir string, vals, includes, incdirs []string, defines map[string]string, undeclared map[string]bool) (bin string, out []byte, err error) {
includeText := ""
for _, inc := range includes {
includeText += fmt.Sprintf("#include <%v>\n", inc)
diff --git a/sys/syz-sysgen/sysgen.go b/sys/syz-sysgen/sysgen.go
index ea3e3e110..56ad15f46 100644
--- a/sys/syz-sysgen/sysgen.go
+++ b/sys/syz-sysgen/sysgen.go
@@ -24,7 +24,7 @@ import (
"github.com/google/syzkaller/pkg/hash"
"github.com/google/syzkaller/pkg/serializer"
"github.com/google/syzkaller/prog"
- "github.com/google/syzkaller/sys"
+ "github.com/google/syzkaller/sys/targets"
)
var (
@@ -35,14 +35,14 @@ var (
func main() {
flag.Parse()
- for OS, archs := range sys.Targets {
+ for OS, archs := range targets.List {
top := ast.ParseGlob(filepath.Join("sys", OS, "*\\.txt"), nil)
if top == nil {
os.Exit(1)
}
type Job struct {
- Target *sys.Target
+ Target *targets.Target
OK bool
Errors []string
Unsupported map[string]bool
@@ -129,7 +129,7 @@ func main() {
}
}
-func generate(target *sys.Target, prg *compiler.Prog, consts map[string]uint64, out io.Writer) {
+func generate(target *targets.Target, prg *compiler.Prog, consts map[string]uint64, out io.Writer) {
fmt.Fprintf(out, "// AUTOGENERATED FILE\n")
fmt.Fprintf(out, "package %v\n\n", target.OS)
fmt.Fprintf(out, "import . \"github.com/google/syzkaller/prog\"\n\n")
@@ -163,7 +163,7 @@ func generate(target *sys.Target, prg *compiler.Prog, consts map[string]uint64,
fmt.Fprintf(out, "\n\n")
}
-func generateExecutorSyscalls(target *sys.Target, syscalls []*prog.Syscall, rev string) []byte {
+func generateExecutorSyscalls(target *targets.Target, syscalls []*prog.Syscall, rev string) []byte {
type SyscallData struct {
Name string
NR int32
diff --git a/sys/targets/targets.go b/sys/targets/targets.go
new file mode 100644
index 000000000..07f3ee8a7
--- /dev/null
+++ b/sys/targets/targets.go
@@ -0,0 +1,74 @@
+// Copyright 2017 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 targets
+
+type Target struct {
+ OS string
+ Arch string
+ PtrSize uint64
+ CArch []string
+ CFlags []string
+ CrossCFlags []string
+ CCompilerPrefix string
+ KernelArch string
+ KernelHeaderArch string
+ KernelCrossCompile string
+}
+
+var List = map[string]map[string]*Target{
+ "linux": map[string]*Target{
+ "amd64": {
+ PtrSize: 8,
+ CArch: []string{"__x86_64__"},
+ CFlags: []string{"-m64"},
+ CrossCFlags: []string{"-m64"},
+ CCompilerPrefix: "x86_64-linux-gnu-",
+ KernelArch: "x86_64",
+ KernelHeaderArch: "x86",
+ },
+ "386": {
+ PtrSize: 4,
+ CArch: []string{"__i386__"},
+ CFlags: []string{"-m32"},
+ CrossCFlags: []string{"-m32"},
+ CCompilerPrefix: "x86_64-linux-gnu-",
+ KernelArch: "i386",
+ KernelHeaderArch: "x86",
+ },
+ "arm64": {
+ PtrSize: 8,
+ CArch: []string{"__aarch64__"},
+ CCompilerPrefix: "aarch64-linux-gnu-",
+ KernelArch: "arm64",
+ KernelHeaderArch: "arm64",
+ },
+ "arm": {
+ PtrSize: 4,
+ CArch: []string{"__arm__"},
+ CFlags: []string{"-D__LINUX_ARM_ARCH__=6", "-m32"},
+ CrossCFlags: []string{"-D__LINUX_ARM_ARCH__=6", "-march=armv6t2"},
+ CCompilerPrefix: "arm-linux-gnueabihf-",
+ KernelArch: "arm",
+ KernelHeaderArch: "arm",
+ },
+ "ppc64le": {
+ PtrSize: 8,
+ CArch: []string{"__ppc64__", "__PPC64__", "__powerpc64__"},
+ CFlags: []string{"-D__powerpc64__"},
+ CrossCFlags: []string{"-D__powerpc64__"},
+ CCompilerPrefix: "powerpc64le-linux-gnu-",
+ KernelArch: "powerpc",
+ KernelHeaderArch: "powerpc",
+ },
+ },
+}
+
+func init() {
+ for OS, archs := range List {
+ for arch, target := range archs {
+ target.OS = OS
+ target.Arch = arch
+ }
+ }
+}