Skip to content

Commit

Permalink
Implement a CMake based build system for KLEE.
Browse files Browse the repository at this point in the history
This is based off intial work by @jirislaby in klee#481. However it
has been substantially modified.

Notably it includes a separate build sytem to build the runtimes which
is inspired by the old build system. The reason for doing this is
because CMake is not well suited for building the runtime:

* CMake is configured to use the host compiler, not the bitcode
  compiler. These are not the same thing.

* Building the runtime using `add_custom_command()` is flawed
  because we can't automatically get transitive depencies (i.e.
  header file dependencies) unless the CMake generator is makefiles.
  (See `IMPLICIT_DEPENDS` of `add_custom_command()` in CMake).

So for now we have a very simple build system for building the runtimes.
In the future we can replace this with something more sophisticated if
we need it.

Support for all features of the old build system are implemented apart
from recording the git revision and showing it in the output of
`klee --help`.

Another notable change is the CMake build system works much better with
LLVM installs which don't ship with testing tools. The build system
will download the sources for `FileCheck` and `not` tools if the
corresponding binaries aren't available and will build them. However
`lit` (availabe via `pip install lit`) and GTest must already be
installed.

Apart from better support for testing a significant advantage of the
new CMake build system compared to the existing "Autoconf/Makefile"
build system is that it is **not** coupled to LLVM's build system
(unlike the existing build system). This means that LLVM's
autoconf/Makefiles don't need to be installed somewhere on the system.

Currently all tests pass.

Support has been implemented in TravisCI and the Dockerfile for
building with CMake.

The existing "Autoconf/Makefile" build system has been left intact
and so both build systems can coexist for a short while. We should
remove the old build system as soon as possible though because it
creates an unnecessary maintance burden.
  • Loading branch information
Dan Liew authored and delcypher committed Nov 7, 2016
1 parent 48abc42 commit 7e75b49
Show file tree
Hide file tree
Showing 53 changed files with 2,835 additions and 91 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ env:
# COVERAGE set indicated that coverage data should be uplaoded to the server, only ONE job should have COVERAGE set

matrix:
# Check KLEE CMake build
- LLVM_VERSION=3.4 SOLVERS=STP:Z3 STP_VERSION=2.1.0 KLEE_UCLIBC=klee_uclibc_v1.0.0 DISABLE_ASSERTIONS=0 ENABLE_OPTIMIZED=1 COVERAGE=0 USE_TCMALLOC=1 USE_CMAKE=1
- LLVM_VERSION=3.4 SOLVERS=metaSMT METASMT_DEFAULT=STP KLEE_UCLIBC=klee_uclibc_v1.0.0 DISABLE_ASSERTIONS=0 ENABLE_OPTIMIZED=1 COVERAGE=0 USE_TCMALLOC=1 USE_CMAKE=1
- LLVM_VERSION=2.9 SOLVERS=STP:Z3 STP_VERSION=2.1.0 KLEE_UCLIBC=klee_uclibc_v1.0.0 DISABLE_ASSERTIONS=0 ENABLE_OPTIMIZED=1 COVERAGE=0 USE_TCMALLOC=1 USE_CMAKE=1

# Test experimental metaSMT support
- LLVM_VERSION=3.4 SOLVERS=metaSMT METASMT_DEFAULT=btor KLEE_UCLIBC=klee_uclibc_v1.0.0 DISABLE_ASSERTIONS=0 ENABLE_OPTIMIZED=1 COVERAGE=0
- LLVM_VERSION=2.9 SOLVERS=metaSMT METASMT_DEFAULT=btor KLEE_UCLIBC=klee_uclibc_v1.0.0 DISABLE_ASSERTIONS=0 ENABLE_OPTIMIZED=1 COVERAGE=0
Expand Down Expand Up @@ -63,7 +68,6 @@ env:
# Check with TCMALLOC
- LLVM_VERSION=3.4 SOLVERS=STP STP_VERSION=2.1.0 KLEE_UCLIBC=klee_uclibc_v1.0.0 DISABLE_ASSERTIONS=0 ENABLE_OPTIMIZED=1 COVERAGE=0 USE_TCMALLOC=1
- LLVM_VERSION=2.9 SOLVERS=STP STP_VERSION=2.1.0 KLEE_UCLIBC=klee_uclibc_v1.0.0 DISABLE_ASSERTIONS=0 ENABLE_OPTIMIZED=1 COVERAGE=0 USE_TCMALLOC=1

