forked from S2E/s2e-old
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
401 lines (308 loc) · 14.4 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#Environment variables:
#
# BUILD_ARCH=corei7, etc...
# Overrides the default clang -march settings.
# Useful to build S2E in VirtualBox or in other VMs that do not support
# some advanced instruction sets.
# Used by STP only for now.
#
# EXTRA_QEMU_FLAGS=...
# Pass additional flags to QEMU's configure script.
#
# PARALLEL=no
# Turn off build parallelization.
#
# LLVMBUILD=...
# Contains llvm-native, llvm-debug, llvm-release, and llvm source folders
# Can be used to avoid rebuilding clang/llvm for every branch of S2E
#
S2ESRC := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
S2EBUILD:=$(CURDIR)
LLVMBUILD?=$(S2EBUILD)
OS := $(shell uname)
JOBS:=2
ifeq ($(PARALLEL),no)
JOBS := 1
else ifeq ($(OS),Darwin)
JOBS := $(patsubst hw.ncpu:%,%,$(shell sysctl hw.ncpu))
else ifeq ($(OS),Linux)
JOBS := $(shell grep -c ^processor /proc/cpuinfo)
endif
MAKE = make -j$(JOBS)
all: all-release guest-tools
guest-tools: stamps/guest-tools32-make stamps/guest-tools64-make
all-release all-asan-release: stamps/tools-release-make
all-release: stamps/afl-make stamps/qemu-release-make
all-asan-release: stamps/qemu-asan-release-make
all-debug all-asan-debug: stamps/tools-debug-make
all-debug: stamps/qemu-debug-make
all-asan-debug: stamps/qemu-asan-debug-make
ifeq ($(wildcard qemu/vl.c),qemu/vl.c)
$(error You should not run make in the S2E source directory!)
endif
LLVM_VERSION=3.2
LLVM_SRC=llvm-$(LLVM_VERSION).src.tar.gz
LLVM_SRC_DIR=llvm-$(LLVM_VERSION).src
LLVM_NATIVE_SRC_DIR=llvm-$(LLVM_VERSION).src.native
CLANG_SRC=clang-$(LLVM_VERSION).src.tar.gz
CLANG_SRC_DIR=clang-$(LLVM_VERSION).src
CLANG_DEST_DIR=$(LLVM_NATIVE_SRC_DIR)/tools/clang
COMPILER_RT_SRC=compiler-rt-$(LLVM_VERSION).src.tar.gz
COMPILER_RT_SRC_DIR=compiler-rt-$(LLVM_VERSION).src
COMPILER_RT_DEST_DIR=$(LLVM_NATIVE_SRC_DIR)/projects/compiler-rt
KLEE_QEMU_DIRS = $(foreach suffix,-debug -release,$(addsuffix $(suffix),klee klee-asan qemu qemu-asan))
ifeq ($(LLVMBUILD),$(S2EBUILD))
LLVM_DIRS = llvm-debug llvm-native llvm-release
endif
AFL_DIR:=$(S2EBUILD)/afl-1.96b
clean:
-rm -Rf $(KLEE_QEMU_DIRS)
-rm -Rf stamps
-rm -Rf $(AFL_DIR)
guestclean:
-rm -f stamps/guest-tools*
-rm -rf guest-tools*
distclean: clean guestclean
-rm -Rf guest-tools $(LLVM_DIRS) stp stp-asan tools-debug tools-release
-rm -Rf $(COMPILER_RT_SRC_DIR) $(LLVM_SRC_DIR) $(LLVM_NATIVE_SRC_DIR)
.PHONY: all all-debug all-release all-asan-debug all-asan-release
.PHONY: clean distclean guestclean
ALWAYS:
guest-tools32 guest-tools64 $(KLEE_QEMU_DIRS) $(LLVM_DIRS) stamps tools-debug tools-release:
mkdir -p $@
stamps/%-configure: | % stamps
cd $* && $(CONFIGURE_COMMAND)
touch $@
stamps/%-make:
$(MAKE) -C $* $(BUILD_OPTS)
touch $@
# On Ubuntu 14.04, c++config.h is located in a platform-specific path
ifeq (,$(wildcard /usr/include/x86_64-linux-gnu/c++/4.8/c++config.h))
export CPLUS_INCLUDE_PATH=/usr/include:/usr/include/x86_64-linux-gnu:/usr/include/x86_64-linux-gnu/c++/4.8
export C_INCLUDE_PATH=/usr/include:/usr/include/x86_64-linux-gnu
endif
#########################
# Download and make AFL #
#########################
AFL_URL = https://github.com/Epeius/afl/archive/master.zip
ARCHIVE = AFL-1.96b.zip
BITMAP = /tmp/aflbitmap
BUILDQEMUSH = build_qemu_support.sh
AFLQEMUARCHIVE = $(AFL_DIR)/qemu_mode/qemu-2.3.0.tar.bz2
QEMUBUILDFLAG = $(AFL_DIR)/qemu_mode/qemubuiltflag
stamps/afl-make:
ifneq ($(ARCHIVE), $(wildcard $(ARCHIVE)))
@echo "[*] Downloading afl from the web..."
rm -f $(ARCHIVE)
wget -O $(ARCHIVE) -- $(AFL_URL) || exit 1
endif
ifneq ($(AFL_DIR), $(wildcard $(AFL_DIR)))
@echo "[*] Uncompressing archive (this will take a while)..."
unzip $(ARCHIVE) || exit 1
mv "afl-master" "afl-1.96b"
endif
@echo "[*] Attempting to build afl (fingers crossed!)..."
cd $(AFL_DIR) && touch $(BITMAP) && make || exit 1
@echo "[+] Build process successful!"
ifneq ($(QEMUBUILDFLAG), $(wildcard $(QEMUBUILDFLAG)))
@echo "[*] Attempting to build AFL-QEMU (fingers crossed!)..."
cd $(AFL_DIR)/qemu_mode && sh $(BUILDQEMUSH) && touch $(QEMUBUILDFLAG) || exit 1
@echo "[+] Build process successful!"
else
@echo "[+] QEMU has been built, go ahead."
endif
#############
# Downloads #
#############
ifeq ($(LLVMBUILD),$(S2EBUILD))
LLVM_SRC_URL = http://llvm.org/releases/$(LLVM_VERSION)/
$(CLANG_SRC) $(COMPILER_RT_SRC) $(LLVM_SRC):
wget $(LLVM_SRC_URL)$@
.INTERMEDIATE: $(CLANG_SRC_DIR) $(COMPILER_RT_SRC_DIR)
$(CLANG_SRC_DIR): $(CLANG_SRC)
$(COMPILER_RT_SRC_DIR): $(COMPILER_RT_SRC)
$(LLVM_SRC_DIR): $(LLVM_SRC)
$(CLANG_SRC_DIR) $(COMPILER_RT_SRC_DIR) $(LLVM_SRC_DIR):
tar -xmzf $<
$(LLVM_NATIVE_SRC_DIR): $(LLVM_SRC_DIR)
$(LLVM_NATIVE_SRC_DIR):
cp -r $< $@
$(CLANG_DEST_DIR): $(CLANG_SRC_DIR) $(LLVM_NATIVE_SRC_DIR)
$(COMPILER_RT_DEST_DIR): $(COMPILER_RT_SRC_DIR) $(LLVM_NATIVE_SRC_DIR)
$(CLANG_DEST_DIR) $(COMPILER_RT_DEST_DIR):
mv $< $@
endif
stp stp-asan: $(S2ESRC)/stp
stp stp-asan:
cp -r $< $@
########
# LLVM #
########
CLANG_CC=$(LLVMBUILD)/llvm-native/Release/bin/clang
CLANG_CXX=$(LLVMBUILD)/llvm-native/Release/bin/clang++
ifeq ($(LLVMBUILD),$(S2EBUILD))
LLVM_CONFIGURE_FLAGS = --prefix=$(S2EBUILD)/opt \
--enable-jit --enable-optimized \
#First build it with the system's compiler
stamps/llvm-native-configure: $(CLANG_DEST_DIR) $(COMPILER_RT_DEST_DIR)
stamps/llvm-native-configure: CONFIGURE_COMMAND = $(S2EBUILD)/$(LLVM_NATIVE_SRC_DIR)/configure \
$(LLVM_CONFIGURE_FLAGS) \
--disable-assertions #compiler-rt won't build if we specify explicit targets...
stamps/llvm-native-make: stamps/llvm-native-configure
stamps/llvm-native-make: BUILD_OPTS = ENABLE_OPTIMIZED=1
#Then, build LLVM with the clang compiler.
#Note that we build LLVM without clang and compiler-rt, because S2E does not need them.
stamps/llvm-debug-configure: stamps/llvm-native-make
stamps/llvm-release-configure: stamps/llvm-native-make
stamps/llvm-%-configure: CONFIGURE_COMMAND = $(S2EBUILD)/$(LLVM_SRC_DIR)/configure \
$(LLVM_CONFIGURE_FLAGS) \
--target=x86_64 --enable-targets=x86 \
CC=$(CLANG_CC) \
CXX=$(CLANG_CXX)
stamps/llvm-debug-make: stamps/llvm-debug-configure
stamps/llvm-debug-make: BUILD_OPTS = ENABLE_OPTIMIZED=0 REQUIRES_RTTI=1
stamps/llvm-release-make: stamps/llvm-release-configure
stamps/llvm-release-make: BUILD_OPTS = ENABLE_OPTIMIZED=1 REQUIRES_RTTI=1
else
stamps/llvm-release-make stamps/llvm-debug-make stamps/llvm-native-make:
@echo "Won't build $@, using $(LLVMBUILD) folder"
endif
#######
# STP #
#######
stamps/stp-make stamps/stp-asan-make: ALWAYS
STP_CONFIGURE_FLAGS = --with-prefix=$(S2EBUILD)/stp --with-fpic \
--with-g++=$(CLANG_CXX) --with-gcc=$(CLANG_CC)
stamps/stp-configure: stamps/llvm-native-make
stamps/stp-configure: CONFIGURE_COMMAND = scripts/configure $(STP_CONFIGURE_FLAGS)
#STP: concurrent build is not reliable
stamps/stp-make: stamps/stp-configure
cd stp && make
mkdir -p stamps && touch $@
#ASAN-enabled STP
#XXX: need to fix the STP build to actually use ASAN...
stamps/stp-asan-configure: stamps/llvm-native-make
stamps/stp-asan-configure: CONFIGURE_COMMAND = scripts/configure $(STP_CONFIGURE_FLAGS) --with-address-sanitizer
stamps/stp-asan-make: stamps/stp-asan-configure
cd stp-asan && make
mkdir -p stamps && touch $@
########
# KLEE #
########
stamps/klee-debug-make stamps/klee-asan-debug-make stamps/klee-release-make stamps/klee-asan-release-make: ALWAYS
KLEE_CONFIGURE_COMMON = $(S2ESRC)/klee/configure \
--prefix=$(S2EBUILD)/opt \
--with-llvmsrc=$(LLVMBUILD)/$(LLVM_SRC_DIR) \
--target=x86_64 --enable-exceptions \
CC=$(CLANG_CC) CXX=$(CLANG_CXX)
KLEE_CONFIGURE_COMMAND = $(KLEE_CONFIGURE_COMMON) --with-stp=$(S2EBUILD)/stp
stamps/klee-debug-configure: stamps/stp-make stamps/llvm-debug-make
stamps/klee-debug-configure: CONFIGURE_COMMAND = $(KLEE_CONFIGURE_COMMAND) \
--with-llvmobj=$(LLVMBUILD)/llvm-debug \
CXXFLAGS="-g -O0" LDFLAGS="-g"
stamps/klee-release-configure: stamps/stp-make stamps/llvm-release-make
stamps/klee-release-configure: CONFIGURE_COMMAND = $(KLEE_CONFIGURE_COMMAND) \
--with-llvmobj=$(LLVMBUILD)/llvm-release
stamps/klee-debug-make: stamps/klee-debug-configure
stamps/klee-debug-make: BUILD_OPTS = ENABLE_OPTIMIZED=0
stamps/klee-release-make: stamps/klee-release-configure
stamps/klee-release-make: BUILD_OPTS = ENABLE_OPTIMIZED=1
#ASAN-enabled KLEE
KLEE_ASAN_CONFIGURE_COMMAND = $(KLEE_CONFIGURE_COMMON) --with-stp=$(S2EBUILD)/stp-asan
stamps/klee-asan-debug-configure: stamps/stp-asan-make stamps/llvm-debug-make
stamps/klee-asan-debug-configure: CONFIGURE_COMMAND = $(KLEE_ASAN_CONFIGURE_COMMAND) \
--with-llvmobj=$(LLVMBUILD)/llvm-debug \
CXXFLAGS="-g -O0 -fsanitize=address" \
LDFLAGS="-g -fsanitize=address"
stamps/klee-asan-release-configure: stamps/stp-asan-make stamps/llvm-release-make
stamps/klee-asan-release-configure: CONFIGURE_COMMAND = $(KLEE_ASAN_CONFIGURE_COMMAND) \
--with-llvmobj=$(LLVMBUILD)/llvm-release \
CXXFLAGS="-fsanitize=address" \
LDFLAGS="-fsanitize=address"
stamps/klee-asan-debug-make: stamps/klee-asan-debug-configure
stamps/klee-asan-debug-make: BUILD_OPTS = ENABLE_OPTIMIZED=0
stamps/klee-asan-release-make: stamps/klee-asan-release-configure
stamps/klee-asan-release-make: BUILD_OPTS = ENABLE_OPTIMIZED=1
########
# QEMU #
########
#HACK: LLVM does not recognize which processor features are supported, and uses SSE4 when it's not supported, so disable this
EXTRA_QEMU_FLAGS += --extra-cflags=-mno-sse3 --extra-cxxflags=-mno-sse3
QEMU_S2E_ARCH =
QEMU_S2E_ARCH += i386-s2e-softmmu i386-softmmu
#QEMU_S2E_ARCH += x86_64-s2e-softmmu x86_64-softmmu
#QEMU_S2E_ARCH += arm-s2e-softmmu arm-softmmu
empty :=
comma := ,
space := $(empty) $(empty)
QEMU_S2E_ARCH := $(subst $(space),$(comma),$(strip $(QEMU_S2E_ARCH)))
QEMU_COMMON_FLAGS = --prefix=$(S2EBUILD)/opt\
--cc=$(CLANG_CC) \
--cxx=$(CLANG_CXX) \
--target-list=$(QEMU_S2E_ARCH)\
--enable-llvm \
--enable-s2e \
--with-pkgversion=S2E \
--disable-virtfs \
--disable-fdt \
$(EXTRA_QEMU_FLAGS)
QEMU_CONFIGURE_FLAGS = --with-stp=$(S2EBUILD)/stp \
$(QEMU_COMMON_FLAGS)
QEMU_DEBUG_FLAGS = --with-llvm=$(LLVMBUILD)/llvm-debug/Debug+Asserts \
--enable-debug
QEMU_RELEASE_FLAGS = --with-llvm=$(LLVMBUILD)/llvm-release/Release+Asserts
stamps/qemu-debug-configure: stamps/klee-debug-make
stamps/qemu-debug-configure: CONFIGURE_COMMAND = $(S2ESRC)/qemu/configure \
--with-klee=$(S2EBUILD)/klee-debug/Debug+Asserts \
$(QEMU_DEBUG_FLAGS) \
$(QEMU_CONFIGURE_FLAGS)
stamps/qemu-release-configure: stamps/klee-release-make
stamps/qemu-release-configure: CONFIGURE_COMMAND = $(S2ESRC)/qemu/configure \
--with-klee=$(S2EBUILD)/klee-release/Release+Asserts \
$(QEMU_RELEASE_FLAGS) \
$(QEMU_CONFIGURE_FLAGS)
stamps/qemu-debug-make: stamps/qemu-debug-configure
stamps/qemu-release-make: stamps/qemu-release-configure
#ASAN-enabled QEMU
QEMU_ASAN_FLAGS = --enable-address-sanitizer \
--with-stp=$(S2EBUILD)/stp-asan \
$(QEMU_COMMON_FLAGS)
stamps/qemu-asan-debug-configure: stamps/klee-asan-debug-make
stamps/qemu-asan-debug-configure: CONFIGURE_COMMAND = $(S2ESRC)/qemu/configure \
--with-klee=$(S2EBUILD)/klee-asan-debug/Debug+Asserts \
$(QEMU_DEBUG_FLAGS) \
$(QEMU_ASAN_FLAGS)
stamps/qemu-asan-release-configure: stamps/klee-asan-release-make
stamps/qemu-asan-release-configure: CONFIGURE_COMMAND = $(S2ESRC)/qemu/configure \
--with-klee=$(S2EBUILD)/klee-asan-release/Release+Asserts \
$(QEMU_RELEASE_FLAGS) \
$(QEMU_ASAN_FLAGS)
stamps/qemu-asan-debug-make: stamps/qemu-asan-debug-configure
stamps/qemu-asan-release-make: stamps/qemu-asan-release-configure
#########
# Tools #
#########
TOOLS_CONFIGURE_COMMAND = $(S2ESRC)/tools/configure \
--with-llvmsrc=$(LLVMBUILD)/$(LLVM_SRC_DIR) \
--with-s2esrc=$(S2ESRC)/qemu \
--target=x86_64 CC=$(CLANG_CC) CXX=$(CLANG_CXX)
stamps/tools-debug-configure: stamps/llvm-debug-make
stamps/tools-debug-configure: CONFIGURE_COMMAND = $(TOOLS_CONFIGURE_COMMAND) \
--with-llvmobj=$(LLVMBUILD)/llvm-debug
stamps/tools-release-configure: stamps/llvm-release-make
stamps/tools-release-configure: CONFIGURE_COMMAND = $(TOOLS_CONFIGURE_COMMAND) \
--with-llvmobj=$(LLVMBUILD)/llvm-release
stamps/tools-debug-make stamps/tools-release-make: ALWAYS
stamps/tools-debug-make: stamps/tools-debug-configure
stamps/tools-debug-make: BUILD_OPTS = ENABLE_OPTIMIZED=0 REQUIRES_RTTI=1
stamps/tools-release-make: stamps/tools-release-configure
stamps/tools-release-make: BUILD_OPTS = ENABLE_OPTIMIZED=1 REQUIRES_RTTI=1
############
#Guest tools
############
GUEST_CONFIGURE_COMMAND = $(S2ESRC)/guest/configure
stamps/guest-tools%-configure: CONFIGURE_COMMAND = $(GUEST_CONFIGURE_COMMAND)
stamps/guest-tools32-make: stamps/guest-tools32-configure
stamps/guest-tools32-make: BUILD_OPTS = CFLAGS="-m32"
stamps/guest-tools64-make: stamps/guest-tools64-configure
stamps/guest-tools64-make: BUILD_OPTS = CFLAGS="-m64"