blob: 7a3d68e7937c9534e66eb10140e2464356854fcb (
plain) (
blame)
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
|
validate_build_config_klee() {
return 0
}
setup_build_variables_klee() {
KLEE_SUFFIX="${LLVM_VERSION_SHORT}${SOLVER_SUFFIX}${SANITIZER_SUFFIX}"
KLEE_BUILD_DIR="${BASE}/klee_build${KLEE_SUFFIX}"
KLEE_SRC="$DIR/../../"
}
download_klee() {
return 0
}
build_klee() {
CMAKE_PREFIX_PATH=("")
local CMAKE_ARGUMENTS=(
"-DLLVM_CONFIG_BINARY=${LLVM_CONFIG}"
"-DLLVMCC=${BITCODE_CC}"
"-DLLVMCXX=${BITCODE_CXX}"
"-DGTEST_SRC_DIR=${GTEST_INSTALL_PATH}"
"-DENABLE_UNIT_TESTS=TRUE"
"-DENABLE_SYSTEM_TESTS=TRUE"
"-DENABLE_DOXYGEN=${ENABLE_DOXYGEN}"
"-DLIT_ARGS=-v"
)
###############################################################################
# klee-uclibc
###############################################################################
if [ "${UCLIBC_VERSION}" != "0" ]; then
CMAKE_ARGUMENTS+=(
"-DENABLE_KLEE_UCLIBC=TRUE"
"-DKLEE_UCLIBC_PATH=${BASE}/klee-uclibc-${LLVM_VERSION_SHORT}"
"-DENABLE_POSIX_RUNTIME=TRUE"
)
else
CMAKE_ARGUMENTS+=(
"-DENABLE_KLEE_UCLIBC=FALSE"
"-DENABLE_POSIX_RUNTIME=FALSE"
)
fi
###############################################################################
# libc++
###############################################################################
if [ "${USE_LIBCXX}" -eq 1 ]; then
CMAKE_ARGUMENTS+=(
"-DENABLE_KLEE_LIBCXX=TRUE"
"-DKLEE_LIBCXX_DIR=${LIBCXX_INSTALL}"
"-DKLEE_LIBCXX_INCLUDE_DIR=${LIBCXX_INSTALL}/include/c++/v1"
)
local LLVM_VERSION_MAJOR="${LLVM_VERSION/.*/}"
[[ "${LLVM_VERSION_MAJOR}" -ge 8 ]] && CMAKE_ARGUMENTS+=(
"-DENABLE_KLEE_EH_CXX=TRUE"
"-DKLEE_LIBCXXABI_SRC_DIR=${LIBCXX_SRC}/libcxxabi"
)
else
CMAKE_ARGUMENTS+=(
"-DENABLE_KLEE_LIBCXX=FALSE"
)
fi
###############################################################################
# Handle setting up solver configure flags for KLEE
###############################################################################
local KLEE_Z3_CONFIGURE_OPTION=("-DENABLE_SOLVER_Z3=OFF")
local KLEE_STP_CONFIGURE_OPTION=("-DENABLE_SOLVER_STP=OFF")
local KLEE_METASMT_CONFIGURE_OPTION=("-DENABLE_SOLVER_METASMT=OFF")
for solver in "${SELECTED_SOLVERS[@]}"; do
echo "Setting CMake configuration option for ${solver}"
case "${solver}" in
stp)
KLEE_STP_CONFIGURE_OPTION=(
"-DENABLE_SOLVER_STP=TRUE"
"-DSTP_DIR=${STP_INSTALL_PATH}/"
)
CMAKE_PREFIX_PATH+=("${STP_INSTALL_PATH}")
;;
z3)
echo "Z3"
KLEE_Z3_CONFIGURE_OPTION=(
"-DENABLE_SOLVER_Z3=TRUE"
"-DZ3_INCLUDE_DIRS=${Z3_INSTALL_PATH}/include"
"-DZ3_LIBRARIES=${Z3_INSTALL_PATH}/lib/libz3.so"
)
;;
metasmt)
echo "metaSMT"
if [ "X${METASMT_DEFAULT}" == "X" ]; then
METASMT_DEFAULT=STP
fi
KLEE_METASMT_CONFIGURE_OPTION=(
"-DENABLE_SOLVER_METASMT=TRUE"
"-DmetaSMT_DIR=${METASMT_BUILD_PATH}"
"-DMETASMT_DEFAULT_BACKEND=${METASMT_DEFAULT}"
)
;;
*)
echo "Unknown solver ${solver}"
exit 1
esac
done
CMAKE_ARGUMENTS+=(
"${KLEE_Z3_CONFIGURE_OPTION[@]}"
"${KLEE_STP_CONFIGURE_OPTION[@]}"
"${KLEE_METASMT_CONFIGURE_OPTION[@]}"
)
###############################################################################
# Handle additional configure flags
###############################################################################
if [[ $(to_bool "${USE_TCMALLOC}") -eq 1 ]] ; then
CMAKE_PREFIX_PATH+=("${TCMALLOC_INSTALL_PATH}")
CMAKE_ARGUMENTS+=("-DENABLE_TCMALLOC=TRUE")
else
CMAKE_ARGUMENTS+=("-DENABLE_TCMALLOC=FALSE")
fi
CMAKE_PREFIX_PATH+=("${SQLITE_INSTALL_PATH}")
###############################################################################
# KLEE
###############################################################################
if [ "X${DISABLE_ASSERTIONS}" == "X1" ]; then
CMAKE_ARGUMENTS+=("-DENABLE_KLEE_ASSERTS=FALSE")
else
CMAKE_ARGUMENTS+=("-DENABLE_KLEE_ASSERTS=TRUE")
fi
if [ "X${ENABLE_OPTIMIZED}" == "X1" ]; then
CMAKE_ARGUMENTS+=("-DCMAKE_BUILD_TYPE=RelWithDebInfo")
else
CMAKE_ARGUMENTS+=("-DCMAKE_BUILD_TYPE=Debug")
fi
CMAKE_ARGUMENTS+=("-DKLEE_RUNTIME_BUILD_TYPE=${KLEE_RUNTIME_BUILD}")
# TODO: We should support Ninja too
# Configure KLEE
local CXX_FLAGS=("")
local C_FLAGS=("")
local LD_FLAGS=("")
if [ "${COVERAGE}" -eq 1 ]; then
CXX_FLAGS+=("-fprofile-arcs" "-ftest-coverage")
C_FLAGS+=("-fprofile-arcs" "-ftest-coverage")
LD_FLAGS+=("-fprofile-arcs" "-ftest-coverage")
fi
if [[ -n "${SANITIZER_BUILD}" ]]; then
C_FLAGS+=("${SANITIZER_C_FLAGS[@]}")
CXX_FLAGS+=("${SANITIZER_CXX_FLAGS[@]}")
LD_FLAGS+=("${SANITIZER_LD_FLAGS[@]}")
CMAKE_ARGUMENTS+=(
"-DCMAKE_C_COMPILER=${SANITIZER_C_COMPILER}"
"-DCMAKE_CXX_COMPILER=${SANITIZER_CXX_COMPILER}"
)
fi
mkdir -p "${KLEE_BUILD_DIR}" || return 1
cd "${KLEE_BUILD_DIR}"
{
echo "CXXFLAGS=\"${CXX_FLAGS[*]}\" \\"
echo "CFLAGS=\"${C_FLAGS[*]}\" \\"
echo "LDFLAGS=\"${LD_FLAGS[*]}\" \\"
if [[ -n "${CMAKE_PREFIX_PATH[*]}" ]]; then
cmake_concatenated=$(IFS=: ; echo "${CMAKE_PREFIX_PATH[*]}")
echo "CMAKE_PREFIX_PATH=\"${cmake_concatenated}\" \\"
fi
echo "cmake ${CMAKE_ARGUMENTS[*]} \"${KLEE_SRC}\""
} > "${KLEE_BUILD_DIR}/.build_command"
source "${KLEE_BUILD_DIR}/.build_command"
make -j$(nproc) || make || return 1
touch "${KLEE_BUILD_DIR}/.is_installed"
}
install_klee() {
return 0
}
get_docker_config_id_klee() {
(
setup_build_variables_klee
echo "${KLEE_SUFFIX}"
)
}
get_docker_context_klee() {
# KLEE's source code is two levels above this script
echo "${DIR}/../../"
}
get_docker_container_context_klee() {
echo "${BASE}/klee_src/"
}
get_build_artifacts_klee() {
(
setup_build_variables_klee
echo "${KLEE_BUILD_DIR}"
)
}
# Check if the binary artifact is installed
is_installed_klee() {
(
setup_build_variables_klee
[[ -f "${KLEE_BUILD_DIR}"/.is_installed ]]
) || return 1
}
setup_artifact_variables_klee() {
setup_build_variables_klee
}
|