2022-03-30 09:31:56 +00:00
|
|
|
{ lib
|
2022-09-22 12:36:57 +00:00
|
|
|
, stdenv
|
2022-03-30 09:31:56 +00:00
|
|
|
, callPackage
|
2022-01-13 20:06:32 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, cmake
|
2022-07-14 12:49:19 +00:00
|
|
|
, clang
|
2022-09-22 12:36:57 +00:00
|
|
|
, llvm
|
2022-01-13 20:06:32 +00:00
|
|
|
, python3
|
|
|
|
, zlib
|
|
|
|
, z3
|
|
|
|
, stp
|
|
|
|
, cryptominisat
|
|
|
|
, gperftools
|
|
|
|
, sqlite
|
|
|
|
, gtest
|
|
|
|
, lit
|
2022-03-30 09:31:56 +00:00
|
|
|
|
|
|
|
# Build KLEE in debug mode. Defaults to false.
|
2022-01-13 20:06:32 +00:00
|
|
|
, debug ? false
|
2022-03-30 09:31:56 +00:00
|
|
|
|
|
|
|
# Include debug info in the build. Defaults to true.
|
|
|
|
, includeDebugInfo ? true
|
|
|
|
|
|
|
|
# Enable KLEE asserts. Defaults to true, since LLVM is built with them.
|
|
|
|
, asserts ? true
|
|
|
|
|
|
|
|
# Build the KLEE runtime in debug mode. Defaults to true, as this improves
|
|
|
|
# stack traces of the software under test.
|
|
|
|
, debugRuntime ? true
|
|
|
|
|
|
|
|
# Enable runtime asserts. Default false.
|
|
|
|
, runtimeAsserts ? false
|
|
|
|
|
|
|
|
# Extra klee-uclibc config.
|
|
|
|
, extraKleeuClibcConfig ? {}
|
2022-01-13 20:06:32 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2022-03-30 09:31:56 +00:00
|
|
|
# Python used for KLEE tests.
|
2022-01-13 20:06:32 +00:00
|
|
|
kleePython = python3.withPackages (ps: with ps; [ tabulate ]);
|
2022-03-30 09:31:56 +00:00
|
|
|
|
|
|
|
# The klee-uclibc derivation.
|
|
|
|
kleeuClibc = callPackage ./klee-uclibc.nix {
|
2022-09-22 12:36:57 +00:00
|
|
|
inherit stdenv clang llvm extraKleeuClibcConfig debugRuntime runtimeAsserts;
|
2022-03-30 09:31:56 +00:00
|
|
|
};
|
2022-09-22 12:36:57 +00:00
|
|
|
in stdenv.mkDerivation rec {
|
2022-01-13 20:06:32 +00:00
|
|
|
pname = "klee";
|
2022-07-14 12:49:19 +00:00
|
|
|
version = "2.3";
|
|
|
|
|
2022-01-13 20:06:32 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "klee";
|
|
|
|
repo = "klee";
|
|
|
|
rev = "v${version}";
|
2022-07-14 12:49:19 +00:00
|
|
|
sha256 = "sha256-E1c6K6Q+LAWm342W8I00JI6+LMvqmULHZLkv9Kj5RmY=";
|
2022-01-13 20:06:32 +00:00
|
|
|
};
|
2022-07-14 12:49:19 +00:00
|
|
|
|
2022-01-13 20:06:32 +00:00
|
|
|
buildInputs = [
|
2022-07-14 12:49:19 +00:00
|
|
|
cryptominisat
|
|
|
|
gperftools
|
|
|
|
lit # Configure phase checking for lit
|
2022-09-22 12:36:57 +00:00
|
|
|
llvm
|
2022-07-14 12:49:19 +00:00
|
|
|
sqlite
|
|
|
|
stp
|
|
|
|
z3
|
2022-01-13 20:06:32 +00:00
|
|
|
];
|
2022-07-14 12:49:19 +00:00
|
|
|
|
2022-01-13 20:06:32 +00:00
|
|
|
nativeBuildInputs = [
|
2022-07-14 12:49:19 +00:00
|
|
|
clang
|
|
|
|
cmake
|
2022-01-13 20:06:32 +00:00
|
|
|
];
|
2022-07-14 12:49:19 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [
|
2022-01-13 20:06:32 +00:00
|
|
|
gtest
|
|
|
|
|
|
|
|
# Should appear BEFORE lit, since lit passes through python rather
|
|
|
|
# than the python environment we make.
|
|
|
|
kleePython
|
|
|
|
(lit.override { python3 = kleePython; })
|
|
|
|
];
|
|
|
|
|
|
|
|
cmakeFlags = let
|
2022-03-30 09:31:56 +00:00
|
|
|
onOff = val: if val then "ON" else "OFF";
|
|
|
|
in [
|
|
|
|
"-DCMAKE_BUILD_TYPE=${if debug then "Debug" else if !debug && includeDebugInfo then "RelWithDebInfo" else "MinSizeRel"}"
|
|
|
|
"-DKLEE_RUNTIME_BUILD_TYPE=${if debugRuntime then "Debug" else "Release"}"
|
|
|
|
"-DKLEE_ENABLE_TIMESTAMP=${onOff false}"
|
|
|
|
"-DENABLE_KLEE_UCLIBC=${onOff true}"
|
|
|
|
"-DKLEE_UCLIBC_PATH=${kleeuClibc}"
|
|
|
|
"-DENABLE_KLEE_ASSERTS=${onOff asserts}"
|
|
|
|
"-DENABLE_POSIX_RUNTIME=${onOff true}"
|
|
|
|
"-DENABLE_UNIT_TESTS=${onOff true}"
|
|
|
|
"-DENABLE_SYSTEM_TESTS=${onOff true}"
|
2022-01-13 20:06:32 +00:00
|
|
|
"-DGTEST_SRC_DIR=${gtest.src}"
|
|
|
|
"-DGTEST_INCLUDE_DIR=${gtest.src}/googletest/include"
|
|
|
|
"-Wno-dev"
|
|
|
|
];
|
|
|
|
|
|
|
|
# Silence various warnings during the compilation of fortified bitcode.
|
2023-03-04 12:14:45 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = toString ["-Wno-macro-redefined"];
|
2022-01-13 20:06:32 +00:00
|
|
|
|
|
|
|
prePatch = ''
|
|
|
|
patchShebangs .
|
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
passthru = {
|
|
|
|
# Let the user depend on `klee.uclibc` for klee-uclibc
|
|
|
|
uclibc = kleeuClibc;
|
|
|
|
};
|
|
|
|
|
2022-01-13 20:06:32 +00:00
|
|
|
meta = with lib; {
|
|
|
|
description = "A symbolic virtual machine built on top of LLVM";
|
|
|
|
longDescription = ''
|
|
|
|
KLEE is a symbolic virtual machine built on top of the LLVM compiler
|
|
|
|
infrastructure. Currently, there are two primary components:
|
|
|
|
|
|
|
|
1. The core symbolic virtual machine engine; this is responsible for
|
|
|
|
executing LLVM bitcode modules with support for symbolic values. This
|
|
|
|
is comprised of the code in lib/.
|
|
|
|
|
|
|
|
2. A POSIX/Linux emulation layer oriented towards supporting uClibc, with
|
|
|
|
additional support for making parts of the operating system environment
|
|
|
|
symbolic.
|
|
|
|
|
|
|
|
Additionally, there is a simple library for replaying computed inputs on
|
|
|
|
native code (for closed programs). There is also a more complicated
|
|
|
|
infrastructure for replaying the inputs generated for the POSIX/Linux
|
|
|
|
emulation layer, which handles running native programs in an environment
|
|
|
|
that matches a computed test input, including setting up files, pipes,
|
|
|
|
environment variables, and passing command line arguments.
|
|
|
|
'';
|
|
|
|
homepage = "https://klee.github.io/";
|
|
|
|
license = licenses.ncsa;
|
|
|
|
platforms = [ "x86_64-linux" ];
|
|
|
|
maintainers = with maintainers; [ numinit ];
|
|
|
|
};
|
|
|
|
}
|