about summary refs log tree commit diff homepage
path: root/scripts/build
diff options
context:
space:
mode:
authorMartin Nowack <m.nowack@imperial.ac.uk>2022-03-25 23:07:40 +0000
committerCristian Cadar <c.cadar@imperial.ac.uk>2022-03-30 12:18:59 +0100
commit0373fd7d10fb5b23c86ebec2e932ea8f059f5b71 (patch)
tree785721f0b4202b1d30fa77160368e969e12a4eaa /scripts/build
parent23548f09b7bff999b0b346a5511b2a316ec798b4 (diff)
downloadklee-0373fd7d10fb5b23c86ebec2e932ea8f059f5b71.tar.gz
Clearly separate between LLVM, a bitcode compiler, and sanitizer compiler
All three can be different but also provided by the same package.
By separating the different use-cases, it allows to set them
independently.
Diffstat (limited to 'scripts/build')
-rw-r--r--scripts/build/p-clang-linux-ubuntu.inc17
-rw-r--r--scripts/build/p-clang-linux.inc5
-rw-r--r--scripts/build/p-clang-osx.inc2
-rw-r--r--scripts/build/p-llvm-linux-ubuntu.inc93
-rw-r--r--scripts/build/p-llvm.inc343
-rw-r--r--scripts/build/p-sanitizer-linux-ubuntu.inc46
-rw-r--r--scripts/build/p-sanitizer-linux.inc42
-rw-r--r--scripts/build/v-sanitizer.inc23
-rw-r--r--scripts/build/v-sqlite.inc2
-rw-r--r--scripts/build/v-stp.inc2
-rw-r--r--scripts/build/v-z3.inc2
11 files changed, 367 insertions, 210 deletions
diff --git a/scripts/build/p-clang-linux-ubuntu.inc b/scripts/build/p-clang-linux-ubuntu.inc
index 736cc097..9dac1352 100644
--- a/scripts/build/p-clang-linux-ubuntu.inc
+++ b/scripts/build/p-clang-linux-ubuntu.inc
@@ -16,18 +16,21 @@ install_binary_artifact_clang() {
     lsb-release
     gnupg
   )
-
   with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
-  wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key| with_sudo apt-key add -
 
-  # Add repository
+  # Add LLVM upstream repository if available
   codename="$(lsb_release --codename --short)"
-  apt_entry="deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}${version} main"
-  if [[ ! $(grep -rq "${apt_entry}" /etc/apt) ]]; then
-    echo "${apt_entry}" | with_sudo tee -a /etc/apt/sources.list
-    with_sudo apt update -y
+  if wget -q "https://apt.llvm.org/${codename}/dists/llvm-toolchain-${codename}${version}/"; then
+    wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key| with_sudo apt-key add -
+
+    apt_entry="deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}${version} main"
+    if ! grep -rq "${apt_entry}" /etc/apt; then
+      echo "${apt_entry}" | with_sudo tee -a /etc/apt/sources.list
+      with_sudo apt update -y
+    fi
   fi
 
