Skip to content

Commit a166f95

Browse files
committed
pythongh-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 4766237 commit a166f95

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

.github/workflows/reusable-san.yml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@ jobs:
2323
&& ' (free-threading)'
2424
|| ''
2525
}}
26-
runs-on: ubuntu-24.04
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
os: [ubuntu-24.04]
30+
openssl_ver: [3.5.4]
31+
runs-on: ${{ matrix.os }}
2732
timeout-minutes: 60
33+
env:
34+
OPENSSL_VER: ${{ matrix.openssl_ver }}
35+
MULTISSL_DIR: ${{ github.workspace }}/multissl
36+
OPENSSL_DIR: ${{ github.workspace }}/multissl/openssl/${{ matrix.openssl_ver }}
2837
steps:
2938
- uses: actions/checkout@v4
3039
with:
@@ -37,17 +46,16 @@ jobs:
3746
# Install clang
3847
wget https://apt.llvm.org/llvm.sh
3948
chmod +x llvm.sh
40-
41-
if [ "${SANITIZER}" = "TSan" ]; then
42-
sudo ./llvm.sh 17 # gh-121946: llvm-18 package is temporarily broken
43-
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 100
44-
sudo update-alternatives --set clang /usr/bin/clang-17
45-
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 100
46-
sudo update-alternatives --set clang++ /usr/bin/clang++-17
49+
sudo ./llvm.sh 20
50+
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-20 100
51+
sudo update-alternatives --set clang /usr/bin/clang-20
52+
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-20 100
53+
sudo update-alternatives --set clang++ /usr/bin/clang++-20
54+
sudo update-alternatives --install /usr/bin/llvm-symbolizer llvm-symbolizer /usr/bin/llvm-symbolizer-20 100
55+
sudo update-alternatives --set llvm-symbolizer /usr/bin/llvm-symbolizer-20
56+
if [ "${{ inputs.sanitizer }}" = "TSan" ]; then
4757
# Reduce ASLR to avoid TSan crashing
4858
sudo sysctl -w vm.mmap_rnd_bits=28
49-
else
50-
sudo ./llvm.sh 20
5159
fi
5260
5361
- name: Sanitizer option setup
@@ -69,6 +77,16 @@ jobs:
6977
- name: Add ccache to PATH
7078
run: |
7179
echo "PATH=/usr/lib/ccache:$PATH" >> "$GITHUB_ENV"
80+
- name: 'Restore OpenSSL build (TSan)'
81+
id: cache-openssl
82+
uses: actions/cache@v4
83+
if: inputs.sanitizer == 'TSan'
84+
with:
85+
path: ./multissl/openssl/${{ env.OPENSSL_VER }}
86+
key: ${{ matrix.os }}-multissl-openssl-tsan-${{ env.OPENSSL_VER }}
87+
- name: Install OpenSSL (TSan)
88+
if: steps.cache-openssl.outputs.cache-hit != 'true' && inputs.sanitizer == 'TSan'
89+
run: python3 Tools/ssl/multissltests.py --steps=library --base-directory "$MULTISSL_DIR" --openssl "$OPENSSL_VER" --system Linux --tsan
7290
- name: Configure CPython
7391
run: >-
7492
./configure
@@ -79,6 +97,7 @@ jobs:
7997
|| '--with-undefined-behavior-sanitizer'
8098
}}
8199
--with-pydebug
100+
${{ inputs.sanitizer == 'TSan' && ' --with-openssl="$OPENSSL_DIR" --with-openssl-rpath=auto' || '' }}
82101
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
83102
- name: Build CPython
84103
run: make -j4

Tools/ssl/multissltests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@
158158
dest='keep_sources',
159159
help="Keep original sources for debugging."
160160
)
161+
parser.add_argument(
162+
'--tsan',
163+
action='store_true',
164+
dest='tsan',
165+
help="Build with thread sanitizer. (Disables fips in OpenSSL 3.x)."
166+
)
161167

162168

163169
class AbstractBuilder(object):
@@ -312,6 +318,8 @@ def _build_src(self, config_args=()):
312318
"""Now build openssl"""
313319
log.info("Running build in {}".format(self.build_dir))
314320
cwd = self.build_dir
321+
if self.args.tsan:
322+
config_args += ("-fsanitize=thread",)
315323
cmd = [
316324
"./config", *config_args,
317325
"shared", "--debug",

0 commit comments

Comments
 (0)