global:
- secure: EF/WAc4BdIRUchF3mjATN3/UwtGWtGaRgb5oIIJHjKhgZFdPsgWsXFgaOB0jaK2hfO/svj/LvlasuRIGxeePVjeaiX8ZlVpuHiX67vdYLY+0kCDRwkusRjm60/GbPU9O/Xjgb/d4aWAEkoq5OnsprVTEvU8iY2JHtAqgwR+wW9I=
- secure: Hrp1MRSxDUH2GTQg3QR/yUttY/3KmgbFb5e+zyy551dKpHjxJdsNe8bquY9oFoT7KmPQYl0HNNjEv4qWW8RK+HWHOCB55nL1KlGpOG7vAJcUEZg7ScbliGgiovMB6jIQVfeP9FhYngfc13vNZQ5PGlqzfSsHSAbvkwEogBToHVw=
Expand Down
202 changes: 139 additions & 63 deletions .travis/klee.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ if [ "${KLEE_UCLIBC}" != "0" ]; then
cd klee-uclibc
./configure --make-llvm-lib --with-cc "${KLEE_CC}" --with-llvm-config /usr/bin/llvm-config-${LLVM_VERSION}
make
KLEE_UCLIBC_CONFIGURE_OPTION="--with-uclibc=$(pwd) --enable-posix-runtime"
if [ "X${USE_CMAKE}" == "X1" ]; then
KLEE_UCLIBC_CONFIGURE_OPTION="-DENABLE_KLEE_UCLIBC=TRUE -DKLEE_UCLIBC_PATH=$(pwd) -DENABLE_POSIX_RUNTIME=TRUE"
else
KLEE_UCLIBC_CONFIGURE_OPTION="--with-uclibc=$(pwd) --enable-posix-runtime"
fi
cd ../
else
KLEE_UCLIBC_CONFIGURE_OPTION=""
if [ "X${USE_CMAKE}" == "X1" ]; then
KLEE_UCLIBC_CONFIGURE_OPTION="-DENABLE_KLEE_UCLIBC=FALSE -DENABLE_POSIX_RUNTIME=FALSE"
else
KLEE_UCLIBC_CONFIGURE_OPTION=""
fi
fi

COVERAGE_FLAGS=""
Expand All @@ -54,52 +62,110 @@ KLEE_STP_CONFIGURE_OPTION=""
KLEE_METASMT_CONFIGURE_OPTION=""
SOLVER_LIST=$(echo "${SOLVERS}" | sed 's/:/ /')

for solver in ${SOLVER_LIST}; do
echo "Setting configuration option for ${solver}"
case ${solver} in
STP)
KLEE_STP_CONFIGURE_OPTION="--with-stp=${BUILD_DIR}/stp/build"
;;
Z3)
echo "Z3"
KLEE_Z3_CONFIGURE_OPTION="--with-z3=/usr"
;;
metaSMT)
echo "metaSMT"
KLEE_METASMT_CONFIGURE_OPTION="--with-metasmt=${BUILD_DIR}/metaSMT/build/root --with-metasmt-default-backend=${METASMT_DEFAULT}"
;;
*)
echo "Unknown solver ${solver}"
exit 1
esac
done

if [ "X${USE_CMAKE}" == "X1" ]; then
# Set CMake configure options
for solver in ${SOLVER_LIST}; do
echo "Setting CMake configuration option for ${solver}"
case ${solver} in
STP)
KLEE_STP_CONFIGURE_OPTION="-DENABLE_SOLVER_STP=TRUE -DSTP_DIR=${BUILD_DIR}/stp/build"
;;
Z3)
echo "Z3"
KLEE_Z3_CONFIGURE_OPTION="-DENABLE_SOLVER_Z3=TRUE"
;;
metaSMT)
echo "metaSMT"
if [ "X${METASMT_DEFAULT}" == "X" ]; then
METASMT_DEFAULT=STP
fi
KLEE_METASMT_CONFIGURE_OPTION="-DENABLE_SOLVER_METASMT=TRUE -DmetaSMT_DIR=${BUILD_DIR}/metaSMT/build -DMETASMT_DEFAULT_BACKEND=${METASMT_DEFAULT}"
;;
*)
echo "Unknown solver ${solver}"
exit 1
esac
done
TCMALLOC_OPTION=$([ "${USE_TCMALLOC:-0}" == 1 ] && echo "-DENABLE_TCMALLOC=TRUE" || echo "-DENABLE_TCMALLOC=FALSE")
else
for solver in ${SOLVER_LIST}; do
echo "Setting configuration option for ${solver}"
case ${solver} in
STP)
KLEE_STP_CONFIGURE_OPTION="--with-stp=${BUILD_DIR}/stp/build"
;;
Z3)
echo "Z3"
KLEE_Z3_CONFIGURE_OPTION="--with-z3=/usr"
;;
metaSMT)
echo "metaSMT"
KLEE_METASMT_CONFIGURE_OPTION="--with-metasmt=${BUILD_DIR}/metaSMT/build/root --with-metasmt-default-backend=${METASMT_DEFAULT}"
;;
*)
echo "Unknown solver ${solver}"
exit 1
esac
done

