2017-07-27 14:59:09 +00:00
|
|
|
# Copyright 2017 syzkaller project authors. All rights reserved.
|
2015-10-12 15:15:57 +00:00
|
|
|
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
|
|
|
|
2017-09-19 09:00:40 +00:00
|
|
|
# There are 4 OS/arch pairs:
|
|
|
|
# - BUILDOS/BUILDARCH: the current machine's pair used for build.
|
|
|
|
# - HOSTOS/HOSTARCH: pair where syz-manager will run.
|
|
|
|
# - TARGETOS/TARGETVMARCH: pair of the target OS under test.
|
|
|
|
# - TARGETOS/TARGETARCH: pair of the target test process.
|
|
|
|
#
|
|
|
|
# The last 2 differ for e.g. amd64 OS and 386 test processes (compat syscall testing).
|
|
|
|
# All pairs default to the current machine. All but BUILD can be overriden.
|
|
|
|
#
|
|
|
|
# For example, to test linux/amd64 on linux/amd64, you just run:
|
|
|
|
# make
|
|
|
|
# To test linux/arm64 from darwin/amd64 host, run:
|
|
|
|
# make HOSTOS=darwin HOSTARCH=amd64 TARGETOS=linux TARGETARCH=arm64
|
|
|
|
# To test x86 compat syscalls, run:
|
|
|
|
# make TARGETVMARCH=amd64 TARGETARCH=386
|
|
|
|
#
|
|
|
|
# There is a special case for Android builds:
|
|
|
|
# NDK=/path/to/android/ndk make TARGETOS=android TARGETARCH=arm64
|
|
|
|
# But you still need to specify "target": "linux/arm64" in syz-manager config.
|
|
|
|
|
|
|
|
BUILDOS := $(shell go env GOOS)
|
|
|
|
BUILDARCH := $(shell go env GOARCH)
|
|
|
|
HOSTOS ?= $(BUILDOS)
|
|
|
|
HOSTARCH ?= $(BUILDARCH)
|
|
|
|
TARGETOS ?= $(HOSTOS)
|
|
|
|
TARGETARCH ?= $(HOSTARCH)
|
|
|
|
TARGETVMARCH ?= $(TARGETARCH)
|
|
|
|
|
|
|
|
ifeq ("$(TARGETARCH)", "amd64")
|
|
|
|
CC = "x86_64-linux-gnu-gcc"
|
|
|
|
else ifeq ("$(TARGETARCH)", "386")
|
|
|
|
CC = "x86_64-linux-gnu-gcc"
|
|
|
|
ADDCFLAGS = "-m32"
|
|
|
|
else ifeq ("$(TARGETARCH)", "arm64")
|
|
|
|
CC = "aarch64-linux-gnu-gcc"
|
|
|
|
else ifeq ("$(TARGETARCH)", "arm")
|
|
|
|
CC = "arm-linux-gnueabihf-gcc"
|
|
|
|
ADDCFLAGS = "-march=armv6t2"
|
|
|
|
else ifeq ("$(TARGETARCH)", "ppc64le")
|
|
|
|
CC = "powerpc64le-linux-gnu-gcc"
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ("$(TARGETOS)", "android")
|
|
|
|
override TARGETOS = "linux"
|
|
|
|
ANDROID_API = 24
|
|
|
|
BUILDGCCARCH = ""
|
|
|
|
ANDROIDARCH = ""
|
|
|
|
TOOLCHAIN = ""
|
|
|
|
GCCBIN = ""
|
|
|
|
ifeq ("$(TARGETARCH)", "amd64")
|
|
|
|
ANDROIDARCH = "x86_64"
|
|
|
|
TOOLCHAIN = "x86_64-4.9"
|
|
|
|
GCCBIN = "x86_64-linux-android-g++"
|
|
|
|
else ifeq ("$(TARGETARCH)", "386")
|
|
|
|
ANDROIDARCH = "x86"
|
|
|
|
TOOLCHAIN = "x86-4.9"
|
|
|
|
GCCBIN = "i686-linux-android-g++"
|
|
|
|
else ifeq ("$(TARGETARCH)", "arm64")
|
|
|
|
ANDROIDARCH = "arm64"
|
|
|
|
TOOLCHAIN = "aarch64-linux-android-4.9"
|
|
|
|
GCCBIN = "aarch64-linux-android-g++"
|
|
|
|
else ifeq ("$(TARGETARCH)", "arm")
|
|
|
|
ANDROIDARCH = "arm"
|
|
|
|
TOOLCHAIN = "arm-linux-androideabi-4.9"
|
|
|
|
GCCBIN = "arm-linux-androideabi-g++"
|
|
|
|
endif
|
|
|
|
ifeq ("$(BUILDARCH)", "amd64")
|
|
|
|
BUILDGCCARCH = "x86_64"
|
|
|
|
else ifeq ("$(BUILDARCH)", "arm64")
|
|
|
|
BUILDGCCARCH = "aarch64"
|
|
|
|
endif
|
|
|
|
CC = $(NDK)/toolchains/$(TOOLCHAIN)/prebuilt/$(BUILDOS)-$(BUILDGCCARCH)/bin/$(GCCBIN)
|
|
|
|
CFLAGS = -I $(NDK)/sources/cxx-stl/llvm-libc++/include --sysroot=$(NDK)/platforms/android-$(ANDROID_API)/arch-$(ANDROIDARCH) -O1 -g -Wall -static
|
|
|
|
endif
|
|
|
|
|
|
|
|
GITREV=$(shell git rev-parse HEAD)
|
|
|
|
ifeq ($(`git diff --shortstat`), "")
|
|
|
|
REV=$(GITREV)
|
|
|
|
else
|
|
|
|
REV=$(GITREV)+
|
|
|
|
endif
|
|
|
|
|
2016-01-25 09:57:56 +00:00
|
|
|
NOSTATIC ?= 0
|
|
|
|
ifeq ($(NOSTATIC), 0)
|
2017-09-19 09:00:40 +00:00
|
|
|
ADDCFLAGS += -static
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Don't generate symbol table and DWARF debug info.
|
|
|
|
# Reduces build time and binary sizes considerably.
|
|
|
|
# That's only needed if you use gdb or nm.
|
|
|
|
# If you need that, build manually without these flags.
|
|
|
|
GOFLAGS := "-ldflags=-s -w -X github.com/google/syzkaller/sys.GitRevision=$(REV)"
|
|
|
|
ifneq ("$(GOTAGS)", "")
|
|
|
|
GOFLAGS += "-tags=$(GOTAGS)"
|
2016-01-25 09:57:56 +00:00
|
|
|
endif
|
|
|
|
|
2017-09-19 09:00:40 +00:00
|
|
|
.PHONY: all host target \
|
2017-07-27 14:59:09 +00:00
|
|
|
manager fuzzer executor \
|
|
|
|
ci hub \
|
|
|
|
execprog mutate prog2c stress repro upgrade db \
|
2017-08-18 09:14:20 +00:00
|
|
|
bin/syz-sysgen bin/syz-extract bin/syz-fmt \
|
2017-07-27 14:59:09 +00:00
|
|
|
extract generate \
|
2017-09-19 09:00:40 +00:00
|
|
|
format tidy test arch presubmit clean
|
2015-10-12 15:15:57 +00:00
|
|
|
|
2017-09-19 09:00:40 +00:00
|
|
|
all: host target
|
2017-09-15 08:15:00 +00:00
|
|
|
|
2017-09-19 09:00:40 +00:00
|
|
|
host:
|
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) go install ./syz-manager
|
2017-09-20 14:51:20 +00:00
|
|
|
$(MAKE) manager repro mutate prog2c db upgrade
|
2017-07-27 14:59:09 +00:00
|
|
|
|
2017-09-19 09:00:40 +00:00
|
|
|
target:
|
|
|
|
GOOS=$(TARGETOS) GOARCH=$(TARGETVMARCH) go install ./syz-fuzzer
|
2017-09-20 14:51:20 +00:00
|
|
|
$(MAKE) fuzzer execprog stress executor
|
2015-10-12 15:15:57 +00:00
|
|
|
|
2017-05-31 18:24:45 +00:00
|
|
|
# executor uses stacks of limited size, so no jumbo frames.
|
2016-01-25 09:57:56 +00:00
|
|
|
executor:
|
2017-09-19 09:00:40 +00:00
|
|
|
mkdir -p ./bin/$(TARGETOS)_$(TARGETARCH)
|
2017-09-20 14:55:28 +00:00
|
|
|
$(CC) -o ./bin/$(TARGETOS)_$(TARGETARCH)/syz-executor executor/executor_$(TARGETOS).cc \
|
2017-09-19 09:00:40 +00:00
|
|
|
-pthread -Wall -Wframe-larger-than=8192 -Wparentheses -Werror -O1 -g \
|
|
|
|
$(ADDCFLAGS) $(CFLAGS) -DGIT_REVISION=\"$(REV)\"
|
2017-05-26 13:32:26 +00:00
|
|
|
|
2015-12-17 15:06:33 +00:00
|
|
|
manager:
|
2017-09-20 14:51:20 +00:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) go build $(GOFLAGS) -o ./bin/syz-manager github.com/google/syzkaller/syz-manager
|
2015-10-12 15:15:57 +00:00
|
|
|
|
2015-12-17 15:06:33 +00:00
|
|
|
fuzzer:
|
2017-09-20 14:51:20 +00:00
|
|
|
GOOS=$(TARGETOS) GOARCH=$(TARGETVMARCH) go build $(GOFLAGS) -o ./bin/$(TARGETOS)_$(TARGETVMARCH)/syz-fuzzer github.com/google/syzkaller/syz-fuzzer
|
2015-10-12 15:15:57 +00:00
|
|
|
|
2015-12-21 12:38:27 +00:00
|
|
|
execprog:
|
2017-09-20 14:51:20 +00:00
|
|
|
GOOS=$(TARGETOS) GOARCH=$(TARGETVMARCH) go build $(GOFLAGS) -o ./bin/$(TARGETOS)_$(TARGETVMARCH)/syz-execprog github.com/google/syzkaller/tools/syz-execprog
|
2015-12-21 12:38:27 +00:00
|
|
|
|
2017-06-19 15:23:03 +00:00
|
|
|
ci:
|
2017-09-20 14:51:20 +00:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) go build $(GOFLAGS) -o ./bin/syz-ci github.com/google/syzkaller/syz-ci
|
2017-06-19 15:23:03 +00:00
|
|
|
|
2017-06-29 14:01:03 +00:00
|
|
|
hub:
|
2017-09-20 14:51:20 +00:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) go build $(GOFLAGS) -o ./bin/syz-hub github.com/google/syzkaller/syz-hub
|
2017-06-29 14:01:03 +00:00
|
|
|
|
2015-12-23 18:19:45 +00:00
|
|
|
repro:
|
2017-09-20 14:51:20 +00:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) go build $(GOFLAGS) -o ./bin/syz-repro github.com/google/syzkaller/tools/syz-repro
|
2015-12-23 18:19:45 +00:00
|
|
|
|
2015-12-21 12:38:27 +00:00
|
|
|
mutate:
|
2017-09-20 14:51:20 +00:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) go build $(GOFLAGS) -o ./bin/syz-mutate github.com/google/syzkaller/tools/syz-mutate
|
2015-12-21 12:38:27 +00:00
|
|
|
|
|
|
|
prog2c:
|
2017-09-20 14:51:20 +00:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) go build $(GOFLAGS) -o ./bin/syz-prog2c github.com/google/syzkaller/tools/syz-prog2c
|
2015-12-21 12:38:27 +00:00
|
|
|
|
|
|
|
stress:
|
2017-09-20 14:51:20 +00:00
|
|
|
GOOS=$(TARGETOS) GOARCH=$(TARGETVMARCH) go build $(GOFLAGS) -o ./bin/$(TARGETOS)_$(TARGETVMARCH)/syz-stress github.com/google/syzkaller/tools/syz-stress
|
2015-12-21 12:38:27 +00:00
|
|
|
|
2017-06-13 17:39:39 +00:00
|
|
|
db:
|
2017-09-20 14:51:20 +00:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) go build $(GOFLAGS) -o ./bin/syz-db github.com/google/syzkaller/tools/syz-db
|
2017-06-13 17:39:39 +00:00
|
|
|
|
2015-12-28 11:49:19 +00:00
|
|
|
upgrade:
|
2017-09-20 14:51:20 +00:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) go build $(GOFLAGS) -o ./bin/syz-upgrade github.com/google/syzkaller/tools/syz-upgrade
|
2015-12-28 11:49:19 +00:00
|
|
|
|
2016-08-26 05:09:25 +00:00
|
|
|
extract: bin/syz-extract
|
2017-09-25 06:47:15 +00:00
|
|
|
bin/syz-extract -build -os=$(TARGETOS) -sourcedir=$(SOURCEDIR)
|
2017-06-17 11:17:11 +00:00
|
|
|
bin/syz-extract:
|
2017-06-17 11:54:15 +00:00
|
|
|
go build $(GOFLAGS) -o $@ ./sys/syz-extract
|
2016-08-26 05:09:25 +00:00
|
|
|
|
|
|
|
generate: bin/syz-sysgen
|
|
|
|
bin/syz-sysgen
|
2017-08-02 17:24:44 +00:00
|
|
|
go generate ./pkg/csource ./executor ./pkg/ifuzz ./pkg/kernel
|
2017-06-13 17:39:21 +00:00
|
|
|
$(MAKE) format
|
2017-06-17 11:17:11 +00:00
|
|
|
bin/syz-sysgen:
|
2017-06-17 11:28:22 +00:00
|
|
|
go build $(GOFLAGS) -o $@ ./sys/syz-sysgen
|
2015-12-24 13:40:46 +00:00
|
|
|
|
2017-08-18 09:14:20 +00:00
|
|
|
format: bin/syz-fmt
|
2015-11-10 19:32:03 +00:00
|
|
|
go fmt ./...
|
2017-01-20 10:55:19 +00:00
|
|
|
clang-format --style=file -i executor/*.cc executor/*.h tools/kcovtrace/*.c
|
2017-09-19 09:00:40 +00:00
|
|
|
bin/syz-fmt sys/linux
|
2017-08-18 09:14:20 +00:00
|
|
|
bin/syz-fmt:
|
|
|
|
go build $(GOFLAGS) -o $@ ./tools/syz-fmt
|
2016-08-28 12:59:48 +00:00
|
|
|
|
2017-06-13 15:21:33 +00:00
|
|
|
tidy:
|
2017-06-14 10:56:42 +00:00
|
|
|
# A single check is enabled for now. But it's always fixable and proved to be useful.
|
2017-06-13 15:21:33 +00:00
|
|
|
clang-tidy -quiet -header-filter=.* -checks=-*,misc-definitions-in-headers -warnings-as-errors=* executor/*.cc
|
2017-06-14 10:56:42 +00:00
|
|
|
# Just check for compiler warnings.
|
|
|
|
$(CC) executor/test_executor.cc -c -o /dev/null -Wparentheses -Wno-unused -Wall
|
2017-06-13 15:21:33 +00:00
|
|
|
|
2017-07-27 14:59:09 +00:00
|
|
|
test:
|
|
|
|
go test -short ./...
|
|
|
|
go test -short -race ./...
|
|
|
|
|
|
|
|
arch:
|
2017-09-19 09:00:40 +00:00
|
|
|
env HOSTOS=darwin HOSTARCH=amd64 $(MAKE) host
|
|
|
|
env HOSTOS=linux HOSTARCH=amd64 $(MAKE) host
|
|
|
|
env TARGETOS=linux TARGETARCH=amd64 $(MAKE) target
|
|
|
|
env TARGETOS=linux TARGETARCH=arm64 $(MAKE) target
|
|
|
|
env TARGETOS=linux TARGETARCH=ppc64le $(MAKE) target
|
|
|
|
# executor build on arm fails with:
|
|
|
|
# Error: alignment too large: 15 assumed
|
|
|
|
env TARGETOS=linux TARGETARCH=arm64 TARGETVMARCH=arm $(MAKE) target
|
2017-09-21 08:25:59 +00:00
|
|
|
# executor build on 386 on travis fails with:
|
|
|
|
# fatal error: asm/errno.h: No such file or directory
|
|
|
|
# We install a bunch of additional packages in .travis.yml,
|
|
|
|
# but I can't guess the right one.
|
|
|
|
env TARGETOS=linux TARGETARCH=amd64 TARGETVMARCH=386 $(MAKE) target
|
2017-07-27 14:59:09 +00:00
|
|
|
|
|
|
|
presubmit:
|
|
|
|
$(MAKE) generate
|
|
|
|
$(MAKE) all
|
|
|
|
$(MAKE) arch
|
|
|
|
$(MAKE) test
|
2016-08-28 14:33:32 +00:00
|
|
|
echo LGTM
|
2015-10-12 15:15:57 +00:00
|
|
|
|
2017-07-27 14:59:09 +00:00
|
|
|
clean:
|
|
|
|
rm -rf ./bin/
|
2017-09-25 06:47:15 +00:00
|
|
|
|
|
|
|
# For a tupical Ubuntu/Debian distribution, requires sudo.
|
|
|
|
install_prerequisites:
|
|
|
|
apt-get install libc6-dev-i386 lib32stdc++-4.8-dev linux-libc-dev g++-aarch64-linux-gnu g++-powerpc64le-linux-gnu g++-arm-linux-gnueabihf
|