ubuntu安装符号执行引擎KLEE

背景:ubuntu20.04上安装klee2.2

官网安装教程:KLEE2-2安装教程(不是很详细,仅参考)

本文的安装环境全部放在/opt/klee_env下,root用户下执行命令

1.安装必备工具和依赖

sudo apt-get install build-essential curl libcap-dev git cmake libncurses5-dev python-minimal python-pip unzip libtcmalloc-minimal4 libgoogle-perftools-dev libsqlite3-dev doxygen
sudo apt-get install python3 python3-pip gcc-multilib g++-multilib
sudo pip3 install lit tabulate wllvm
sudo apt-get install zlib1g-dev

2.安装LLVM9

对于版本在18.04以上的Ubuntu,可以直接使用包管理器安装LLVM套件 
sudo apt-get install clang-9 llvm-9 llvm-9-dev llvm-9-tools

3.安装约束求解器z3(时间有点长)

git clone https://github.com/Z3Prover/z3.git 
cd z3/ 
python scripts/mk_make.py 
sudo make install

4.安装uClibc 和 POSIX 环境(建议安装)

如果想使用 KLEE 来运行实际程序,将需要启用 KLEE POSIX 运行时,它构建在uClibc C 库之上。毕竟针对实际程序还是有用的

git clone https://github.com/klee/klee-uclibc.git 
cd klee-uclibc /configure --make-llvm-lib --with-llvm-config /usr/bin/llvm-config-9 
make

5.获取谷歌测试集(可选)

curl -OL https://github.com/google/googletest/archive/release-1.7.0.zip 
unzip release-1.7.0.zip

6.下载klee2-2的代码

下载地址:Releases · klee/klee · GitHub

下载后,解压到/opt/klee_env的路径下

构建 libc++,为了支持C++代码的运行,需要打开对C++标准库的支持

cd klee-2.2
LLVM_VERSION=9 SANITIZER_BUILD= BASE=/opt/klee_env(自己的路径) REQUIRES_RTTI=1 DISABLE_ASSERTIONS=1 ENABLE_DEBUG=0 ENABLE_OPTIMIZED=1 ./scripts/build/build.sh libcxx

7.编译构建klee

安装gcc9(可选)

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update 
sudo apt-get install gcc-9 g++-9

编译

cd klee2-2 
mkdir build
sudo cmake -DENABLE_SOLVER_STP=NO -DENABLE_SOLVER_Z3=ON -DENABLE_POSIX_RUNTIME=ON -DENABLE_KLEE_UCLIBC=ON -DKLEE_LIBCXX_DIR=/opt/klee_env/libc++-install-90/ DKLEE_LIBCXX_INCLUDE_DIR=/opt/klee_env/libc++-install-90/include/c++/v1/ -DENABLE_KLEE_EH_CXX=ON -DKLEE_LIBCXXABI_SRC_DIR=/opt/klee_env/llvm-90/libcxxabi/ -DKLEE_UCLIBC_PATH=/opt/klee_env/klee-uclibc/ -DENABLE_UNIT_TESTS=ON -DENABLE_SYSTEM_TESTS=ON -DGTEST_SRC_DIR=/opt/klee_env/googletest-release-1.7.0/ -DLLVM_CONFIG_BINARY=/usr/bin/llvm-config-9 -DLLVMCC=/usr/bin/clang-9 -DLLVMCXX=/usr/bin/clang++-9 -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ .. 
#没有报错进行最后几步 
make 
sudo make install
 #成功了!!!

8.成功的编译全过程,参考一下,报错什么就比对一下


