Skip to content

Commit 06b4de4

Browse files
colesburykumaraditya303
authored andcommitted
gh-143750: Compile OpenSSL with TSan for TSan CI
- Also fix "Install dependencies" step so that we use the installed Clang. We can use clang-20 on both ASan and TSan now.
1 parent 1051384 commit 06b4de4

2 files changed

Lines changed: 42 additions & 18 deletions

File tree

.github/workflows/reusable-san.yml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
}}
2929
runs-on: ubuntu-26.04
3030
timeout-minutes: 60
31+
env:
32+
OPENSSL_VER: 3.5.4
3133
steps:
3234
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
3335
with:
@@ -38,28 +40,41 @@ jobs:
3840
run: |
3941
sudo ./.github/workflows/posix-deps-apt.sh
4042
# On ubuntu-26.04 image, clang is clang-21 by default
41-
42-
if [ "${SANITIZER}" = "TSan" ]; then
43-
# Reduce ASLR to avoid TSan crashing
44-
sudo sysctl -w vm.mmap_rnd_bits=28
45-
fi
46-
47-
- name: Sanitizer option setup
48-
run: |
49-
if [ "${SANITIZER}" = "TSan" ]; then
50-
echo "TSAN_OPTIONS=${SAN_LOG_OPTION} suppressions=${GITHUB_WORKSPACE}/Tools/tsan/suppressions${{
51-
fromJSON(inputs.free-threading)
52-
&& '_free_threading'
53-
|| ''
54-
}}.txt handle_segv=0" >> "$GITHUB_ENV"
55-
else
56-
echo "UBSAN_OPTIONS=${SAN_LOG_OPTION} halt_on_error=1 suppressions=${GITHUB_WORKSPACE}/Tools/ubsan/suppressions.txt" >> "$GITHUB_ENV"
57-
fi
5843
echo "CC=clang" >> "$GITHUB_ENV"
5944
echo "CXX=clang++" >> "$GITHUB_ENV"
45+
- name: TSan option setup
46+
if: inputs.sanitizer == 'TSan'
47+
run: |
48+
# Reduce ASLR to avoid TSan crashing
49+
sudo sysctl -w vm.mmap_rnd_bits=28
50+
echo "MULTISSL_DIR=${GITHUB_WORKSPACE}/multissl" >> "$GITHUB_ENV"
51+
echo "OPENSSL_DIR=${GITHUB_WORKSPACE}/multissl/openssl/${OPENSSL_VER}" >> "$GITHUB_ENV"
52+
echo "TSAN_OPTIONS=${SAN_LOG_OPTION} suppressions=${GITHUB_WORKSPACE}/Tools/tsan/suppressions${{
53+
fromJSON(inputs.free-threading)
54+
&& '_free_threading'
55+
|| ''
56+
}}.txt handle_segv=0" >> "$GITHUB_ENV"
6057
env:
61-
SANITIZER: ${{ inputs.sanitizer }}
6258
SAN_LOG_OPTION: log_path=${{ github.workspace }}/san_log
59+
- name: UBSan option setup
60+
if: inputs.sanitizer != 'TSan'
61+
run: |
62+
echo "UBSAN_OPTIONS=${SAN_LOG_OPTION} halt_on_error=1 suppressions=${GITHUB_WORKSPACE}/Tools/ubsan/suppressions.txt" >> "$GITHUB_ENV"
63+
env:
64+
SAN_LOG_OPTION: log_path=${{ github.workspace }}/san_log
65+
- name: Add ccache to PATH
66+
run: |
67+
echo "PATH=/usr/lib/ccache:$PATH" >> "$GITHUB_ENV"
68+
- name: 'Restore OpenSSL build (TSan)'
69+
id: cache-openssl
70+
if: inputs.sanitizer == 'TSan'
71+
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
72+
with:
73+
path: ./multissl/openssl/${{ env.OPENSSL_VER }}
74+
key: ${{ env.IMAGE_OS_VERSION }}-multissl-openssl-tsan-${{ env.OPENSSL_VER }}
75+
- name: Install OpenSSL (TSan)
76+
if: steps.cache-openssl.outputs.cache-hit != 'true' && inputs.sanitizer == 'TSan'
77+
run: python3 Tools/ssl/multissltests.py --steps=library --base-directory "$MULTISSL_DIR" --openssl "$OPENSSL_VER" --system Linux --tsan
6378
- name: Configure CPython
6479
run: >-
6580
./configure
@@ -70,6 +85,7 @@ jobs:
7085
|| '--with-undefined-behavior-sanitizer --with-strict-overflow'
7186
}}
7287
--with-pydebug
88+
${{ inputs.sanitizer == 'TSan' && '--with-openssl="$OPENSSL_DIR" --with-openssl-rpath=auto' || '' }}
7389
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
7490
- name: Build CPython
7591
run: make -j4

Tools/ssl/multissltests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@
163163
dest='keep_sources',
164164
help="Keep original sources for debugging."
165165
)
166+
parser.add_argument(
167+
'--tsan',
168+
action='store_true',
169+
dest='tsan',
170+
help="Build with thread sanitizer. (Disables fips in OpenSSL 3.x)."
171+
)
166172

167173

168174
class AbstractBuilder(object):
@@ -317,6 +323,8 @@ def _build_src(self, config_args=()):
317323
"""Now build openssl"""
318324
log.info("Running build in {}".format(self.build_dir))
319325
cwd = self.build_dir
326+
if self.args.tsan:
327+
config_args += ("-fsanitize=thread",)
320328
cmd = [
321329
"./config", *config_args,
322330
"shared", "--debug",

0 commit comments

Comments
 (0)