TCMALLOC_OPTION=$([ "${USE_TCMALLOC:-0}" == 1 ] && echo "--with-tcmalloc" || echo "--without-tcmalloc")
fi

TCMALLOC_OPTION=$([ "${USE_TCMALLOC:-0}" == 1 ] && echo "--with-tcmalloc" || echo "--without-tcmalloc")
###############################################################################
# KLEE
###############################################################################
mkdir klee
cd klee

# Build KLEE
# Note: ENABLE_SHARED=0 is required because llvm-2.9 is incorectly packaged
# and is missing the shared library that was supposed to be built that the build
# system will try to use by default.
${KLEE_SRC}/configure --with-llvmsrc=/usr/lib/llvm-${LLVM_VERSION}/build \
--with-llvmobj=/usr/lib/llvm-${LLVM_VERSION}/build \
--with-llvmcc=${KLEE_CC} \
--with-llvmcxx=${KLEE_CXX} \
${KLEE_STP_CONFIGURE_OPTION} \
${KLEE_Z3_CONFIGURE_OPTION} \
${KLEE_METASMT_CONFIGURE_OPTION} \
${KLEE_UCLIBC_CONFIGURE_OPTION} \
${TCMALLOC_OPTION} \
CXXFLAGS="${COVERAGE_FLAGS}" \
&& make DISABLE_ASSERTIONS=${DISABLE_ASSERTIONS} \
ENABLE_OPTIMIZED=${ENABLE_OPTIMIZED} \
ENABLE_SHARED=0

if [ "X${USE_CMAKE}" == "X1" ]; then
GTEST_SRC_DIR="${BUILD_DIR}/test-utils/googletest-release-1.7.0/"
if [ "X${DISABLE_ASSERTIONS}" == "X1" ]; then
KLEE_ASSERTS_OPTION="-DENABLE_KLEE_ASSERTS=FALSE"
else
KLEE_ASSERTS_OPTION="-DENABLE_KLEE_ASSERTS=TRUE"
fi