root@root-vm:/opt/klee_env/klee-2.2/build# cmake -DENABLE_POSIX_RUNTIME=ON -DKLEE_UCLIBC_PATH=/opt/klee_env/klee-uclibc/  -DENABLE_UNIT_TESTS=ON -DLLVM_CONFIG_BINARY=/usr/bin/llvm-config-9  -DGTEST_SRC_DIR=/opt/klee_env/googletest-release-1.7.0/  -DKLEE_LIBCXX_DIR=/opt/klee_env/libc++-install-90/  -DKLEE_LIBCXX_INCLUDE_DIR=/opt/klee_env/libc++-install-90/include/c++/v1/ -DENABLE_KLEE_EH_CXX=ON -DKLEE_LIBCXXABI_SRC_DIR=/opt/klee_env/llvm-90/libcxxabi/ -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++  ..
-- KLEE version 2.2
-- CMake generator: Unix Makefiles
-- Build type: RelWithDebInfo
-- KLEE assertions enabled
-- LLVM_CONFIG_BINARY: /usr/bin/llvm-config-9
-- LLVM_PACKAGE_VERSION: "9.0.1"
-- LLVM_VERSION_MAJOR: "9"
-- LLVM_VERSION_MINOR: "0"
-- LLVM_VERSION_PATCH: "1"
-- LLVM_DEFINITIONS: "-D_GNU_SOURCE;-D__STDC_CONSTANT_MACROS;-D__STDC_FORMAT_MACROS;-D__STDC_LIMIT_MACROS"
-- LLVM_ENABLE_ASSERTIONS: "ON"
-- LLVM_ENABLE_EH: "OFF"
-- LLVM_ENABLE_RTTI: "ON"
-- LLVM_INCLUDE_DIRS: "/usr/lib/llvm-9/include"
-- LLVM_LIBRARY_DIRS: "/usr/lib/llvm-9/lib"
-- LLVM_TOOLS_BINARY_DIR: "/usr/lib/llvm-9/bin"
-- LLVM_ENABLE_VISIBILITY_INLINES_HIDDEN: "OFF"
-- TARGET_TRIPLE: "x86_64-pc-linux-gnu"
-- LLVM_BUILD_MAIN_SRC_DIR: "/usr/lib/llvm-9/build/"
-- Looking for bitcode compilers
-- Found /usr/bin/clang-9
-- Found /usr/bin/clang++-9
-- Testing bitcode compiler /usr/bin/clang-9
-- Compile success
-- Checking compatibility with LLVM 9.0.1
-- "/usr/bin/clang-9" is compatible
-- Testing bitcode compiler /usr/bin/clang++-9
-- Compile success
-- Checking compatibility with LLVM 9.0.1
-- "/usr/bin/clang++-9" is compatible
-- LLVMCC: /usr/bin/clang-9
-- LLVMCXX: /usr/bin/clang++-9
-- C++ compiler supports -Wall
-- C++ compiler supports -Wextra
-- C++ compiler supports -Wno-unused-parameter
-- C compiler supports -Wall
-- C compiler supports -Wextra
-- C compiler supports -Wno-unused-parameter
-- Not treating compiler warnings as errors
-- Could NOT find STP (missing: STP_DIR)
-- STP solver support disabled
-- Found Z3 libraries: "/usr/lib/x86_64-linux-gnu/libz3.so"
-- Found Z3 include path: "/usr/include"
-- Z3 solver support enabled
-- Found Z3
-- Z3_get_error_msg requires context
-- metaSMT solver support disabled
-- C++ compiler supports -fno-exceptions
-- Zlib support enabled
-- TCMalloc support enabled
-- C++ compiler supports -fno-builtin-malloc
-- C++ compiler supports -fno-builtin-calloc
-- C++ compiler supports -fno-builtin-realloc
-- C++ compiler supports -fno-builtin-free
-- SELinux support disabled
-- Workaround for LLVM PR39177 (affecting LLVM 3.9 - 7.0.0) disabled
-- KLEE_RUNTIME_BUILD_TYPE: Debug+Asserts
-- 32bit platform supported: 1
-- POSIX runtime enabled
-- klee-uclibc support enabled
-- Found klee-uclibc library: "/opt/klee_env/klee-uclibc/lib/libc.a"
-- klee-libc++ support enabled
-- Use libc++ include path: "/opt/klee_env/libc++-install-90/include/c++/v1"
-- Found libc++ library: "/opt/klee_env/libc++-install-90/lib/libc++.bca"
-- Use libc++abi source path: "/opt/klee_env/llvm-90/libcxxabi"
-- Support for C++ Exceptions enabled
-- CMAKE_CXX_FLAGS:  -Wall -Wextra -Wno-unused-parameter
-- KLEE_COMPONENT_EXTRA_INCLUDE_DIRS: '/usr/lib/llvm-9/include;/usr/include;/usr/include;/usr/include'
-- KLEE_COMPONENT_CXX_DEFINES: '-D_GNU_SOURCE;-D__STDC_CONSTANT_MACROS;-D__STDC_FORMAT_MACROS;-D__STDC_LIMIT_MACROS;-DKLEE_UCLIBC_BCA_NAME="klee-uclibc.bca";-DKLEE_LIBCXX_BC_NAME="libc++.bca"'
-- KLEE_COMPONENT_CXX_FLAGS: '-fno-exceptions;-fno-builtin-malloc;-fno-builtin-calloc;-fno-builtin-realloc;-fno-builtin-free'
-- KLEE_COMPONENT_EXTRA_LIBRARIES: '/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libtcmalloc.so'
-- KLEE_SOLVER_LIBRARIES: '/usr/lib/x86_64-linux-gnu/libz3.so'
-- LIB_BC_SUFFIX: 64_Release;64_Release+Debug;64_Release+Asserts;64_Release+Debug+Asserts;64_Debug;64_Debug+Asserts;32_Release;32_Release+Debug;32_Release+Asserts;32_Release+Debug+Asserts;32_Debug;32_Debug+Asserts
-- KLEE_RUNTIME_DIRECTORY: /opt/klee_env/klee-2.2/build/runtime/lib
-- Testing is enabled
-- Using lit: /usr/local/bin/lit
-- Unit tests enabled
-- Google Test: Building from source.
-- GTEST_SRC_DIR: /opt/klee_env/googletest-release-1.7.0/
-- Found PythonInterp: /usr/bin/python3.8 (found version "3.8.10") 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- GTEST_INCLUDE_DIR: /opt/klee_env/googletest-release-1.7.0/include
-- System tests enabled
CMake Deprecation Warning at test/CMakeLists.txt:143 (cmake_policy):
  The OLD behavior for policy CMP0026 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.


-- Found Doxygen: /usr/bin/doxygen (found version "1.8.17") found components: doxygen missing components: dot
-- Doxygen found
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/klee_env/klee-2.2/build

make成功结果:

sudo make install 成功结果:

 参考教程:

1.在 Ubuntu 18.04 下安装 Klee 2.2_Grazie_的博客-CSDN博客

2.ubuntu安装klee教程 - 代码先锋网

3.符号执行---KLEE论文阅读笔记与详细安装过程 


 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值