Skip to content

Instantly share code, notes, and snippets.

@Mr-Slippery
Created November 18, 2020 20:49
Show Gist options
  • Save Mr-Slippery/bdbdd63c757088341633087706400738 to your computer and use it in GitHub Desktop.
Save Mr-Slippery/bdbdd63c757088341633087706400738 to your computer and use it in GitHub Desktop.
Example invocation of KLEE on a sample source or user-supplied file
#!/usr/bin/env bash
set -euo pipefail
FILE=${1-main.cc}
if [ ! -f "${FILE}" ]
then
cat << EOF > "${FILE}"
#include <klee/klee.h>
#include <assert.h>
int main(int argc, char *argv[])
{
int root;
klee_make_symbolic(&root, sizeof root, "root");
klee_assert(root * root != 121);
return 0;
}
EOF
fi
KLEE_IMAGE="klee/klee:2.1"
docker pull "${KLEE_IMAGE}"
RUN="docker run -v $(pwd):$(pwd) --rm ${KLEE_IMAGE}"
CLANG_BIN=/tmp/llvm-60-install_O_D_A/bin
CLANGXX="${RUN} ${CLANG_BIN}/clang++"
CLANG="${RUN} ${CLANG_BIN}/clang"
KLEE_INCLUDE=/home/klee/klee_src/include
KLEE_BUILD=/home/klee/klee_build
KLEE_BIN="${KLEE_BUILD}/bin"
KLEE="${RUN} ${KLEE_BIN}/klee"
KTEST="${RUN} ${KLEE_BIN}/ktest-tool"
${CLANG} -g -emit-llvm -DKLEE -I"${KLEE_INCLUDE}" -c "$(pwd)/${FILE}" -o "$(pwd)/${FILE%%.*}.bc"
#${KLEE} --libc=uclibc --posix-runtime "$(pwd)/${FILE%%.*}.bc" -sym-files 1 64
time ${KLEE} "$(pwd)/${FILE%%.*}.bc"
#time ${KLEE} -emit-all-errors "$(pwd)/${FILE%%.*}.bc"
ERROR_FILE="$(basename "$(find -L klee-last -name '*.assert.err')")"
${KTEST} "$(pwd)/klee-last/${ERROR_FILE%%.*}.ktest"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment