From 7296cf374d9ec92c394edf965d5347742fe5aed9 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 14 Sep 2017 14:06:17 +0200 Subject: sys/syz-extract: generate multiple arches at once --- sys/linux/extract.sh | 21 +++-------- sys/syz-extract/extract.go | 89 +++++++++++++++++++++++++++------------------- 2 files changed, 57 insertions(+), 53 deletions(-) (limited to 'sys') diff --git a/sys/linux/extract.sh b/sys/linux/extract.sh index 9a5ba45f0..e6dc9e880 100755 --- a/sys/linux/extract.sh +++ b/sys/linux/extract.sh @@ -5,6 +5,8 @@ # Assuming x86 host, you also need to install: # sudo apt-get install gcc-aarch64-linux-gnu gcc-powerpc64le-linux-gnu gcc-arm-linux-gnueabihf +set -eu + if [ "$LINUX" == "" ]; then if [ "$ANDROID" == "" ]; then echo "usage: make extract LINUX=/linux/checkout]" @@ -34,24 +36,11 @@ UPSTREAM_FILES="bpf.txt dri.txt fuse.txt input.txt ipc.txt ANDROID_FILES="tlk_device.txt ion.txt" if [ "$BUILD_FOR_ANDROID" == "no" ]; then + ARCHES="" FILES="$UPSTREAM_FILES" else + ARCHES="amd64,arm64" FILES="$ANDROID_FILES" fi -generate_arch() { - echo generating arch $1... - (cd sys/linux; ../../bin/syz-extract -arch $1 -linux "$LINUX" -build $FILES) - if [ $? -ne 0 ]; then - exit 1 - fi - echo -} - -generate_arch amd64 -generate_arch arm64 -if [ "$BUILD_FOR_ANDROID" == "no" ]; then - generate_arch 386 - generate_arch arm - generate_arch ppc64le -fi +(cd sys/linux; ../../bin/syz-extract -build -arch "$ARCHES" -linux "$LINUX" $FILES) diff --git a/sys/syz-extract/extract.go b/sys/syz-extract/extract.go index 7a9437e47..707b77e58 100644 --- a/sys/syz-extract/extract.go +++ b/sys/syz-extract/extract.go @@ -11,6 +11,7 @@ import ( "os" "path/filepath" "runtime" + "sort" "strings" "sync" "time" @@ -24,7 +25,7 @@ import ( var ( flagLinux = flag.String("linux", "", "path to linux kernel source checkout") flagLinuxBld = flag.String("linuxbld", "", "path to linux kernel build directory") - flagArch = flag.String("arch", "", "arch to generate") + flagArch = flag.String("arch", "", "comma-separated list of arches to generate (all by default)") flagBuild = flag.Bool("build", false, "generate arch-specific files in the linux dir") ) @@ -35,56 +36,70 @@ type File struct { } func main() { + const OS = "linux" flag.Parse() if *flagLinux == "" { failf("provide path to linux kernel checkout via -linux flag (or make extract LINUX= flag)") } - if *flagLinuxBld == "" { - *flagLinuxBld = *flagLinux - } - if *flagArch == "" { - failf("-arch flag is required") - } - target := sys.Targets["linux"][*flagArch] - if target == nil { - failf("unknown arch %v", *flagArch) + if *flagBuild && *flagLinuxBld != "" { + failf("-build and -linuxbld is an invalid combination") } n := len(flag.Args()) if n == 0 { failf("usage: syz-extract -linux=/linux/checkout -arch=arch input_file.txt...") } - if *flagBuild { - buildKernel(target, *flagLinux) + var arches []string + if *flagArch != "" { + arches = strings.Split(*flagArch, ",") + } else { + for arch := range sys.Targets[OS] { + arches = append(arches, arch) + } + sort.Strings(arches) } + for _, arch := range arches { + fmt.Printf("generating %v/%v...\n", OS, arch) + target := sys.Targets[OS][arch] + if target == nil { + failf("unknown arch %v", arch) + } + if *flagBuild { + buildKernel(target, *flagLinux) + *flagLinuxBld = *flagLinux + } else if *flagLinuxBld == "" { + *flagLinuxBld = *flagLinux + } - files := make([]File, n) - inc := make(chan *File, n) - for i, f := range flag.Args() { - files[i].name = f - inc <- &files[i] - } - close(inc) + files := make([]File, n) + inc := make(chan *File, n) + for i, f := range flag.Args() { + files[i].name = f + inc <- &files[i] + } + close(inc) - procs := runtime.GOMAXPROCS(0) - var wg sync.WaitGroup - wg.Add(procs) - for p := 0; p < procs; p++ { - go func() { - defer wg.Done() - for f := range inc { - f.undeclared, f.err = processFile(target, f.name) - } - }() - } - wg.Wait() - for _, f := range files { - fmt.Printf("extracting from %v\n", f.name) - if f.err != nil { - failf("%v", f.err) + procs := runtime.GOMAXPROCS(0) + var wg sync.WaitGroup + wg.Add(procs) + for p := 0; p < procs; p++ { + go func() { + defer wg.Done() + for f := range inc { + f.undeclared, f.err = processFile(target, f.name) + } + }() } - for c := range f.undeclared { - fmt.Printf("undefined const: %v\n", c) + wg.Wait() + for _, f := range files { + fmt.Printf("extracting from %v\n", f.name) + if f.err != nil { + failf("%v", f.err) + } + for c := range f.undeclared { + fmt.Printf("undefined const: %v\n", c) + } } + fmt.Printf("\n") } } -- cgit mrf-deployment