From ca3d9b08fbc3b39afe91526391d2cec9bce4ab6a Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Mon, 4 Oct 2021 12:07:05 -0700 Subject: [PATCH] CI: add TSAN to the sanitizers pipelines (#42444) (cherry picked from commit f985b47df75dbe4522b7befe172dd8c251ffa4a9) --- .buildkite/pipelines/main/misc/sanitizers.yml | 20 ++++++ contrib/tsan/Make.user.tsan | 16 +++++ contrib/tsan/build.sh | 61 +++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 contrib/tsan/Make.user.tsan create mode 100755 contrib/tsan/build.sh diff --git a/.buildkite/pipelines/main/misc/sanitizers.yml b/.buildkite/pipelines/main/misc/sanitizers.yml index f586881917f0a..43beb05807a8e 100644 --- a/.buildkite/pipelines/main/misc/sanitizers.yml +++ b/.buildkite/pipelines/main/misc/sanitizers.yml @@ -25,3 +25,23 @@ steps: commands: | echo "--- Build julia-debug with ASAN" contrib/asan/build.sh ./tmp/test-asan -j$${JULIA_CPU_THREADS:?} debug + - label: "tsan" + key: "tsan" + plugins: + - JuliaCI/julia#v1: + # Drop default "registries" directory, so it is not persisted from execution to execution + persist_depot_dirs: packages,artifacts,compiled + version: '1.6' + - staticfloat/sandbox#v1: + rootfs_url: https://github.com/JuliaCI/rootfs-images/releases/download/v3.1/llvm_passes.x86_64.tar.gz + rootfs_treehash: "9dd715500b117a16fcfa419ea0bca0c0ca902cee" + uid: 1000 + gid: 1000 + workspaces: + - "/cache/repos:/cache/repos" + timeout_in_minutes: 120 + if: | # We only run the `tsan` job on Julia 1.8 and later. + (pipeline.slug != "julia-release-1-dot-6") && (pipeline.slug != "julia-release-1-dot-7") + commands: | + echo "--- Build julia-debug runtime with TSAN" + contrib/tsan/build.sh ./tmp/test-tsan -j$${JULIA_CPU_THREADS:?} julia-src-debug diff --git a/contrib/tsan/Make.user.tsan b/contrib/tsan/Make.user.tsan new file mode 100644 index 0000000000000..3773832aafeb8 --- /dev/null +++ b/contrib/tsan/Make.user.tsan @@ -0,0 +1,16 @@ +TOOLCHAIN=$(BUILDROOT)/../toolchain +BINDIR=$(TOOLCHAIN)/usr/bin +TOOLDIR=$(TOOLCHAIN)/usr/tools + +# use our new toolchain +USECLANG=1 +override CC=$(BINDIR)/clang +override CXX=$(TOOLDIR)/clang++ + +USE_BINARYBUILDER_LLVM=1 + +override SANITIZE=1 +override SANITIZE_THREAD=1 + +# default to a debug build for better line number reporting +override JULIA_BUILD_MODE=debug diff --git a/contrib/tsan/build.sh b/contrib/tsan/build.sh new file mode 100755 index 0000000000000..67956d2dcaa68 --- /dev/null +++ b/contrib/tsan/build.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# This file is a part of Julia. License is MIT: https://julialang.org/license + +# +# Usage: +# contrib/tsan/build.sh [...] +# +# Build TSAN-enabled julia. Given a workspace directory , build +# TSAN-enabled julia in /tsan. Required toolss are install under +# /toolchain. Note that the same passed to `contrib/asan/build.sh` +# can be used to share the toolchain used for ASAN. This scripts also takes +# optional arguments which are passed to `make`. The default +# make target is `debug`. + +set -ue + +# `$WORKSPACE` is a directory in which we create `toolchain` and `tsan` +# sub-directories. +WORKSPACE="$1" +shift +if [ "$WORKSPACE" = "" ]; then + echo "Workspace directory must be specified as the first argument" >&2 + exit 2 +fi + +mkdir -pv "$WORKSPACE" +WORKSPACE="$(cd "$WORKSPACE" && pwd)" +if [ "$WORKSPACE" = "" ]; then + echo "Failed to create the workspace directory." >&2 + exit 2 +fi + +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +JULIA_HOME="$HERE/../../" + +echo +echo "Installing toolchain..." + +TOOLCHAIN="$WORKSPACE/toolchain" +if [ ! -d "$TOOLCHAIN" ]; then + make -C "$JULIA_HOME" configure O=$TOOLCHAIN + cp "$HERE/../asan/Make.user.tools" "$TOOLCHAIN/Make.user" +fi + +make -C "$TOOLCHAIN/deps" install-clang install-llvm-tools + +# TODO: https://github.com/JuliaPackaging/Yggdrasil/issues/3359 +rm "$TOOLCHAIN/usr/tools/clang++" +ln -s "$TOOLCHAIN/usr/bin/clang" "$TOOLCHAIN/usr/tools/clang++" + +echo +echo "Building Julia..." + +BUILD="$WORKSPACE/tsan" +if [ ! -d "$BUILD" ]; then + make -C "$JULIA_HOME" configure O="$BUILD" + cp "$HERE/Make.user.tsan" "$BUILD/Make.user" +fi + +cd "$BUILD" # so that we can pass `-C src` to `make` +make "$@"