+
   with_sudo apt update -y
   dependencies=(
     "llvm${version}"
diff --git a/scripts/build/p-clang-linux.inc b/scripts/build/p-clang-linux.inc
index f3dfbb6e..c6ee025e 100644
--- a/scripts/build/p-clang-linux.inc
+++ b/scripts/build/p-clang-linux.inc
@@ -16,11 +16,6 @@ setup_artifact_variables_clang() {
 
   BITCODE_CC="${bin_path}/clang"
   BITCODE_CXX="${bin_path}/clang++"
-
-  #[[ -z ${SANITIZER_C_COMPILER+x} ]] && 
-  SANITIZER_C_COMPILER="${BITCODE_CC}"
-  #[[ -z ${SANITIZER_CXX_COMPILER+x} ]] && 
-  SANITIZER_CXX_COMPILER="${BITCODE_CXX}"
 }
 
 # Check if the binary artifact is installed
diff --git a/scripts/build/p-clang-osx.inc b/scripts/build/p-clang-osx.inc
index e3634e5a..a0ef5a9d 100644
--- a/scripts/build/p-clang-osx.inc
+++ b/scripts/build/p-clang-osx.inc
@@ -18,7 +18,5 @@ setup_artifact_variables_clang() {
   BITCODE_CC="/usr/local/opt/llvm@${LLVM_VERSION_MAJOR}/bin/clang"
   BITCODE_CXX="/usr/local/opt/llvm@${LLVM_VERSION_MAJOR}/bin/clang++"
 
-  SANITIZER_C_COMPILER="${BITCODE_CC}"
-  SANITIZER_CXX_COMPILER="${BITCODE_CXX}"
   LLVM_CONFIG="/usr/local/opt/llvm@${LLVM_VERSION_MAJOR}/bin/llvm-config"
 }
\ No newline at end of file
diff --git a/scripts/build/p-llvm-linux-ubuntu.inc b/scripts/build/p-llvm-linux-ubuntu.inc
index 83e02d8e..f066592b 100644
--- a/scripts/build/p-llvm-linux-ubuntu.inc
+++ b/scripts/build/p-llvm-linux-ubuntu.inc
@@ -40,6 +40,7 @@ install_build_dependencies_llvm() {
     git # To check out code
     zlib1g-dev
     cmake
+    git
   )
   
   if [[ "${SANITIZERS[*]}" == "memory" ]]; then
@@ -51,7 +52,8 @@ install_build_dependencies_llvm() {
 }
 
 install_binary_artifact_llvm() {
-  local enable_optimized=$(to_bool "${ENABLE_OPTIMIZED}")
+  # No need to check for optimised, we can build against LLVM with optimised and non-optimised versions
+  #  local enable_optimized=$(to_bool "${ENABLE_OPTIMIZED}")
   local enable_debug=$(to_bool "${ENABLE_DEBUG}")
   local disable_assertions=$(to_bool "${DISABLE_ASSERTIONS}")
   local requires_rtti=$(to_bool "${REQUIRES_RTTI}")
@@ -80,18 +82,21 @@ install_binary_artifact_llvm() {
     gnupg
   )
   with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
-  wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key| with_sudo apt-key add -
-  
+
   local version=""
   [[ "${LLVM_VERSION_MAJOR}" -le 6 ]] && version="-${LLVM_VERSION}"
   [[ "${LLVM_VERSION_MAJOR}" -ge 7 ]] && version="-${LLVM_VERSION_MAJOR}"
 
-  # Add repository
+  # Add LLVM upstream repository if available
   codename="$(lsb_release --codename --short)"
-  apt_entry="deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}${version} main"
-  if [[ ! $(grep -rq "${apt_entry}" /etc/apt) ]]; then
-    echo  "${apt_entry}" >> /etc/apt/sources.list
-    apt update -y
+  if wget -q "https://apt.llvm.org/${codename}/dists/llvm-toolchain-${codename}${version}/"; then
+    wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key| with_sudo apt-key add -
+
+    apt_entry="deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}${version} main"
+    if ! grep -rq "${apt_entry}" /etc/apt; then
+      echo "${apt_entry}" | with_sudo tee -a /etc/apt/sources.list
+      with_sudo apt update -y
+    fi
   fi
 
   dependencies=(
@@ -105,23 +110,36 @@ install_binary_artifact_llvm() {
   with_sudo apt -y --no-install-recommends install "${dependencies[@]}" || return 1
 }
 
-# Check if the binary artifact is installed
-is_installed_llvm() {
+check_llvm_config_version() {
+    local check_mode=1
+    strict_mode="$1" # if llvm-config should be checked strictly
+    local lc=""
+    lc="$2" # path to llvm-config
+
+    # If not set return error
+    [[ -z "${lc}" ]] && return 1
+
+    # First check, if the provided llvm-config is a full path
+    if [[ ! -f "${lc}" ]]; then
+      # Nothing found, assume it's just the name of the binary in path, find the path
+      lc=$(which "${lc}")
+
+      # If path not found return error
+      [[ -z "${lc}" ]] && return 1
+    fi
+
     local version=""
     local LLVM_VERSION_MAJOR="${LLVM_VERSION/.*/}"
     local LLVM_VERSION_MINOR="${LLVM_VERSION/*./}"
     [[ "${LLVM_VERSION_MAJOR}" -le 6 ]] && version="${LLVM_VERSION}"
     [[ "${LLVM_VERSION_MAJOR}" -ge 7 ]] && version="${LLVM_VERSION_MAJOR}"
-    local lc=""
 
-    # Check for llvm-config without suffix but correct versions number
-    lc=$(which "llvm-config")
-    if [[ -z "${lc}" || $($lc --version) != "${LLVM_VERSION}"* ]]; then
-      # Check if llvm-config with the right version exists
-      lc=$(which "llvm-config-${version}")
-    fi
 
-    [[ -z "${lc}" ]] && return 1
+    # Check for llvm-config without suffix but correct version number
+    [[ $($lc --version) == "${LLVM_VERSION}"* ]] || return 1
+
+    # In case correct version numbers are required, return already
+    [[ "${check_mode}" == "0" ]] && return 0;
 
     local rtti
     rtti="$(${lc} --has-rtti)"
@@ -130,9 +148,35 @@ is_installed_llvm() {
     local build_mode
     build_mode="$(${lc} --build-mode)"
 
-    # Check requested mode with mode of the found item  
+    # Check requested mode with mode of the found item
     [[ $(to_bool "${REQUIRES_RTTI}") -eq $(to_bool "${rtti}") ]] || return 1
     [[ $(to_bool "${DISABLE_ASSERTIONS}") -ne $(to_bool "${assertion}") ]] || return 1
+
+    local shared_mode
+    shared_mode="$(${lc} --shared-mode)" || return 1
+}
+
+# Check if the binary artifact is installed
+is_installed_llvm() {
+  # Check for variables set and not empty
+  local version=""
+  local LLVM_VERSION_MAJOR="${LLVM_VERSION/.*/}"
+  local LLVM_VERSION_MINOR="${LLVM_VERSION/*./}"
+  [[ "${LLVM_VERSION_MAJOR}" -le 6 ]] && version="${LLVM_VERSION}"
+  [[ "${LLVM_VERSION_MAJOR}" -ge 7 ]] && version="${LLVM_VERSION_MAJOR}"
+
+  # Check for llvm-config without suffix but correct version number
+  local lc
+
+  # First check with the version-specific number
+  lc=$(which "llvm-config-${LLVM_VERSION_MAJOR}")
+  check_llvm_config_version 1 "${lc}" && return 0
+
+  # As alternative, try the version-less number
+  lc=$(which "llvm-config")
+  check_llvm_config_version 1 "${lc}" && return 0
+
+  return 1
 }
 
 setup_artifact_variables_llvm() {
@@ -142,21 +186,22 @@ setup_artifact_variables_llvm() {
     local LLVM_VERSION_MINOR="${LLVM_VERSION/*./}"
     [[ "${LLVM_VERSION_MAJOR}" -le 6 ]] && version="${LLVM_VERSION}"
     [[ "${LLVM_VERSION_MAJOR}" -ge 7 ]] && version="${LLVM_VERSION_MAJOR}"
+
     local lc=""
-    # Check for llvm-config without suffix but correct versions number
+    # Check for llvm-config without suffix but correct version number
     lc=$(which "llvm-config")
-    if [[ -z "${lc}" || $($lc --version) != "${LLVM_VERSION}"* ]]; then
+    local is_ins=$(check_llvm_config_version 1 "${lc}")
+    if [[ ! "${is_ins}" ]]; then
       # Check if llvm-config with the right version exists
       lc=$(which "llvm-config-${version}")
+      is_ins=$(check_llvm_config_version 1 "${lc}") || return 1
     fi
 
-    [[ -z "${lc}" ]] && return 1
-
     LLVM_CONFIG="${lc}"
-
     LLVM_INSTALL="$(${lc} --bindir)"
     BITCODE_CC="${LLVM_INSTALL}/clang"
     BITCODE_CXX="${LLVM_INSTALL}/clang++"
+    LLVM_BIN="${LLVM_INSTALL}/bin"
 }
 
 get_build_artifacts_llvm() {
diff --git a/scripts/build/p-llvm.inc b/scripts/build/p-llvm.inc
index e335ad73..d1b9374e 100644
--- a/scripts/build/p-llvm.inc
+++ b/scripts/build/p-llvm.inc
@@ -1,92 +1,92 @@
 validate_build_config_llvm() {
-    # Check variables that are needed for building 
-    [[ -n "${LLVM_SRC_BASE}" ]] || { echo "LLVM_SRC_BASE not set"; exit 1; }
-    [[ -n "${LLVM_VERSION_SHORT}" ]] || { echo "LLVM_VERSION_SHORT not set"; exit 1; }
+  # Check variables that are needed for building
+  [[ -n "${LLVM_SRC_BASE}" ]] || {
+    echo "LLVM_SRC_BASE not set"
+    exit 1
+  }
+  [[ -n "${LLVM_VERSION_SHORT}" ]] || {
+    echo "LLVM_VERSION_SHORT not set"
+    exit 1
+  }
 }
 
 setup_build_variables_llvm() {
-    LLVM_SUFFIX=""
-
-    local BuildMode=""
-    local enable_optimized=$(to_bool "${ENABLE_OPTIMIZED}")
-    local enable_debug=$(to_bool "${ENABLE_DEBUG}")
-    local disable_assertions=$(to_bool "${DISABLE_ASSERTIONS}")
-    local requires_rtti=$(to_bool "${REQUIRES_RTTI}")
-
-    if [[ "${enable_optimized}" == "1" ]]; then
-      LLVM_SUFFIX+="_O"
-      BuildMode="Release"
-    else
-      LLVM_SUFFIX+="_NO"
-    fi
+  source "${DIR}/common-functions"
+  LLVM_SUFFIX=""
 
-    if [[ ("${enable_debug}" == "1") || ("${enable_optimized}" != "1") ]]; then
-      LLVM_SUFFIX+="_D"
-      [ -z "$BuildMode" ] && BuildMode="Debug" || BuildMode="$BuildMode+Debug"
-    else
-      LLVM_SUFFIX+="_ND"
-    fi
+  local BuildMode=""
+  local enable_optimized=$(to_bool "${ENABLE_OPTIMIZED}")
+  local enable_debug=$(to_bool "${ENABLE_DEBUG}")
+  local disable_assertions=$(to_bool "${DISABLE_ASSERTIONS}")
+  local requires_rtti=$(to_bool "${REQUIRES_RTTI}")
 
-    if [[ "${disable_assertions}" == "1" || -z "${disable_assertions}" ]]; then
-      LLVM_SUFFIX+="_NA"
-    else
-      LLVM_SUFFIX+="_A"
-      [ -z "$BuildMode" ] && BuildMode="Asserts" || BuildMode="$BuildMode+Asserts"
-    fi
+  if [[ "${enable_optimized}" == "1" ]]; then
+    LLVM_SUFFIX+="_O"
+    BuildMode="Release"
+  else
+    LLVM_SUFFIX+="_NO"
+  fi
 
-    if [[ "${requires_rtti}" == "1" ]]; then
-      LLVM_SUFFIX+="_RTTI"
-    fi
+  if [[ ("${enable_debug}" == "1") || ("${enable_optimized}" != "1") ]]; then
+    LLVM_SUFFIX+="_D"
+    [ -z "$BuildMode" ] && BuildMode="Debug" || BuildMode="$BuildMode+Debug"
+  else
+    LLVM_SUFFIX+="_ND"
+  fi
 
-    if [[ "${SANITIZER_SUFFIX}x" != "x" ]]; then
-      LLVM_SUFFIX+="${SANITIZER_SUFFIX}"
-    fi
+  if [[ "${disable_assertions}" == "1" || -z "${disable_assertions}" ]]; then
+    LLVM_SUFFIX+="_NA"
+  else
+    LLVM_SUFFIX+="_A"
+    [ -z "$BuildMode" ] && BuildMode="Asserts" || BuildMode="$BuildMode+Asserts"
+  fi
+
+  if [[ "${requires_rtti}" == "1" ]]; then
+    LLVM_SUFFIX+="_RTTI"
+  fi
 
-    LLVM_SRC_BASE="${BASE}/llvm-${LLVM_VERSION_SHORT}"
-    LLVM_BUILD="${LLVM_SRC_BASE}-build${LLVM_SUFFIX}"
-    LLVM_INSTALL="${LLVM_SRC_BASE}-install${LLVM_SUFFIX}"
-    LLVM_BIN="${LLVM_INSTALL}/bin"
-    LLVM_BUILD_BIN="${LLVM_BUILD}/bin"
-
-    LLVM_CONFIG="${LLVM_BIN}/llvm-config"
-    BITCODE_CC="${LLVM_BIN}/clang"
-    BITCODE_CXX="${LLVM_BIN}/clang++"
-
-
-    for sanitizer in "${SANITIZERS[@]}"; do
-      [[ -z "${sanitizer}" ]] && continue
-      # Undefined Behaviour Sanitizer
-      if [ "${sanitizer}" == "memory" ]; then
-        SANITIZER_LLVM_UNINSTRUMENTED="${LLVM_BUILD}_uninstrumented"
-        SANITIZER_LLVM_LIBCXX="${LLVM_BUILD}_libcxx"
-
-        SANITIZER_C_COMPILER="${SANITIZER_LLVM_UNINSTRUMENTED}/bin/clang"
-        SANITIZER_CXX_COMPILER="${SANITIZER_LLVM_UNINSTRUMENTED}/bin/clang++"
-        SANITIZER_CMAKE_C_COMPILER=("-DCMAKE_C_COMPILER=${SANITIZER_C_COMPILER}")
-        SANITIZER_CMAKE_CXX_COMPILER=("-DCMAKE_CXX_COMPILER=${SANITIZER_CXX_COMPILER}")
-
-        MSAN_LINK_FLAGS=("-lc++abi" "-Wl,--rpath=${SANITIZER_LLVM_LIBCXX}/lib" "-L${SANITIZER_LLVM_LIBCXX}/lib")
-        MSAN_FLAGS=("${MSAN_LINK_FLAGS[@]}" -nostdinc++
-           -isystem "${SANITIZER_LLVM_LIBCXX}/include"
-           -isystem "${SANITIZER_LLVM_LIBCXX}/include/c++/v1"
-           "-fsanitize=memory"
-           "-fsanitize-memory-track-origins"
-           -w -fno-omit-frame-pointer -g)
-        SANITIZER_CXX_FLAGS+=("${MSAN_FLAGS[@]}" "-stdlib=libc++")
-        SANITIZER_C_FLAGS+=("${MSAN_FLAGS[@]}")
-        SANITIZER_LD_FLAGS+=("${MSAN_LINK_FLAGS[@]}")
-
-        # Use the uninstrumented compiler
-        BITCODE_CC="${SANITIZER_C_COMPILER}"
-        BITCODE_CXX="${SANITIZER_CXX_COMPILER}"
-        # But point to the instrumented llvm-config
-        LLVM_CONFIG="${LLVM_BIN}/llvm-config"
-        continue
-      fi
-      # Setup default sanitizer arguments
-      SANITIZER_C_COMPILER="${LLVM_BIN}/clang"
-      SANITIZER_CXX_COMPILER="${LLVM_BIN}/clang++"
-    done
+  if [[ "${SANITIZER_SUFFIX}x" != "x" ]]; then
+    LLVM_SUFFIX+="${SANITIZER_SUFFIX}"
+  fi
+
+  LLVM_SRC_BASE="${BASE}/llvm-${LLVM_VERSION_SHORT}"
+  LLVM_BUILD="${LLVM_SRC_BASE}-build${LLVM_SUFFIX}"
+  LLVM_INSTALL="${LLVM_SRC_BASE}-install${LLVM_SUFFIX}"
+  LLVM_BIN="${LLVM_INSTALL}/bin"
+  LLVM_BUILD_BIN="${LLVM_BUILD}/bin"
+
+  LLVM_CONFIG="${LLVM_BIN}/llvm-config"
+  BITCODE_CC="${LLVM_BIN}/clang"
+  BITCODE_CXX="${LLVM_BIN}/clang++"
+
+  for sanitizer in "${SANITIZERS[@]}"; do
+    [[ -z "${sanitizer}" ]] && continue
+    # Undefined Behaviour Sanitizer
+    if [ "${sanitizer}" == "memory" ]; then
+      SANITIZER_LLVM_UNINSTRUMENTED="${LLVM_BUILD}_uninstrumented"
+      SANITIZER_LLVM_LIBCXX="${LLVM_BUILD}_libcxx"
+
+      MSAN_LINK_FLAGS=("-lc++abi" "-Wl,--rpath=${SANITIZER_LLVM_LIBCXX}/lib" "-L${SANITIZER_LLVM_LIBCXX}/lib")
+      MSAN_FLAGS=("${MSAN_LINK_FLAGS[@]}" -nostdinc++
+        -isystem "${SANITIZER_LLVM_LIBCXX}/include"
+        -isystem "${SANITIZER_LLVM_LIBCXX}/include/c++/v1"
+        "-fsanitize=memory"
+        "-fsanitize-memory-track-origins"
+        -w -fno-omit-frame-pointer -g)
+      SANITIZER_CXX_FLAGS+=("${MSAN_FLAGS[@]}" "-stdlib=libc++")
+      SANITIZER_C_FLAGS+=("${MSAN_FLAGS[@]}")
+      SANITIZER_LD_FLAGS+=("${MSAN_LINK_FLAGS[@]}")
+      SANITIZER_C_COMPILER="${SANITIZER_LLVM_UNINSTRUMENTED}/bin/clang"
+      SANITIZER_CXX_COMPILER="${SANITIZER_LLVM_UNINSTRUMENTED}/bin/clang++"
+
+      # Use the uninstrumented compiler
+      BITCODE_CC="${SANITIZER_C_COMPILER}"
+      BITCODE_CXX="${SANITIZER_CXX_COMPILER}"
+      # But point to the instrumented llvm-config
+      LLVM_CONFIG="${LLVM_BIN}/llvm-config"
+      continue
+    fi
+  done
 }
 
 download_llvm() {
@@ -98,73 +98,74 @@ download_llvm() {
 
   branch_name="release/${LLVM_VERSION_MAJOR}.x"
   git_clone_or_update "https://github.com/llvm/llvm-project.git" "${LLVM_SRC_BASE}" "${branch_name}" || exit 1
-
   # Apply existing patches if needed
   if [ -f "${DIR}/patches/llvm${LLVM_VERSION_SHORT}.patch" ]; then
-     cd "${LLVM_SRC_BASE}" || (echo "Directory does not exist"; exit 1)
-     patch -p1 --follow-symlinks -i "${DIR}/patches/llvm${LLVM_VERSION_SHORT}.patch" || return 1
+    cd "${LLVM_SRC_BASE}" || (
+      echo "Directory does not exist"
+      exit 1
+    )
+    patch -p1 --follow-symlinks -i "${DIR}/patches/llvm${LLVM_VERSION_SHORT}.patch" || return 1
   fi
 
-  touch "${LLVM_SRC_BASE}/.src_checked_out" 
+  touch "${LLVM_SRC_BASE}/.src_checked_out"
 }
 
-build_llvm() {
-    local enable_optimized=$(to_bool "${ENABLE_OPTIMIZED}")
-    local enable_debug=$(to_bool "${ENABLE_DEBUG}")
-    local disable_assertions=$(to_bool "${DISABLE_ASSERTIONS}")
-    local requires_rtti=$(to_bool "${REQUIRES_RTTI}")
 
-    # For memory sanitizer, we have a multi-stage build process
-    if [[ "${SANITIZER_BUILD}" == "memory" ]]; then
-       # Build uninstrumented compiler
-       mkdir -p "${SANITIZER_LLVM_UNINSTRUMENTED}"
-       cd "${SANITIZER_LLVM_UNINSTRUMENTED}"
-       cmake -GNinja -DCMAKE_BUILD_TYPE=Release \
+configure_llvm() {
+  local enable_optimized=$(to_bool "${ENABLE_OPTIMIZED}")
+  local enable_debug=$(to_bool "${ENABLE_DEBUG}")
+  local disable_assertions=$(to_bool "${DISABLE_ASSERTIONS}")
+  local requires_rtti=$(to_bool "${REQUIRES_RTTI}")
+
+  # For memory sanitizer, we have a multi-stage build process
+  if [[ "${SANITIZER_BUILD}" == "memory" ]]; then
+    # Build uninstrumented compiler
+    mkdir -p "${SANITIZER_LLVM_UNINSTRUMENTED}"
+    cd "${SANITIZER_LLVM_UNINSTRUMENTED}"
+    cmake -GNinja -DCMAKE_BUILD_TYPE=Release \
       "-DLLVM_OPTIMIZED_TABLEGEN=ON" \
-        "-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;libcxx;libcxxabi" \
+      "-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;libcxx;libcxxabi" \
       "-DLLVM_TARGETS_TO_BUILD=X86" \
-        "${LLVM_SRC_BASE}/llvm"
+      "${LLVM_SRC_BASE}/llvm"
     ninja compiler-rt cxx cxxabi clang || return 1
 
-       # Build instrumented libc/libc++
-       mkdir -p "${SANITIZER_LLVM_LIBCXX}"
-       cd "${SANITIZER_LLVM_LIBCXX}"
-       cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-        "-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;libcxx;libcxxabi" \
-        -DLLVM_USE_SANITIZER=MemoryWithOrigins \
-        "${SANITIZER_CMAKE_C_COMPILER[@]}" \
-        "${SANITIZER_CMAKE_CXX_COMPILER[@]}" \
+    # Build instrumented libc/libc++
+    mkdir -p "${SANITIZER_LLVM_LIBCXX}"
+    cd "${SANITIZER_LLVM_LIBCXX}"
+    cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+      "-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;libcxx;libcxxabi" \
+      -DLLVM_USE_SANITIZER=MemoryWithOrigins \
+      "-DCMAKE_C_COMPILER=${SANITIZER_C_COMPILER}" \
+      "-DCMAKE_CXX_COMPILER=${SANITIZER_CXX_COMPILER}" \
       "-DLLVM_OPTIMIZED_TABLEGEN=ON" \
       "-DLLVM_TARGETS_TO_BUILD=X86" \
-        "${LLVM_SRC_BASE}/llvm"
-    ninja compiler-rt cxx cxxabi|| return 1
-
-       # Build instrumented clang
-       mkdir -p "${LLVM_BUILD}"
-       cd "${LLVM_BUILD}"
-       C_F="${SANITIZER_C_FLAGS[*]}"
-       CXX_F="${SANITIZER_CXX_FLAGS[*]}"
-       LD_F="${SANITIZER_LD_FLAGS[*]}"
-       cmake -GNinja \
-          "${SANITIZER_CMAKE_C_COMPILER[@]}" \
-          "${SANITIZER_CMAKE_CXX_COMPILER[@]}" \
-          -DCMAKE_C_FLAGS="$C_F" \
-          -DCMAKE_CXX_FLAGS="${CXX_F}" \
-          -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-          "-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;libcxx;libcxxabi" \
-          -DLLVM_ENABLE_ASSERTIONS=On \
-          -DLLVM_USE_SANITIZER=MemoryWithOrigins \
-          -DLLVM_ENABLE_LIBCXX=ON \
-          -DCMAKE_EXE_LINKER_FLAGS="${LD_F}" \
-          -DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL}" \
+      "${LLVM_SRC_BASE}/llvm"
+    ninja compiler-rt cxx cxxabi || return 1
+
+    # Build instrumented clang
+    mkdir -p "${LLVM_BUILD}"
+    cd "${LLVM_BUILD}"
+    C_F="${SANITIZER_C_FLAGS[*]}"
+    CXX_F="${SANITIZER_CXX_FLAGS[*]}"
+    LD_F="${SANITIZER_LD_FLAGS[*]}"
+    cmake -GNinja \
+      "-DCMAKE_C_COMPILER=${SANITIZER_C_COMPILER}" \
+      "-DCMAKE_CXX_COMPILER=${SANITIZER_CXX_COMPILER}" \
+      -DCMAKE_C_FLAGS="$C_F" \
+      -DCMAKE_CXX_FLAGS="${CXX_F}" \
+      -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+      "-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;libcxx;libcxxabi" \
+      -DLLVM_ENABLE_ASSERTIONS=On \
+      -DLLVM_USE_SANITIZER=MemoryWithOrigins \
+      -DLLVM_ENABLE_LIBCXX=ON \
+      -DCMAKE_EXE_LINKER_FLAGS="${LD_F}" \
+      -DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL}" \
       -DBUILD_SHARED_LIBS=ON \
       -DLLVM_OPTIMIZED_TABLEGEN=ON \
       -DLLVM_TARGETS_TO_BUILD=X86 \
-          "${LLVM_SRC_BASE}/llvm"
-      # Build clang as a dependency and install all needed packages
-    ninja clang || return 1
-      return 0
-    fi
+      "${LLVM_SRC_BASE}/llvm"
+    return 0
+  fi
 
   # Configure; build; and install
   mkdir -p "${LLVM_BUILD}"
@@ -175,8 +176,8 @@ build_llvm() {
 
   # Configure LLVM
   CONFIG=(
-     "-DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL}"
-     "-DLLVM_BUILD_LLVM_DYLIB=TRUE"
+    "-DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL}"
+    "-DLLVM_BUILD_LLVM_DYLIB=TRUE"
   )
 
   # Select components to build
@@ -213,38 +214,59 @@ build_llvm() {
 
   # Remove unneeded targets
   CONFIG+=(
-     "-DLLVM_INCLUDE_EXAMPLES=OFF"
-#     "-DLLVM_INCLUDE_TESTS=OFF"
+    "-DLLVM_INCLUDE_EXAMPLES=OFF"
     "-DCLANG_INCLUDE_TESTS=OFF"
-     "-DLLVM_INCLUDE_BENCHMARKS=OFF"
-     "-DBUILD_SHARED_LIBS=ON"
+    "-DLLVM_INCLUDE_BENCHMARKS=OFF"
+    "-DBUILD_SHARED_LIBS=ON"
     "-DLLVM_OPTIMIZED_TABLEGEN=ON"
     "-DLLVM_TARGETS_TO_BUILD=X86"
   )
 
-  local variables=("")
-
-  if [[ -n "${CC:-}" ]]; then
-    variables+=("CC=${CC}")
+  if [[ -n ${SANITIZER_BUILD} ]]; then
+    CC="${SANITIZER_C_COMPILER}"
+    CXX="${SANITIZER_CXX_COMPILER}"
   fi
 
-  if [[ -n "${CXX:-}" ]]; then
-    variables+=("CXX=${CXX}")
-  fi
+  (
+    if [[ -n "${CC:-}" ]]; then
+      export "CC=${CC}"
+    fi
 
-  if [[ -n "${LDFLAGS:-}" ]]; then
-    variables+=("LDFLAGS=${LLVM_LDFLAGS}")
-  fi
+    if [[ -n "${CXX:-}" ]]; then
+      export "CXX=${CXX}"
+    fi
+
+    if [[ -n "${LDFLAGS:-}" ]]; then
+      export "LDFLAGS=${LLVM_LDFLAGS}"
+    fi
 
-  if [[ -n "${variables[*]}" ]]; then
-    "${variables[*]}" cmake "${CONFIG[@]}" "${LLVM_SRC_BASE}/llvm"
-  else
     cmake "${CONFIG[@]}" "${LLVM_SRC_BASE}/llvm"
-  fi
+  )
+}
+build_llvm() {
+  configure_llvm
+  (
+    if [[ "${SANITIZER_BUILD}" == "memory" ]]; then
+      ninja clang|| return 1
+      return 0
+    fi
+
+    if [[ -n "${CC:-}" ]]; then
+      export "CC=${CC}"
+    fi
+
+    if [[ -n "${CXX:-}" ]]; then
+      export "CXX=${CXX}"
+    fi
 
-  # Linking LLVM can require a lot of memory.
-  # First try multicore - if that doesn't work, try single core
-  (make "-j$(nproc)") || (make) || return 1
+    if [[ -n "${LDFLAGS:-}" ]]; then
+      export "LDFLAGS=${LLVM_LDFLAGS}"
+    fi
+
+    # Linking LLVM can require a lot of memory.
+    # First try multicore - if that doesn't work, try single core
+    (make "-j$(nproc)") || (make) || return 1
+  ) || return 1
   touch "${LLVM_BUILD}/.build_finished"
 }
 
@@ -254,24 +276,25 @@ install_llvm() {
     make "-j$(nproc)" install
     cp "${LLVM_BUILD_BIN}/FileCheck" "${LLVM_INSTALL}/bin/"
     cp "${LLVM_BUILD_BIN}/not" "${LLVM_INSTALL}/bin/"
-  
+
     # Remove debug information from binaries
     strip "${LLVM_INSTALL}/bin/"* || /bin/true
     strip "${LLVM_INSTALL}/lib/libclang"* || /bin/true
     strip "${LLVM_INSTALL}/lib/libLTO"* || /bin/true
   else
     # Handle memory sanitizer install
-    LLVM_PACKAGES=( \
+    LLVM_PACKAGES=(
       install-clang install-llvm-config install-llvm-objdump
       install-llvm-link install-llvm-ar install-llvm-nm install-llvm-dis
       install-clang-headers install-llvm-as
       install-llvm-symbolizer install-LLVMSupport install-lli not FileCheck
-      install-llvm-headers )
-  
+      install-llvm-headers
+      )
+
     ninja "${LLVM_PACKAGES[@]}"
 
-    for i in $(ninja -t targets |grep install-LLVM | cut -d : -f 1); do ninja "$i"; done
-    
+    for i in $(ninja -t targets | grep install-LLVM | cut -d : -f 1); do ninja "$i"; done
+
     cp "${LLVM_BUILD}/bin/FileCheck" "${LLVM_INSTALL}/bin/"
     cp "${LLVM_BUILD}/bin/not" "${LLVM_INSTALL}/bin/"
   fi
diff --git a/scripts/build/p-sanitizer-linux-ubuntu.inc b/scripts/build/p-sanitizer-linux-ubuntu.inc
new file mode 100644
index 00000000..bb6187ea
--- /dev/null
+++ b/scripts/build/p-sanitizer-linux-ubuntu.inc
@@ -0,0 +1,46 @@
+install_binary_artifact_sanitizer() {
+  if [[ -z "${SANITIZER_BUILD:=}" ]]; then
+    return 1
+  fi
+
+  source "${DIR}/common-functions"
+  local SANITIZER_LLVM_VERSION_MAJOR="${SANITIZER_LLVM_VERSION/.*/}"
+  local SANITIZER_LLVM_VERSION_MINOR="${SANITIZER_LLVM_VERSION/*./}"
+
+  local version=""
+  [[ "${SANITIZER_LLVM_VERSION_MAJOR}" -le 6 ]] && version="-${SANITIZER_LLVM_VERSION}"
+  [[ "${SANITIZER_LLVM_VERSION_MAJOR}" -ge 7 ]] && version="-${SANITIZER_LLVM_VERSION_MAJOR}"
+
+  # Add certificate
+  with_sudo apt update -y
+  dependencies=(
+    ca-certificates
+    wget
+    lsb-release
+    gnupg
+  )
+
+  with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
+  wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | with_sudo apt-key add -
+
+  # Add repository
+  codename="$(lsb_release --codename --short)"
+  apt_entry="deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}${version} main"
+  if [[ ! $(grep -rq "${apt_entry}" /etc/apt) ]]; then
+    echo "${apt_entry}" | with_sudo tee -a /etc/apt/sources.list
+    with_sudo apt update -y
+  fi
+
+  with_sudo apt update -y
+  dependencies=(
+    "llvm${version}"
+    "clang${version}"
+  )
+
+  #Install essential dependencies
+  with_sudo apt -y --no-install-recommends install "${dependencies[@]}" || return 1
+}
+
+get_docker_config_id_sanitizer() {
+  return 0
+}
diff --git a/scripts/build/p-sanitizer-linux.inc b/scripts/build/p-sanitizer-linux.inc
new file mode 100644
index 00000000..b7a7718e
--- /dev/null
+++ b/scripts/build/p-sanitizer-linux.inc
@@ -0,0 +1,42 @@
+setup_artifact_variables_sanitizer() {
+  local SANITIZER_LLVM_VERSION_MAJOR="${SANITIZER_LLVM_VERSION/.*/}"
+  local SANITIZER_LLVM_VERSION_MINOR="${SANITIZER_LLVM_VERSION/*./}"
+  local version=""
+  [[ "${SANITIZER_LLVM_VERSION_MAJOR}" -le 6 ]] && version="-${SANITIZER_LLVM_VERSION}"
+  [[ "${SANITIZER_LLVM_VERSION_MAJOR}" -ge 7 ]] && version="-${SANITIZER_LLVM_VERSION_MAJOR}"
+
+  # Only set LLVM_CONFIG if not set yet
+  if [[ -z "${SANITIZER_LLVM_CONFIG-}" ]]; then
+    SANITIZER_LLVM_CONFIG=$(which "llvm-config${version}")
+  fi
+
+
+  local bin_path=""
+  bin_path="$(dirname "$(readlink -f "$(which "clang${version}")")")"
+
+  SANITIZER_BITCODE_CC="${bin_path}/clang"
+  SANITIZER_BITCODE_CXX="${bin_path}/clang++"
+
+  if [[ -z ${SANITIZER_C_COMPILER:=} ]]; then
+    SANITIZER_C_COMPILER="${SANITIZER_BITCODE_CC}"
+  fi
+
+  if [[ -z ${SANITIZER_CXX_COMPILER:=} ]]; then
+    SANITIZER_CXX_COMPILER="${SANITIZER_BITCODE_CXX}"
+  fi
+}
+
+# Check if the binary artifact is installed
+is_installed_sanitizer() {
+  if [[ -z ${SANITIZER_BUILD:-} ]]; then
+   return 1
+  fi
+  local SANITIZER_LLVM_VERSION_MAJOR="${SANITIZER_LLVM_VERSION/.*/}"
+  local SANITIZER_LLVM_VERSION_MINOR="${SANITIZER_LLVM_VERSION/*./}"
+  local version=""
+  [[ "${SANITIZER_LLVM_VERSION_MAJOR}" -le 6 ]] && version="${SANITIZER_LLVM_VERSION}"
+  [[ "${SANITIZER_LLVM_VERSION_MAJOR}" -ge 7 ]] && version="${SANITIZER_LLVM_VERSION_MAJOR}"
+
+  # Check if clang with the right version exists
+  which "clang-${version}"
+}
\ No newline at end of file
diff --git a/scripts/build/v-sanitizer.inc b/scripts/build/v-sanitizer.inc
index 895ffd21..b86ef23f 100644
--- a/scripts/build/v-sanitizer.inc
+++ b/scripts/build/v-sanitizer.inc
@@ -1,15 +1,20 @@
-#!/bin/bash
 # Variables for sanitizer handling
-
-required_variables_sanitizer=(
-  "SANITIZER_BUILD"
-)
+required_variables_sanitizer(){
+ if [[ -z ${SANITIZER_BUILD:-} ]]; then
+   return 0
+ fi
+ echo "SANITIZER_BUILD"
+ echo "SANITIZER_LLVM_VERSION"
+}
 
 artifact_dependency_sanitizer=("")
 
 required_variables_check_sanitizer() {
-  # Allowe empty sanitizer builds
-  [[ -z "${SANITIZER_BUILD}" ]] && return 0
+  # Allow empty sanitizer builds
+  if [[ -z ${SANITIZER_BUILD:-} ]]; then
+    SANITIZER_BUILD=""
+    return 0
+  fi
   
   local sanitizers
   IFS=":" read -r -a sanitizers <<< "${SANITIZER_BUILD}"
@@ -25,7 +30,7 @@ required_variables_check_sanitizer() {
 }
 
 setup_variables_sanitizer() {
-  if [[ -z "${SANITIZER_BUILD}" ]]; then
+  if [[ -z "${SANITIZER_BUILD:-}" ]]; then
     SANITIZERS=("")
     SANITIZER_SUFFIX=""
     return 0
@@ -89,4 +94,4 @@ setup_variables_sanitizer() {
     echo "Unknown sanitizer: $sanitizer"
     exit 1
   done
-  }
+}
diff --git a/scripts/build/v-sqlite.inc b/scripts/build/v-sqlite.inc
index 594912a6..366f442f 100644
--- a/scripts/build/v-sqlite.inc
+++ b/scripts/build/v-sqlite.inc
@@ -1,3 +1,3 @@
-artifact_dependency_sqlite=("sanitizer_compiler")
+artifact_dependency_sqlite=("sanitizer")
 
 required_variables_sqlite=("")
diff --git a/scripts/build/v-stp.inc b/scripts/build/v-stp.inc
index 9bbc28f1..0885a3d1 100644
--- a/scripts/build/v-stp.inc
+++ b/scripts/build/v-stp.inc
@@ -5,4 +5,4 @@ required_variables_stp=(
 )
 
 # On which artifacts does STP depend on
-artifact_dependency_stp=("sanitizer_compiler")
\ No newline at end of file
+artifact_dependency_stp=("sanitizer")
\ No newline at end of file
diff --git a/scripts/build/v-z3.inc b/scripts/build/v-z3.inc
index 915336a3..92e68658 100644
--- a/scripts/build/v-z3.inc
+++ b/scripts/build/v-z3.inc
@@ -4,4 +4,4 @@ required_variables_z3=(
 )
 
 # Artifacts Z3 depends on
-artifact_dependency_z3=("sanitizer_compiler")
\ No newline at end of file
+artifact_dependency_z3=("sanitizer")
\ No newline at end of file