Skip to content

Commit 71da576

Browse files
lucascolleyisuruf
andcommitted
gh-155375: -shared-libsan for linux ASAN builds
[skip ci] Co-authored-by: Isuru Fernando <isuruf@gmail.com>
1 parent 5e0c502 commit 71da576

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎Tools/pixi-packages/build.sh‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ if [[ "${PYTHON_VARIANT}" == "freethreading" ]]; then
77
elif [[ "${PYTHON_VARIANT}" == "asan" ]]; then
88
CONFIGURE_EXTRA="--with-address-sanitizer"
99
export ASAN_OPTIONS="strict_init_order=true"
10+
if [[ "$target_platform" == linux-* && "$c_compiler" == "clang" ]]; then
11+
export LDFLAGS="-shared-libsan $LDFLAGS"
12+
# with -shared-libsan, conftest/python binaries link the ASan runtime
13+
# dynamically; it lives under $BUILD_PREFIX (from the clang build
14+
# dependency), not $PREFIX, so the loader can't find it without this.
15+
export LD_LIBRARY_PATH="${BUILD_PREFIX}/lib:${LD_LIBRARY_PATH}"
16+
fi
1017
elif [[ "${PYTHON_VARIANT}" == "tsan_freethreading" ]]; then
1118
CONFIGURE_EXTRA="--disable-gil --with-thread-sanitizer"
1219
export TSAN_OPTIONS="suppressions=${SRC_DIR}/Tools/tsan/suppressions_free_threading.txt"
@@ -58,3 +65,12 @@ touch configure-done
5865

5966
make -j"${CPU_COUNT}" install
6067
ln -sf "${PREFIX}/bin/python3" "${PREFIX}/bin/python"
68+
69+
if [[ "${PYTHON_VARIANT}" == "asan" && "$target_platform" == linux-* && "$c_compiler" == "clang" ]]; then
70+
# python is linked with -shared-libsan, so it (and anything invoking it,
71+
# e.g. numpy's build) needs the ASan runtime findable at load time.
72+
# Ship it in $PREFIX/lib: python's own rpath already points there, and
73+
# that rpath gets relocated to wherever this package is installed, so no
74+
# LD_LIBRARY_PATH is needed downstream.
75+
cp "${BUILD_PREFIX}"/lib/libclang_rt.asan-*.so "${PREFIX}/lib/"
76+
fi

0 commit comments

Comments
 (0)