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.
This commit is contained in:
Dmitry Vyukov 2017-09-15 15:56:48 +02:00
parent 66393d1884
commit da1873aadd
6 changed files with 89 additions and 85 deletions

View File

@ -20,7 +20,7 @@ import (
"unsafe"
"github.com/google/syzkaller/prog"
"github.com/google/syzkaller/sys"
"github.com/google/syzkaller/sys/targets"
)
type Options struct {
@ -481,7 +481,7 @@ func preprocessCommonHeader(target *prog.Target, opts Options, handled map[strin
defines = append(defines, "__NR_"+name)
}
sysTarget := sys.Targets[target.OS][target.Arch]
sysTarget := targets.List[target.OS][target.Arch]
defines = append(defines, sysTarget.CArch...)
cmd := exec.Command("cpp", "-nostdinc", "-undef", "-fdirectives-only", "-dDI", "-E", "-P", "-")
@ -529,7 +529,7 @@ func Build(target *prog.Target, lang, src string) (string, error) {
return "", fmt.Errorf("failed to create temp file: %v", err)
}
bin.Close()
sysTarget := sys.Targets[target.OS][target.Arch]
sysTarget := targets.List[target.OS][target.Arch]
compiler := sysTarget.CCompilerPrefix + "gcc"
if _, err := exec.LookPath(compiler); err != nil {
return "", NoCompilerErr

View File

@ -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

View File

@ -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)
}

View File

@ -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)

View File

@ -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

74
sys/targets/targets.go Normal file
View File

@ -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
}
}
}