about summary refs log tree commit diff
path: root/shell.nix
diff options
context:
space:
mode:
Diffstat (limited to 'shell.nix')
-rw-r--r--shell.nix46
1 files changed, 46 insertions, 0 deletions
diff --git a/shell.nix b/shell.nix
index 8ec7eb8..b1372d0 100644
--- a/shell.nix
+++ b/shell.nix
@@ -5,6 +5,22 @@
 
 with import <nixpkgs> { };
 let
+  bcExtractHook = writeTextFile {
+    name = "bc-extract-hook";
+    text = ''
+      #!${runtimeShell}
+      extractBitcodes() {
+        mkdir -p $out/share/klee
+        for i in $out/bin/*
+        do
+          ${wllvm}/bin/extract-bc -o $out/share/klee/$(basename $i).bc $i
+        done
+      }
+      preDistPhases+=(extractBitcodes)
+    '';
+    executable = true;
+    destination = "/nix-support/setup-hook";
+  };
   binRenameHook = version: writeTextFile {
     name = "bin-rename-hook";
     text = ''
@@ -20,9 +36,11 @@ let
     destination = "/nix-support/setup-hook";
   };
   cppcheck = version: commit: hash: callPackage ./cppcheck {
+    stdenv = wllvmStdenv;
     inherit version;
     inherit commit;
     inherit hash;
+    inherit bcExtractHook;
     binRenameHook = binRenameHook version;
   };
   grep-2_6 = fetchurl {
@@ -34,20 +52,47 @@ let
     hash = "sha256-Tc4KT7g93QEg31HgC1L6dg8u2GddTUwLCuZCumkurWQ=";
   };
   grep = version: base: commit: hash: callPackage ./grep {
+    stdenv = wllvmStdenv;
     inherit version;
     inherit base;
     snapshot = fetchurl {
       url = "http://git.savannah.gnu.org/cgit/grep.git/snapshot/grep-${commit}.tar.gz";
       inherit hash;
     };
+    inherit bcExtractHook;
     binRenameHook = binRenameHook version;
   };
   md4c = version: commit: hash: callPackage ./md4c {
+    stdenv = wllvmStdenv;
     inherit version;
     inherit commit;
     inherit hash;
+    inherit bcExtractHook;
     binRenameHook = binRenameHook version;
   };
+  wllvmStdenv = let
+    inherit (llvmPackages_12) clang libllvm stdenv;
+    cflags = lib.concatStringsSep " " [
+      # Recommended by https://github.com/klee/klee/issues/902
+      "-g" "-O1" "-Xclang" "-disable-llvm-passes"
+      # Prevent clang from emitting safe version of certain library functions
+      # KLEE has yet to model
+      "-D__NO_STRING_INLINES" "-D_FORTIFY_SOURCE=0" "-U__OPTIMIZE__"
+    ];
+    wllvmEnv = writeText "wllvm.env" ''
+      CC=wllvm
+      CXX=wllvm++
+      export CFLAGS="${cflags}"
+      export CXXFLAGS="${cflags}"
+      export LLVM_COMPILER=clang
+      export PATH=${lib.makeBinPath [ clang libllvm wllvm ]}:$PATH
+    '';
+  in overrideCC stdenv (wrapCCWith {
+    cc = wllvm;
+    extraBuildCommands = ''
+      cat ${wllvmEnv} >> $out/nix-support/setup-hook
+    '';
+  });
 in mkShell {
   packages = [
     (cppcheck "9261.buggy"
@@ -74,5 +119,6 @@ in mkShell {
     (md4c "107.fixed"
       "5d7c35973e5d06b46ca21b5b6e292c56dba7ca23"
       "sha256-N/vIRhXuU948z0O4NXKMSKOZGAEE6UjGDT5oqrGpUy8=")
+    klee
   ];
 }