2017-07-27 16:59:09 +02:00
|
|
|
# Copyright 2017 syzkaller project authors. All rights reserved.
|
2015-10-12 17:15:57 +02:00
|
|
|
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
|
|
|
|
2018-06-05 17:14:47 +02:00
|
|
|
# There are 3 OS/arch pairs:
|
2017-09-19 11:00:40 +02:00
|
|
|
# - 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
|
|
|
|
#
|
2017-12-19 15:22:08 +01:00
|
|
|
# There is one special case for extracting constants for Android
|
|
|
|
# (you don't need this unless you update system call descriptions):
|
|
|
|
# make extract TARGETOS=android SOURCEDIR=/path/to/android/checkout
|
2017-09-19 11:00:40 +02:00
|
|
|
|
2018-06-05 17:14:47 +02:00
|
|
|
define newline
|
2017-09-19 11:00:40 +02:00
|
|
|
|
2018-05-04 19:51:44 +02:00
|
|
|
|
2018-06-05 17:14:47 +02:00
|
|
|
endef
|
|
|
|
ENV := $(subst \n,$(newline),$(shell \
|
|
|
|
SOURCEDIR=$(SOURCEDIR) HOSTOS=$(HOSTOS) HOSTARCH=$(HOSTARCH) \
|
|
|
|
TARGETOS=$(TARGETOS) TARGETARCH=$(TARGETARCH) TARGETVMARCH=$(TARGETVMARCH) \
|
|
|
|
go run tools/syz-env/env.go))
|
|
|
|
$(info $(ENV))
|
|
|
|
$(eval $(ENV))
|
|
|
|
ifeq ("$(NCORES)", "")
|
|
|
|
$(error syz-env failed)
|
2017-09-19 11:00:40 +02:00
|
|
|
endif
|
2018-06-05 17:14:47 +02:00
|
|
|
MAKEFLAGS += " -j$(NCORES) "
|
|
|
|
export MAKEFLAGS
|
2017-09-19 11:00:40 +02:00
|
|
|
|
2018-06-05 17:14:47 +02:00
|
|
|
GO := go
|
2018-02-14 18:16:27 -08:00
|
|
|
# By default, build all Go binaries as static. We don't need cgo and it is
|
|
|
|
# known to cause problems at least on Android emulator.
|
|
|
|
export CGO_ENABLED=0
|
|
|
|
|
2017-09-25 15:40:58 +02:00
|
|
|
ifeq ("$(TARGETOS)", "fuchsia")
|
2018-06-06 20:55:40 +02:00
|
|
|
# SOURCEDIR should point to fuchsia checkout.
|
2018-06-26 18:59:07 +02:00
|
|
|
GO = $(SOURCEDIR)/third_party/go/bin/go
|
|
|
|
export GOROOT=$(SOURCEDIR)/third_party/go
|
2017-09-25 15:40:58 +02:00
|
|
|
export CGO_ENABLED=1
|
|
|
|
ifeq ("$(TARGETARCH)", "amd64")
|
2018-03-21 02:26:33 -07:00
|
|
|
# Required by the goroot.
|
|
|
|
export ZIRCON_BUILD_DIR=$(SOURCEDIR)/out/build-zircon/build-x64
|
2017-09-25 15:40:58 +02:00
|
|
|
else ifeq ("$(TARGETARCH)", "arm64")
|
2018-03-21 02:26:33 -07:00
|
|
|
# Required by the goroot.
|
|
|
|
export ZIRCON_BUILD_DIR=$(SOURCEDIR)/out/build-zircon/build-arm64
|
2017-09-25 15:40:58 +02:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2017-09-19 11:00:40 +02:00
|
|
|
GITREV=$(shell git rev-parse HEAD)
|
2017-12-20 15:21:19 -05:00
|
|
|
ifeq ("$(shell git diff --shortstat)", "")
|
2017-09-19 11:00:40 +02:00
|
|
|
REV=$(GITREV)
|
|
|
|
else
|
|
|
|
REV=$(GITREV)+
|
|
|
|
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 10:57:56 +01:00
|
|
|
endif
|
|
|
|
|
2017-09-19 11:00:40 +02:00
|
|
|
.PHONY: all host target \
|
2017-07-27 16:59:09 +02:00
|
|
|
manager fuzzer executor \
|
|
|
|
ci hub \
|
2018-06-21 14:38:08 +02:00
|
|
|
execprog mutate prog2c stress repro upgrade db \
|
2017-08-18 11:14:20 +02:00
|
|
|
bin/syz-sysgen bin/syz-extract bin/syz-fmt \
|
2018-05-04 19:51:44 +02:00
|
|
|
extract generate generate_go generate_sys \
|
|
|
|
format format_go format_cpp format_sys \
|
|
|
|
tidy test test_race check_links check_diff \
|
|
|
|
arch arch_darwin_amd64_host arch_linux_amd64_host \
|
|
|
|
arch_freebsd_amd64_host arch_netbsd_amd64_host \
|
|
|
|
arch_linux_amd64_target arch_linux_386_target \
|
|
|
|
arch_linux_arm64_target arch_linux_arm_target arch_linux_ppc64le_target \
|
|
|
|
arch_freebsd_amd64_target arch_netbsd_amd64_target arch_windows_amd64_target \
|
|
|
|
presubmit presubmit_parallel clean
|
2015-10-12 17:15:57 +02:00
|
|
|
|
2017-09-19 11:00:40 +02:00
|
|
|
all: host target
|
2017-09-15 10:15:00 +02:00
|
|
|
|
2017-09-19 11:00:40 +02:00
|
|
|
host:
|
2017-09-25 15:40:58 +02:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(GO) install ./syz-manager
|
2018-06-21 14:38:08 +02:00
|
|
|
$(MAKE) manager repro mutate prog2c db upgrade
|
2017-07-27 16:59:09 +02:00
|
|
|
|
2017-09-19 11:00:40 +02:00
|
|
|
target:
|
2017-09-25 15:40:58 +02:00
|
|
|
GOOS=$(TARGETOS) GOARCH=$(TARGETVMARCH) $(GO) install ./syz-fuzzer
|
2017-09-20 16:51:20 +02:00
|
|
|
$(MAKE) fuzzer execprog stress executor
|
2015-10-12 17:15:57 +02:00
|
|
|
|
2017-05-31 20:24:45 +02:00
|
|
|
# executor uses stacks of limited size, so no jumbo frames.
|
2016-01-25 10:57:56 +01:00
|
|
|
executor:
|
2017-09-19 11:00:40 +02:00
|
|
|
mkdir -p ./bin/$(TARGETOS)_$(TARGETARCH)
|
2017-09-27 11:48:07 +02:00
|
|
|
$(CC) -o ./bin/$(TARGETOS)_$(TARGETARCH)/syz-executor$(EXE) executor/executor_$(TARGETOS).cc \
|
2018-02-10 12:14:13 +01:00
|
|
|
-pthread -Wall -Wframe-larger-than=8192 -Wparentheses -Werror -O2 \
|
2017-10-16 12:18:50 +02:00
|
|
|
$(ADDCFLAGS) $(CFLAGS) -DGOOS=\"$(TARGETOS)\" -DGIT_REVISION=\"$(REV)\"
|
2017-05-26 15:32:26 +02:00
|
|
|
|
2015-12-17 16:06:33 +01:00
|
|
|
manager:
|
2017-09-25 15:40:58 +02:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(GO) build $(GOFLAGS) -o ./bin/syz-manager github.com/google/syzkaller/syz-manager
|
2015-10-12 17:15:57 +02:00
|
|
|
|
2015-12-17 16:06:33 +01:00
|
|
|
fuzzer:
|
2017-09-27 11:48:07 +02:00
|
|
|
GOOS=$(TARGETOS) GOARCH=$(TARGETVMARCH) $(GO) build $(GOFLAGS) -o ./bin/$(TARGETOS)_$(TARGETVMARCH)/syz-fuzzer$(EXE) github.com/google/syzkaller/syz-fuzzer
|
2015-10-12 17:15:57 +02:00
|
|
|
|
2015-12-21 12:38:27 +00:00
|
|
|
execprog:
|
2017-09-27 11:48:07 +02:00
|
|
|
GOOS=$(TARGETOS) GOARCH=$(TARGETVMARCH) $(GO) build $(GOFLAGS) -o ./bin/$(TARGETOS)_$(TARGETVMARCH)/syz-execprog$(EXE) github.com/google/syzkaller/tools/syz-execprog
|
2015-12-21 12:38:27 +00:00
|
|
|
|
2017-06-19 17:23:03 +02:00
|
|
|
ci:
|
2017-09-25 15:40:58 +02:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(GO) build $(GOFLAGS) -o ./bin/syz-ci github.com/google/syzkaller/syz-ci
|
2017-06-19 17:23:03 +02:00
|
|
|
|
2017-06-29 16:01:03 +02:00
|
|
|
hub:
|
2017-09-25 15:40:58 +02:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(GO) build $(GOFLAGS) -o ./bin/syz-hub github.com/google/syzkaller/syz-hub
|
2017-06-29 16:01:03 +02:00
|
|
|
|
2015-12-23 19:19:45 +01:00
|
|
|
repro:
|
2017-09-25 15:40:58 +02:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(GO) build $(GOFLAGS) -o ./bin/syz-repro github.com/google/syzkaller/tools/syz-repro
|
2015-12-23 19:19:45 +01:00
|
|
|
|
2015-12-21 12:38:27 +00:00
|
|
|
mutate:
|
2017-09-25 15:40:58 +02: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-25 15:40:58 +02: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-27 11:48:07 +02:00
|
|
|
GOOS=$(TARGETOS) GOARCH=$(TARGETVMARCH) $(GO) build $(GOFLAGS) -o ./bin/$(TARGETOS)_$(TARGETVMARCH)/syz-stress$(EXE) github.com/google/syzkaller/tools/syz-stress
|
2015-12-21 12:38:27 +00:00
|
|
|
|
2017-06-13 19:39:39 +02:00
|
|
|
db:
|
2017-09-25 15:40:58 +02:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(GO) build $(GOFLAGS) -o ./bin/syz-db github.com/google/syzkaller/tools/syz-db
|
2017-06-13 19:39:39 +02:00
|
|
|
|
2015-12-28 12:49:19 +01:00
|
|
|
upgrade:
|
2017-09-25 15:40:58 +02:00
|
|
|
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(GO) build $(GOFLAGS) -o ./bin/syz-upgrade github.com/google/syzkaller/tools/syz-upgrade
|
2015-12-28 12:49:19 +01:00
|
|
|
|
2016-08-26 07:09:25 +02:00
|
|
|
extract: bin/syz-extract
|
2018-05-18 09:48:49 +02:00
|
|
|
bin/syz-extract -build -os=$(TARGETOS) -sourcedir=$(SOURCEDIR) $(FILES)
|
2017-06-17 13:17:11 +02:00
|
|
|
bin/syz-extract:
|
2017-09-25 15:40:58 +02:00
|
|
|
$(GO) build $(GOFLAGS) -o $@ ./sys/syz-extract
|
2016-08-26 07:09:25 +02:00
|
|
|
|
2018-05-04 19:51:44 +02:00
|
|
|
generate: generate_go generate_sys
|
2017-06-13 19:39:21 +02:00
|
|
|
$(MAKE) format
|
2018-05-04 19:51:44 +02:00
|
|
|
|
2018-05-05 14:27:27 +02:00
|
|
|
generate_go: bin/syz-sysgen
|
2018-06-21 14:53:21 +02:00
|
|
|
$(GO) generate ./pkg/csource ./executor ./pkg/ifuzz ./pkg/build
|
2018-05-04 19:51:44 +02:00
|
|
|
|
|
|
|
generate_sys: bin/syz-sysgen
|
|
|
|
bin/syz-sysgen
|
|
|
|
|
2017-06-17 13:17:11 +02:00
|
|
|
bin/syz-sysgen:
|
2017-09-25 15:40:58 +02:00
|
|
|
$(GO) build $(GOFLAGS) -o $@ ./sys/syz-sysgen
|
2015-12-24 14:40:46 +01:00
|
|
|
|
2018-05-04 19:51:44 +02:00
|
|
|
format: format_go format_cpp format_sys
|
|
|
|
|
|
|
|
format_go:
|
2017-09-25 15:40:58 +02:00
|
|
|
$(GO) fmt ./...
|
2018-05-04 19:51:44 +02:00
|
|
|
|
|
|
|
format_cpp:
|
2017-01-20 11:55:19 +01:00
|
|
|
clang-format --style=file -i executor/*.cc executor/*.h tools/kcovtrace/*.c
|
2018-05-04 19:51:44 +02:00
|
|
|
|
|
|
|
format_sys: bin/syz-fmt
|
2017-12-13 13:49:08 +01:00
|
|
|
bin/syz-fmt sys/test
|
2017-10-17 11:02:27 +02:00
|
|
|
bin/syz-fmt sys/akaros
|
2017-10-02 14:14:48 +02:00
|
|
|
bin/syz-fmt sys/freebsd
|
2017-10-24 15:24:37 +05:30
|
|
|
bin/syz-fmt sys/netbsd
|
2017-09-19 11:00:40 +02:00
|
|
|
bin/syz-fmt sys/linux
|
2017-09-25 08:47:30 +02:00
|
|
|
bin/syz-fmt sys/fuchsia
|
2017-09-27 20:17:09 +02:00
|
|
|
bin/syz-fmt sys/windows
|
2018-05-04 19:51:44 +02:00
|
|
|
|
2017-08-18 11:14:20 +02:00
|
|
|
bin/syz-fmt:
|
2017-09-25 15:40:58 +02:00
|
|
|
$(GO) build $(GOFLAGS) -o $@ ./tools/syz-fmt
|
2016-08-28 14:59:48 +02:00
|
|
|
|
2017-06-13 17:21:33 +02:00
|
|
|
tidy:
|
2017-06-14 12:56:42 +02:00
|
|
|
# A single check is enabled for now. But it's always fixable and proved to be useful.
|
2017-06-13 17:21:33 +02:00
|
|
|
clang-tidy -quiet -header-filter=.* -checks=-*,misc-definitions-in-headers -warnings-as-errors=* executor/*.cc
|
2017-06-14 12:56:42 +02:00
|
|
|
# Just check for compiler warnings.
|
|
|
|
$(CC) executor/test_executor.cc -c -o /dev/null -Wparentheses -Wno-unused -Wall
|
2017-06-13 17:21:33 +02:00
|
|
|
|
2018-03-20 13:26:51 +01:00
|
|
|
gometalinter:
|
|
|
|
env CGO_ENABLED=1 gometalinter.v2 ./...
|
|
|
|
|
2018-05-04 19:51:44 +02:00
|
|
|
arch: arch_darwin_amd64_host arch_linux_amd64_host arch_freebsd_amd64_host arch_netbsd_amd64_host \
|
|
|
|
arch_linux_amd64_target arch_linux_386_target \
|
|
|
|
arch_linux_arm64_target arch_linux_arm_target arch_linux_ppc64le_target \
|
|
|
|
arch_freebsd_amd64_target arch_netbsd_amd64_target arch_windows_amd64_target
|
2017-07-27 16:59:09 +02:00
|
|
|
|
2018-05-04 19:51:44 +02:00
|
|
|
arch_darwin_amd64_host:
|
2017-09-19 11:00:40 +02:00
|
|
|
env HOSTOS=darwin HOSTARCH=amd64 $(MAKE) host
|
2018-05-04 19:51:44 +02:00
|
|
|
|
|
|
|
arch_linux_amd64_host:
|
2017-09-19 11:00:40 +02:00
|
|
|
env HOSTOS=linux HOSTARCH=amd64 $(MAKE) host
|
2018-05-04 19:51:44 +02:00
|
|
|
|
|
|
|
arch_linux_amd64_target:
|
2017-09-19 11:00:40 +02:00
|
|
|
env TARGETOS=linux TARGETARCH=amd64 $(MAKE) target
|
2018-05-04 19:51:44 +02:00
|
|
|
|
|
|
|
arch_linux_386_target:
|
2017-09-21 10:25:59 +02: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
|
2018-05-04 19:51:44 +02:00
|
|
|
|
|
|
|
arch_linux_arm64_target:
|
|
|
|
env TARGETOS=linux TARGETARCH=arm64 $(MAKE) target
|
|
|
|
|
|
|
|
arch_linux_arm_target:
|
|
|
|
# executor build on arm fails with:
|
|
|
|
# Error: alignment too large: 15 assumed
|
|
|
|
env TARGETOS=linux TARGETARCH=arm64 TARGETVMARCH=arm $(MAKE) target
|
|
|
|
|
|
|
|
arch_linux_ppc64le_target:
|
|
|
|
env TARGETOS=linux TARGETARCH=ppc64le $(MAKE) target
|
|
|
|
|
|
|
|
arch_freebsd_amd64_host:
|
|
|
|
env HOSTOS=freebsd HOSTARCH=amd64 $(MAKE) host
|
|
|
|
|
|
|
|
arch_freebsd_amd64_target:
|
2017-10-23 10:19:56 +02:00
|
|
|
env TARGETOS=freebsd TARGETARCH=amd64 $(MAKE) target
|
2018-05-04 19:51:44 +02:00
|
|
|
|
|
|
|
arch_netbsd_amd64_host:
|
|
|
|
env HOSTOS=netbsd HOSTARCH=amd64 $(MAKE) host
|
|
|
|
|
|
|
|
arch_netbsd_amd64_target:
|
2017-10-23 10:19:56 +02:00
|
|
|
env TARGETOS=netbsd TARGETARCH=amd64 $(MAKE) target
|
2017-07-27 16:59:09 +02:00
|
|
|
|
2018-05-04 19:51:44 +02:00
|
|
|
arch_windows_amd64_target:
|
|
|
|
env GOOG=windows GOARCH=amd64 $(GO) install ./syz-fuzzer
|
|
|
|
env TARGETOS=windows TARGETARCH=amd64 $(MAKE) fuzzer execprog stress
|
|
|
|
|
2017-07-27 16:59:09 +02:00
|
|
|
presubmit:
|
|
|
|
$(MAKE) generate
|
2017-11-20 17:23:36 +01:00
|
|
|
$(MAKE) check_diff
|
2018-05-04 19:51:44 +02:00
|
|
|
$(GO) install ./...
|
|
|
|
$(MAKE) presubmit_parallel
|
2018-05-13 11:59:44 +02:00
|
|
|
$(MAKE) gometalinter
|
2016-08-28 16:33:32 +02:00
|
|
|
echo LGTM
|
2015-10-12 17:15:57 +02:00
|
|
|
|
2018-05-13 11:59:44 +02:00
|
|
|
presubmit_parallel: test test_race arch check_links
|
2018-05-04 19:51:44 +02:00
|
|
|
|
|
|
|
test:
|
|
|
|
# Executor tests use cgo.
|
|
|
|
env CGO_ENABLED=1 $(GO) test -short ./...
|
|
|
|
|
|
|
|
test_race:
|
|
|
|
env CGO_ENABLED=1 $(GO) test -short -race -bench=.* -benchtime=.2s ./...
|
|
|
|
|
2017-07-27 16:59:09 +02:00
|
|
|
clean:
|
|
|
|
rm -rf ./bin/
|
2017-09-25 08:47:15 +02:00
|
|
|
|
2018-03-20 13:26:51 +01:00
|
|
|
# For a tupical Ubuntu/Debian distribution.
|
2018-05-12 10:10:02 +02:00
|
|
|
# We use "|| true" for apt-get install because packages are all different on different distros,
|
|
|
|
# and we want to install at least gometalinter on Travis CI.
|
2017-09-25 08:47:15 +02:00
|
|
|
install_prerequisites:
|
2018-05-13 11:34:03 +02:00
|
|
|
uname -a
|
|
|
|
sudo apt-get update
|
2018-04-02 19:38:11 +02:00
|
|
|
sudo apt-get install -y -q libc6-dev-i386 linux-libc-dev \
|
2018-05-12 10:10:02 +02:00
|
|
|
gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf gcc-powerpc64le-linux-gnu || true
|
2018-05-18 09:48:49 +02:00
|
|
|
sudo apt-get install -y -q g++-aarch64-linux-gnu || true
|
|
|
|
sudo apt-get install -y -q g++-powerpc64le-linux-gnu || true
|
|
|
|
sudo apt-get install -y -q g++-arm-linux-gnueabihf || true
|
2018-03-20 13:26:51 +01:00
|
|
|
go get -u gopkg.in/alecthomas/gometalinter.v2
|
|
|
|
gometalinter.v2 --install
|
2017-10-26 18:48:54 +02:00
|
|
|
|
|
|
|
check_links:
|
|
|
|
python ./tools/check_links.py $$(pwd) $$(ls ./*.md; find ./docs/ -name '*.md')
|
2017-11-20 17:23:36 +01:00
|
|
|
|
|
|
|
# Check that the diff is empty. This is meant to be executed after generating
|
|
|
|
# and formatting the code to make sure that everything is committed.
|
|
|
|
check_diff:
|
|
|
|
DIFF="$(shell git diff --name-only)"; test -z "$$DIFF"
|