if [ "X${ENABLE_OPTIMIZED}" == "X1" ]; then
CMAKE_BUILD_TYPE="RelWithDebInfo"
else
CMAKE_BUILD_TYPE="Debug"
fi
# Compute CMake build type
CXXFLAGS="${COVERAGE_FLAGS}" \
cmake \
-DLLVM_CONFIG_BINARY="/usr/lib/llvm-${LLVM_VERSION}/bin/llvm-config" \
-DLLVMCC="${KLEE_CC}" \
-DLLVMCXX="${KLEE_CXX}" \
${KLEE_STP_CONFIGURE_OPTION} \
${KLEE_Z3_CONFIGURE_OPTION} \
${KLEE_METASMT_CONFIGURE_OPTION} \
${KLEE_UCLIBC_CONFIGURE_OPTION} \
${TCMALLOC_OPTION} \
-DGTEST_SRC_DIR=${GTEST_SRC_DIR} \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
${KLEE_ASSERTS_OPTION} \
-DENABLE_TESTS=TRUE \
-DLIT_ARGS="-v" \
${KLEE_SRC} && make
else
# Build KLEE
# Note: ENABLE_SHARED=0 is required because llvm-2.9 is incorectly packaged
# and is missing the shared library that was supposed to be built that the build
# system will try to use by default.
${KLEE_SRC}/configure --with-llvmsrc=/usr/lib/llvm-${LLVM_VERSION}/build \
--with-llvmobj=/usr/lib/llvm-${LLVM_VERSION}/build \
--with-llvmcc=${KLEE_CC} \
--with-llvmcxx=${KLEE_CXX} \
${KLEE_STP_CONFIGURE_OPTION} \
${KLEE_Z3_CONFIGURE_OPTION} \
${KLEE_METASMT_CONFIGURE_OPTION} \
${KLEE_UCLIBC_CONFIGURE_OPTION} \
${TCMALLOC_OPTION} \
CXXFLAGS="${COVERAGE_FLAGS}" \
&& make DISABLE_ASSERTIONS=${DISABLE_ASSERTIONS} \
ENABLE_OPTIMIZED=${ENABLE_OPTIMIZED} \
ENABLE_SHARED=0
fi
###############################################################################
# Testing
###############################################################################
Expand All @@ -108,32 +174,42 @@ set +e # We want to let all the tests run before we exit
###############################################################################
# Unit tests
###############################################################################
# The unittests makefile doesn't seem to have been packaged so get it from SVN
sudo mkdir -p /usr/lib/llvm-${LLVM_VERSION}/build/unittests/
svn export http://llvm.org/svn/llvm-project/llvm/branches/${SVN_BRANCH}/unittests/Makefile.unittest \
../Makefile.unittest
sudo mv ../Makefile.unittest /usr/lib/llvm-${LLVM_VERSION}/build/unittests/

make unittests \
DISABLE_ASSERTIONS=${DISABLE_ASSERTIONS} \
ENABLE_OPTIMIZED=${ENABLE_OPTIMIZED} \
ENABLE_SHARED=0
RETURN="$?"
if [ "X${USE_CMAKE}" == "X1" ]; then
make unittests
RETURN="$?"
else
# The unittests makefile doesn't seem to have been packaged so get it from SVN
sudo mkdir -p /usr/lib/llvm-${LLVM_VERSION}/build/unittests/
svn export http://llvm.org/svn/llvm-project/llvm/branches/${SVN_BRANCH}/unittests/Makefile.unittest \
../Makefile.unittest
sudo mv ../Makefile.unittest /usr/lib/llvm-${LLVM_VERSION}/build/unittests/

make unittests \
DISABLE_ASSERTIONS=${DISABLE_ASSERTIONS} \
ENABLE_OPTIMIZED=${ENABLE_OPTIMIZED} \
ENABLE_SHARED=0
RETURN="$?"
fi

###############################################################################
# lit tests
###############################################################################
# Note can't use ``make check`` because llvm-lit is not available
cd test
# The build system needs to generate this file before we can run lit
make lit.site.cfg \
DISABLE_ASSERTIONS=${DISABLE_ASSERTIONS} \
ENABLE_OPTIMIZED=${ENABLE_OPTIMIZED} \
ENABLE_SHARED=0

set +e # We want to let all the tests run before we exit
lit -v .
RETURN="${RETURN}$?"
if [ "X${USE_CMAKE}" == "X1" ]; then
make integrationtests
RETURN="${RETURN}$?"
else
# Note can't use ``make check`` because llvm-lit is not available
cd test
# The build system needs to generate this file before we can run lit
make lit.site.cfg \
DISABLE_ASSERTIONS=${DISABLE_ASSERTIONS} \
ENABLE_OPTIMIZED=${ENABLE_OPTIMIZED} \
ENABLE_SHARED=0

set +e # We want to let all the tests run before we exit
lit -v .
RETURN="${RETURN}$?"
fi

#generate and upload coverage if COVERAGE is set
if [ ${COVERAGE} -eq 1 ]; then
Expand Down
8 changes: 8 additions & 0 deletions .travis/testing-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
# Make sure we exit if there is a failure
set -e

if [ "X${USE_CMAKE}" == "X1" ]; then
# The New CMake build system just needs the GTest sources regardless
# of LLVM version.
wget https://github.com/google/googletest/archive/release-1.7.0.zip
unzip release-1.7.0.zip
exit 0
fi

if [ "${LLVM_VERSION}" != "2.9" ]; then
# Using LLVM3.4 all we need is vanilla GoogleTest :)
wget https://github.com/google/googletest/archive/release-1.7.0.zip
Expand Down
Loading

0 comments on commit 7e75b49

Please sign in to comment.