Skip to content

Commit f985b47

Browse files
authored
CI: add TSAN to the sanitizers pipelines (#42444)
1 parent 923ddb7 commit f985b47

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

.buildkite/pipelines/main/misc/sanitizers.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,23 @@ steps:
2424
commands: |
2525
echo "--- Build julia-debug with ASAN"
2626
contrib/asan/build.sh ./tmp/test-asan -j$${JULIA_CPU_THREADS:?} debug
27+
- label: "tsan"
28+
key: "tsan"
29+
plugins:
30+
- JuliaCI/julia#v1:
31+
# Drop default "registries" directory, so it is not persisted from execution to execution
32+
persist_depot_dirs: packages,artifacts,compiled
33+
version: '1.6'
34+
- staticfloat/sandbox#v1:
35+
rootfs_url: https://github.com/JuliaCI/rootfs-images/releases/download/v3.1/llvm_passes.x86_64.tar.gz
36+
rootfs_treehash: "9dd715500b117a16fcfa419ea0bca0c0ca902cee"
37+
uid: 1000
38+
gid: 1000
39+
workspaces:
40+
- "/cache/repos:/cache/repos"
41+
timeout_in_minutes: 120
42+
if: | # We only run the `tsan` job on Julia 1.8 and later.
43+
(pipeline.slug != "julia-release-1-dot-6") && (pipeline.slug != "julia-release-1-dot-7")
44+
commands: |
45+
echo "--- Build julia-debug runtime with TSAN"
46+
contrib/tsan/build.sh ./tmp/test-tsan -j$${JULIA_CPU_THREADS:?} julia-src-debug

contrib/tsan/Make.user.tsan

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
TOOLCHAIN=$(BUILDROOT)/../toolchain
2+
BINDIR=$(TOOLCHAIN)/usr/bin
3+
TOOLDIR=$(TOOLCHAIN)/usr/tools
4+
5+
# use our new toolchain
6+
USECLANG=1
7+
override CC=$(BINDIR)/clang
8+
override CXX=$(TOOLDIR)/clang++
9+
10+
USE_BINARYBUILDER_LLVM=1
11+
12+
override SANITIZE=1
13+
override SANITIZE_THREAD=1
14+
15+
# default to a debug build for better line number reporting
16+
override JULIA_BUILD_MODE=debug

contrib/tsan/build.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# This file is a part of Julia. License is MIT: https://julialang.org/license
3+
4+
#
5+
# Usage:
6+
# contrib/tsan/build.sh <path> [<make_targets>...]
7+
#
8+
# Build TSAN-enabled julia. Given a workspace directory <path>, build
9+
# TSAN-enabled julia in <path>/tsan. Required toolss are install under
10+
# <path>/toolchain. Note that the same <path> passed to `contrib/asan/build.sh`
11+
# can be used to share the toolchain used for ASAN. This scripts also takes
12+
# optional <make_targets> arguments which are passed to `make`. The default
13+
# make target is `debug`.
14+
15+
set -ue
16+
17+
# `$WORKSPACE` is a directory in which we create `toolchain` and `tsan`
18+
# sub-directories.
19+
WORKSPACE="$1"
20+
shift
21+
if [ "$WORKSPACE" = "" ]; then
22+
echo "Workspace directory must be specified as the first argument" >&2
23+
exit 2
24+
fi
25+
26+
mkdir -pv "$WORKSPACE"
27+
WORKSPACE="$(cd "$WORKSPACE" && pwd)"
28+
if [ "$WORKSPACE" = "" ]; then
29+
echo "Failed to create the workspace directory." >&2
30+
exit 2
31+
fi
32+
33+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
34+
JULIA_HOME="$HERE/../../"
35+
36+
echo
37+
echo "Installing toolchain..."
38+
39+
TOOLCHAIN="$WORKSPACE/toolchain"
40+
if [ ! -d "$TOOLCHAIN" ]; then
41+
make -C "$JULIA_HOME" configure O=$TOOLCHAIN
42+
cp "$HERE/../asan/Make.user.tools" "$TOOLCHAIN/Make.user"
43+
fi
44+
45+
make -C "$TOOLCHAIN/deps" install-clang install-llvm-tools
46+
47+
# TODO: https://github.com/JuliaPackaging/Yggdrasil/issues/3359
48+
rm "$TOOLCHAIN/usr/tools/clang++"
49+
ln -s "$TOOLCHAIN/usr/bin/clang" "$TOOLCHAIN/usr/tools/clang++"
50+
51+
echo
52+
echo "Building Julia..."
53+
54+
BUILD="$WORKSPACE/tsan"
55+
if [ ! -d "$BUILD" ]; then
56+
make -C "$JULIA_HOME" configure O="$BUILD"
57+
cp "$HERE/Make.user.tsan" "$BUILD/Make.user"
58+
fi
59+
60+
cd "$BUILD" # so that we can pass `-C src` to `make`
61+
make "$@"

0 commit comments

Comments
 (0)