1# Copyright 2017 syzkaller project authors. All rights reserved. 2# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4# There are 3 OS/arch pairs: 5# - HOSTOS/HOSTARCH: pair where syz-manager will run. 6# - TARGETOS/TARGETVMARCH: pair of the target OS under test. 7# - TARGETOS/TARGETARCH: pair of the target test process. 8# 9# The last 2 differ for e.g. amd64 OS and 386 test processes (compat syscall testing). 10# All pairs default to the current machine. All but BUILD can be overriden. 11# 12# For example, to test linux/amd64 on linux/amd64, you just run: 13# make 14# To test linux/arm64 from darwin/amd64 host, run: 15# make HOSTOS=darwin HOSTARCH=amd64 TARGETOS=linux TARGETARCH=arm64 16# To test x86 compat syscalls, run: 17# make TARGETVMARCH=amd64 TARGETARCH=386 18# 19# There is one special case for extracting constants for Android 20# (you don't need this unless you update system call descriptions): 21# make extract TARGETOS=android SOURCEDIR=/path/to/android/checkout 22 23define newline 24 25 26endef 27ENV := $(subst \n,$(newline),$(shell \ 28 SOURCEDIR=$(SOURCEDIR) HOSTOS=$(HOSTOS) HOSTARCH=$(HOSTARCH) \ 29 TARGETOS=$(TARGETOS) TARGETARCH=$(TARGETARCH) TARGETVMARCH=$(TARGETVMARCH) \ 30 go run tools/syz-env/env.go)) 31$(info $(ENV)) 32$(eval $(ENV)) 33ifeq ("$(NCORES)", "") 34$(error syz-env failed) 35endif 36MAKEFLAGS += " -j$(NCORES) " 37export MAKEFLAGS 38 39GO := go 40HOSTGO := go 41# By default, build all Go binaries as static. We don't need cgo and it is 42# known to cause problems at least on Android emulator. 43export CGO_ENABLED=0 44TARGETGOOS := $(TARGETOS) 45TARGETGOARCH := $(TARGETVMARCH) 46 47ifeq ("$(TARGETOS)", "fuchsia") 48 # SOURCEDIR should point to fuchsia checkout. 49 GO = "$(SOURCEDIR)/scripts/devshell/go" 50endif 51 52GITREV=$(shell git rev-parse HEAD) 53ifeq ("$(shell git diff --shortstat)", "") 54 REV=$(GITREV) 55else 56 REV=$(GITREV)+ 57endif 58 59# Don't generate symbol table and DWARF debug info. 60# Reduces build time and binary sizes considerably. 61# That's only needed if you use gdb or nm. 62# If you need that, build manually without these flags. 63GOFLAGS := "-ldflags=-s -w -X github.com/google/syzkaller/sys.GitRevision=$(REV)" 64GOHOSTFLAGS := $(GOFLAGS) 65GOTARGETFLAGS := $(GOFLAGS) 66ifneq ("$(GOTAGS)", "") 67 GOHOSTFLAGS += "-tags=$(GOTAGS)" 68endif 69GOTARGETFLAGS += "-tags=syz_target syz_os_$(TARGETOS) syz_arch_$(TARGETVMARCH) $(GOTAGS)" 70 71ifeq ("$(TARGETOS)", "test") 72 TARGETGOOS := $(HOSTOS) 73 TARGETGOARCH := $(HOSTARCH) 74endif 75 76ifeq ("$(TARGETOS)", "akaros") 77 TARGETGOOS := $(HOSTOS) 78 TARGETGOARCH := $(HOSTARCH) 79endif 80 81.PHONY: all host target \ 82 manager runtest fuzzer executor \ 83 ci hub \ 84 execprog mutate prog2c stress repro upgrade db \ 85 bin/syz-sysgen bin/syz-extract bin/syz-fmt \ 86 extract generate generate_go generate_sys \ 87 format format_go format_cpp format_sys \ 88 tidy test test_race check_links check_diff \ 89 arch arch_darwin_amd64_host arch_linux_amd64_host \ 90 arch_freebsd_amd64_host arch_netbsd_amd64_host \ 91 arch_linux_amd64_target arch_linux_386_target \ 92 arch_linux_arm64_target arch_linux_arm_target arch_linux_ppc64le_target \ 93 arch_freebsd_amd64_target arch_netbsd_amd64_target arch_windows_amd64_target \ 94 arch_test presubmit presubmit_parallel clean 95 96all: host target 97 98host: 99 GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) install ./syz-manager 100 $(MAKE) manager runtest repro mutate prog2c db upgrade 101 102target: 103 GOOS=$(TARGETGOOS) GOARCH=$(TARGETGOARCH) $(GO) install ./syz-fuzzer 104 $(MAKE) fuzzer execprog stress executor 105 106# executor uses stacks of limited size, so no jumbo frames. 107executor: 108 mkdir -p ./bin/$(TARGETOS)_$(TARGETARCH) 109 $(CC) -o ./bin/$(TARGETOS)_$(TARGETARCH)/syz-executor$(EXE) executor/executor.cc \ 110 -pthread -Wall -Wframe-larger-than=8192 -Wparentheses -Werror -O2 $(ADDCFLAGS) $(CFLAGS) \ 111 -DGOOS_$(TARGETOS)=1 -DGOARCH_$(TARGETARCH)=1 -DGIT_REVISION=\"$(REV)\" 112 113manager: 114 GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-manager github.com/google/syzkaller/syz-manager 115 116runtest: 117 GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-runtest github.com/google/syzkaller/tools/syz-runtest 118 119fuzzer: 120 GOOS=$(TARGETGOOS) GOARCH=$(TARGETGOARCH) $(GO) build $(GOTARGETFLAGS) -o ./bin/$(TARGETOS)_$(TARGETVMARCH)/syz-fuzzer$(EXE) github.com/google/syzkaller/syz-fuzzer 121 122execprog: 123 GOOS=$(TARGETGOOS) GOARCH=$(TARGETGOARCH) $(GO) build $(GOTARGETFLAGS) -o ./bin/$(TARGETOS)_$(TARGETVMARCH)/syz-execprog$(EXE) github.com/google/syzkaller/tools/syz-execprog 124 125ci: 126 GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-ci github.com/google/syzkaller/syz-ci 127 128hub: 129 GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-hub github.com/google/syzkaller/syz-hub 130 131repro: 132 GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-repro github.com/google/syzkaller/tools/syz-repro 133 134mutate: 135 GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-mutate github.com/google/syzkaller/tools/syz-mutate 136 137prog2c: 138 GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-prog2c github.com/google/syzkaller/tools/syz-prog2c 139 140stress: 141 GOOS=$(TARGETGOOS) GOARCH=$(TARGETGOARCH) $(GO) build $(GOTARGETFLAGS) -o ./bin/$(TARGETOS)_$(TARGETVMARCH)/syz-stress$(EXE) github.com/google/syzkaller/tools/syz-stress 142 143db: 144 GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-db github.com/google/syzkaller/tools/syz-db 145 146upgrade: 147 GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-upgrade github.com/google/syzkaller/tools/syz-upgrade 148 149extract: bin/syz-extract 150 bin/syz-extract -build -os=$(TARGETOS) -sourcedir=$(SOURCEDIR) $(FILES) 151bin/syz-extract: 152 GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o $@ ./sys/syz-extract 153 154generate: generate_go generate_sys 155 $(MAKE) format 156 157generate_go: bin/syz-sysgen format_cpp 158 $(GO) generate ./pkg/csource ./executor ./pkg/ifuzz ./pkg/build 159 160generate_sys: bin/syz-sysgen 161 bin/syz-sysgen 162 163bin/syz-sysgen: 164 $(GO) build $(GOHOSTFLAGS) -o $@ ./sys/syz-sysgen 165 166format: format_go format_cpp format_sys 167 168format_go: 169 $(GO) fmt ./... 170 171format_cpp: 172 clang-format --style=file -i executor/*.cc executor/*.h tools/kcovtrace/*.c 173 174format_sys: bin/syz-fmt 175 bin/syz-fmt sys/test 176 bin/syz-fmt sys/akaros 177 bin/syz-fmt sys/freebsd 178 bin/syz-fmt sys/netbsd 179 bin/syz-fmt sys/linux 180 bin/syz-fmt sys/fuchsia 181 bin/syz-fmt sys/windows 182 183bin/syz-fmt: 184 $(GO) build $(GOHOSTFLAGS) -o $@ ./tools/syz-fmt 185 186tidy: 187 # A single check is enabled for now. But it's always fixable and proved to be useful. 188 clang-tidy -quiet -header-filter=.* -checks=-*,misc-definitions-in-headers -warnings-as-errors=* executor/*.cc 189 # Just check for compiler warnings. 190 $(CC) executor/test_executor.cc -c -o /dev/null -Wparentheses -Wno-unused -Wall 191 192gometalinter: 193 env CGO_ENABLED=1 gometalinter.v2 ./... 194 195arch: arch_darwin_amd64_host arch_linux_amd64_host arch_freebsd_amd64_host arch_netbsd_amd64_host \ 196 arch_linux_amd64_target arch_linux_386_target \ 197 arch_linux_arm64_target arch_linux_arm_target arch_linux_ppc64le_target \ 198 arch_freebsd_amd64_target arch_netbsd_amd64_target arch_windows_amd64_target \ 199 arch_test 200 201arch_darwin_amd64_host: 202 env HOSTOS=darwin HOSTARCH=amd64 $(MAKE) host 203 204arch_linux_amd64_host: 205 env HOSTOS=linux HOSTARCH=amd64 $(MAKE) host 206 207arch_linux_amd64_target: 208 env TARGETOS=linux TARGETARCH=amd64 $(MAKE) target 209 210arch_linux_386_target: 211 # executor build on 386 on travis fails with: 212 # fatal error: asm/errno.h: No such file or directory 213 # We install a bunch of additional packages in .travis.yml, 214 # but I can't guess the right one. 215 env TARGETOS=linux TARGETARCH=amd64 TARGETVMARCH=386 $(MAKE) target 216 217arch_linux_arm64_target: 218 env TARGETOS=linux TARGETARCH=arm64 $(MAKE) target 219 220arch_linux_arm_target: 221 # executor build on arm fails with: 222 # Error: alignment too large: 15 assumed 223 env TARGETOS=linux TARGETARCH=arm64 TARGETVMARCH=arm $(MAKE) target 224 225arch_linux_ppc64le_target: 226 env TARGETOS=linux TARGETARCH=ppc64le $(MAKE) target 227 228arch_freebsd_amd64_host: 229 env HOSTOS=freebsd HOSTARCH=amd64 $(MAKE) host 230 231arch_freebsd_amd64_target: 232 env TARGETOS=freebsd TARGETARCH=amd64 $(MAKE) target 233 234arch_netbsd_amd64_host: 235 env HOSTOS=netbsd HOSTARCH=amd64 $(MAKE) host 236 237arch_netbsd_amd64_target: 238 env TARGETOS=netbsd TARGETARCH=amd64 $(MAKE) target 239 240arch_windows_amd64_target: 241 env GOOG=windows GOARCH=amd64 $(GO) install ./syz-fuzzer 242 env TARGETOS=windows TARGETARCH=amd64 $(MAKE) fuzzer execprog stress 243 244arch_test: 245 env TARGETOS=test TARGETARCH=64 $(MAKE) executor 246 env TARGETOS=test TARGETARCH=64_fork $(MAKE) executor 247 # 32-bit build fails on travis with: 248 # /usr/include/c++/4.8/utility:68:28: fatal error: bits/c++config.h: No such file or directory 249 # #include <bits/c++config.h> 250 # env TARGETOS=test TARGETARCH=32_shmem $(MAKE) executor 251 # env TARGETOS=test TARGETARCH=32_fork_shmem $(MAKE) executor 252 253presubmit: 254 $(MAKE) generate 255 $(MAKE) check_diff 256 $(GO) install ./... 257 $(MAKE) presubmit_parallel 258 $(MAKE) gometalinter 259 echo LGTM 260 261presubmit_parallel: test test_race arch check_links 262 263test: 264 # Executor tests use cgo. 265 env CGO_ENABLED=1 $(GO) test -short ./... 266 267test_race: 268 env CGO_ENABLED=1 $(GO) test -short -race -bench=.* -benchtime=.2s ./... 269 270clean: 271 rm -rf ./bin/ 272 273# For a tupical Ubuntu/Debian distribution. 274# We use "|| true" for apt-get install because packages are all different on different distros, 275# and we want to install at least gometalinter on Travis CI. 276install_prerequisites: 277 uname -a 278 sudo apt-get update 279 sudo apt-get install -y -q libc6-dev-i386 linux-libc-dev \ 280 gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf gcc-powerpc64le-linux-gnu || true 281 sudo apt-get install -y -q g++-aarch64-linux-gnu || true 282 sudo apt-get install -y -q g++-powerpc64le-linux-gnu || true 283 sudo apt-get install -y -q g++-arm-linux-gnueabihf || true 284 go get -u gopkg.in/alecthomas/gometalinter.v2 285 gometalinter.v2 --install 286 287check_links: 288 python ./tools/check_links.py $$(pwd) $$(ls ./*.md; find ./docs/ -name '*.md') 289 290# Check that the diff is empty. This is meant to be executed after generating 291# and formatting the code to make sure that everything is committed. 292check_diff: 293 DIFF="$(shell git diff --name-only)"; test -z "$$DIFF" 294