mirror of
https://github.com/reactos/syzkaller.git
synced 2024-11-23 11:29:46 +00:00
sys/syz-extract: use consolidated target info
Move knowledge about targets from extract.sh to syz-extract, and make it use target into from sys.
This commit is contained in:
parent
75ddf7ab90
commit
f7eb58493b
2
Makefile
2
Makefile
@ -71,7 +71,7 @@ upgrade:
|
||||
go build $(GOFLAGS) -o ./bin/syz-upgrade github.com/google/syzkaller/tools/syz-upgrade
|
||||
|
||||
extract: bin/syz-extract
|
||||
LINUX=$(LINUX) LINUXBLD=$(LINUXBLD) ./sys/linux/extract.sh
|
||||
LINUX=$(LINUX) ./sys/linux/extract.sh
|
||||
bin/syz-extract:
|
||||
go build $(GOFLAGS) -o $@ ./sys/syz-extract
|
||||
|
||||
|
@ -41,36 +41,17 @@ fi
|
||||
|
||||
generate_arch() {
|
||||
echo generating arch $1...
|
||||
echo "cd $LINUX; make defconfig"
|
||||
OUT=`(cd $LINUX; make ARCH=$2 CROSS_COMPILE=$3 CFLAGS=$4 defconfig 2>&1)`
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "$OUT"
|
||||
exit 1
|
||||
fi
|
||||
# Without CONFIG_NETFILTER kernel does not build.
|
||||
(cd $LINUX; sed -i "s@# CONFIG_NETFILTER is not set@CONFIG_NETFILTER=y@g" .config)
|
||||
(cd $LINUX; make ARCH=$2 CROSS_COMPILE=$3 CFLAGS=$4 olddefconfig)
|
||||
echo "cd $LINUX; make"
|
||||
OUT=`(cd $LINUX; make ARCH=$2 CROSS_COMPILE=$3 CFLAGS=$4 init/main.o 2>&1)`
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "$OUT"
|
||||
exit 1
|
||||
fi
|
||||
(cd sys/linux; ../../bin/syz-extract -arch $1 -linux "$LINUX" -linuxbld "$LINUXBLD" $FILES)
|
||||
(cd sys/linux; ../../bin/syz-extract -arch $1 -linux "$LINUX" -build $FILES)
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
}
|
||||
|
||||
# $1 Go arch
|
||||
# $2 kernel arch
|
||||
# $3 cross-compiler prefix
|
||||
# $4 CLAGS
|
||||
generate_arch amd64 x86_64 x86_64-linux-gnu- "-m64"
|
||||
generate_arch arm64 arm64 aarch64-linux-gnu- ""
|
||||
generate_arch amd64
|
||||
generate_arch arm64
|
||||
if [ "$BUILD_FOR_ANDROID" == "no" ]; then
|
||||
generate_arch 386 i386 "" "-m32"
|
||||
generate_arch arm arm arm-linux-gnueabihf- "-march=armv6t2"
|
||||
generate_arch ppc64le powerpc powerpc64le-linux-gnu- ""
|
||||
generate_arch 386
|
||||
generate_arch arm
|
||||
generate_arch ppc64le
|
||||
fi
|
||||
|
@ -70,6 +70,7 @@ func init() {
|
||||
for arch, target := range archs {
|
||||
target.OS = OS
|
||||
target.Arch = arch
|
||||
target.CrossCFlags = append(target.CrossCFlags, target.CFlags...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/syzkaller/pkg/ast"
|
||||
"github.com/google/syzkaller/pkg/compiler"
|
||||
@ -24,6 +25,7 @@ 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")
|
||||
flagBuild = flag.Bool("build", false, "generate arch-specific files in the linux dir")
|
||||
)
|
||||
|
||||
type File struct {
|
||||
@ -33,11 +35,6 @@ type File struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
failf := func(msg string, args ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, msg+"\n", args...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
if *flagLinux == "" {
|
||||
failf("provide path to linux kernel checkout via -linux flag (or make extract LINUX= flag)")
|
||||
@ -56,6 +53,9 @@ func main() {
|
||||
if n == 0 {
|
||||
failf("usage: syz-extract -linux=/linux/checkout -arch=arch input_file.txt...")
|
||||
}
|
||||
if *flagBuild {
|
||||
buildKernel(target, *flagLinux)
|
||||
}
|
||||
|
||||
files := make([]File, n)
|
||||
inc := make(chan *File, n)
|
||||
@ -120,3 +120,37 @@ func processFile(target *sys.Target, inname string) (map[string]bool, error) {
|
||||
}
|
||||
return undeclared, nil
|
||||
}
|
||||
|
||||
func buildKernel(target *sys.Target, dir string) {
|
||||
// TODO(dvyukov): use separate temp build dir.
|
||||
// This will allow to do build for all archs in parallel and
|
||||
// won't destroy user's build state.
|
||||
makeArgs := []string{
|
||||
"ARCH=" + target.KernelArch,
|
||||
"CROSS_COMPILE=" + target.CCompilerPrefix,
|
||||
"CFLAGS=" + strings.Join(target.CrossCFlags, " "),
|
||||
}
|
||||
out, err := osutil.RunCmd(time.Hour, dir, "make", append(makeArgs, "defconfig")...)
|
||||
if err != nil {
|
||||
failf("make defconfig failed: %v\n%s\n", err, out)
|
||||
}
|
||||
// Without CONFIG_NETFILTER kernel does not build.
|
||||
out, err = osutil.RunCmd(time.Minute, dir, "sed", "-i",
|
||||
"s@# CONFIG_NETFILTER is not set@CONFIG_NETFILTER=y@g", ".config")
|
||||
if err != nil {
|
||||
failf("sed .config failed: %v\n%s\n", err, out)
|
||||
}
|
||||
out, err = osutil.RunCmd(time.Hour, dir, "make", append(makeArgs, "olddefconfig")...)
|
||||
if err != nil {
|
||||
failf("make olddefconfig failed: %v\n%s\n", err, out)
|
||||
}
|
||||
out, err = osutil.RunCmd(time.Hour, dir, "make", append(makeArgs, "init/main.o")...)
|
||||
if err != nil {
|
||||
failf("make failed: %v\n%s\n", err, out)
|
||||
}
|
||||
}
|
||||
|
||||
func failf(msg string, args ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, msg+"\n", args...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user