forked from S2E/s2e-old
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
309 lines (225 loc) · 11.3 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
#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.
S2ESRC := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
S2EBUILD:=$(CURDIR)
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
all-release all-asan-release: stamps/tools-release-make
all-release: 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_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))
LLVM_DIRS = llvm-debug llvm-native llvm-release
clean:
-rm -Rf $(KLEE_QEMU_DIRS)
-rm -Rf stamps
guestclean:
-$(MAKE) -C $(S2ESRC)/guest clean
-rm -f stamps/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-tools $(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 $@
#############
# Downloads #
#############
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 $<
stp stp-asan: $(S2ESRC)/stp
$(LLVM_NATIVE_SRC_DIR): $(LLVM_SRC_DIR)
$(LLVM_NATIVE_SRC_DIR) stp stp-asan:
cp -r $< $@
$(CLANG_DEST_DIR): $(CLANG_SRC_DIR) $(LLVM_SRC_DIR)
$(COMPILER_RT_DEST_DIR): $(COMPILER_RT_SRC_DIR) $(LLVM_NATIVE_SRC_DIR)
$(CLANG_DEST_DIR) $(COMPILER_RT_DEST_DIR):
mv $< $@
########
# LLVM #
########
CLANG_CC=$(S2EBUILD)/llvm-native/Release/bin/clang
CLANG_CXX=$(S2EBUILD)/llvm-native/Release/bin/clang++
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-%-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-release-make: stamps/llvm-native-make
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
#######
# STP #
#######
stamps/stp-make stamps/stp-asan-make: stamps/llvm-native-make ALWAYS
STP_CONFIGURE_FLAGS = --with-prefix=$(S2EBUILD)/stp --with-fpic \
--with-g++=$(CLANG_CXX) --with-gcc=$(CLANG_CC) \
--with-cryptominisat2
stamps/stp-configure: CONFIGURE_COMMAND = scripts/configure $(STP_CONFIGURE_FLAGS)
stamps/stp-make: stamps/stp-configure
#ASAN-enabled STP
#XXX: need to fix the STP build to actually use ASAN...
stamps/stp-asan-configure: CONFIGURE_COMMAND = scripts/configure $(STP_CONFIGURE_FLAGS) --with-address-sanitizer
stamps/stp-asan-make: stamps/stp-asan-configure
########
# KLEE #
########
stamps/klee-debug-make stamps/klee-asan-debug-make: stamps/llvm-debug-make
stamps/klee-release-make stamps/klee-asan-release-make: stamps/llvm-release-make
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=$(S2EBUILD)/$(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: CONFIGURE_COMMAND = $(KLEE_CONFIGURE_COMMAND) \
--with-llvmobj=$(S2EBUILD)/llvm-debug \
CXXFLAGS="-g -O0" LDFLAGS="-g"
stamps/klee-release-configure: CONFIGURE_COMMAND = $(KLEE_CONFIGURE_COMMAND) \
--with-llvmobj=$(S2EBUILD)/llvm-release
stamps/klee-debug-make stamps/klee-release-make: stamps/stp-make
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: CONFIGURE_COMMAND = $(KLEE_ASAN_CONFIGURE_COMMAND) \
--with-llvmobj=$(S2EBUILD)/llvm-debug \
CXXFLAGS="-g -O0 -fsanitize=address" \
LDFLAGS="-g -fsanitize=address"
stamps/klee-asan-release-configure: CONFIGURE_COMMAND = $(KLEE_ASAN_CONFIGURE_COMMAND) \
--with-llvmobj=$(S2EBUILD)/llvm-release \
CXXFLAGS="-fsanitize=address" \
LDFLAGS="-fsanitize=address"
stamps/klee-asan-debug-make stamps/klee-asan-release-make: stamps/stp-asan-make
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 #
########
QEMU_COMMON_FLAGS = --prefix=$(S2EBUILD)/opt\
--cc=$(CLANG_CC) \
--cxx=$(CLANG_CXX) \
--target-list=x86_64-s2e-softmmu,x86_64-softmmu,i386-s2e-softmmu,i386-softmmu \
--enable-llvm \
--enable-s2e \
--with-pkgversion=S2E \
$(EXTRA_QEMU_FLAGS)
QEMU_CONFIGURE_FLAGS = --with-stp=$(S2EBUILD)/stp \
$(QEMU_COMMON_FLAGS)
QEMU_DEBUG_FLAGS = --with-llvm=$(S2EBUILD)/llvm-debug/Debug+Asserts \
--enable-debug
QEMU_RELEASE_FLAGS = --with-llvm=$(S2EBUILD)/llvm-release/Release+Asserts
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: CONFIGURE_COMMAND = $(S2ESRC)/qemu/configure \
--with-klee=$(S2EBUILD)/klee-release/Release+Asserts \
$(QEMU_RELEASE_FLAGS) \
$(QEMU_CONFIGURE_FLAGS)
stamps/qemu-debug-make: stamps/klee-debug-make stamps/qemu-debug-configure
stamps/qemu-release-make: stamps/klee-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: CONFIGURE_COMMAND = $(S2ESRC)/qemu/configure \
--with-klee=$(S2EBUILD)/klee-asan-debug/Debug+Asserts \
$(QEMU_DEBUG_FLAGS) \
$(QEMU_ASAN_FLAGS)
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/klee-asan-debug-make stamps/qemu-asan-debug-configure
stamps/qemu-asan-release-make: stamps/klee-asan-release-make stamps/qemu-asan-release-configure
#########
# Tools #
#########
TOOLS_CONFIGURE_COMMAND = $(S2ESRC)/tools/configure \
--with-llvmsrc=$(S2EBUILD)/$(LLVM_SRC_DIR) \
--with-s2esrc=$(S2ESRC)/qemu \
--target=x86_64 CC=$(CLANG_CC) CXX=$(CLANG_CXX)
stamps/tools-debug-configure: CONFIGURE_COMMAND = $(TOOLS_CONFIGURE_COMMAND) \
--with-llvmobj=$(S2EBUILD)/llvm-debug
stamps/tools-release-configure: CONFIGURE_COMMAND = $(TOOLS_CONFIGURE_COMMAND) \
--with-llvmobj=$(S2EBUILD)/llvm-release
stamps/tools-debug-make stamps/tools-release-make: ALWAYS
stamps/tools-debug-make: stamps/llvm-debug-make stamps/tools-debug-configure
stamps/tools-debug-make: BUILD_OPTS = ENABLE_OPTIMIZED=0 REQUIRES_RTTI=1
stamps/tools-release-make: stamps/llvm-release-make stamps/tools-release-configure
stamps/tools-release-make: BUILD_OPTS = ENABLE_OPTIMIZED=1 REQUIRES_RTTI=1
############
#Guest tools
############
stamps/guest-tools: ALWAYS | guest-tools stamps
$(MAKE) -C $(S2ESRC)/guest install BUILD_DIR=$(S2EBUILD)/guest-tools
touch $@