Skip to content

Commit ed3a469

Browse files
committed
asan: replace used python in mlir lit.cfg with shim script
1 parent 3787844 commit ed3a469

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

mlir/test/lit.cfg.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,19 @@ def add_runtime(name):
177177
# Python configuration with sanitizer requires some magic preloading. This will only work on clang/linux.
178178
# TODO: detect Darwin/Windows situation (or mark these tests as unsupported on these platforms).
179179
if "asan" in config.available_features and "Linux" in config.host_os:
180-
python_executable = f"LD_PRELOAD=$({config.host_cxx} -print-file-name=libclang_rt.asan-{config.host_arch}.so) {config.python_executable}"
180+
# Write shim script that preloads the necessary shared object for ASAN tests. Fallback to such script for two reasons:
181+
#
182+
# (1) Provide full support for LLVM's test utils like `not`, which are prepended to the original statement containing the `LD_PRELOAD` env definition.
183+
# Having environment definitions in the middle of a command line is syntactically illegal.
184+
# (2) Mitigate issues with LIT's internal shell that puts single quotes around the environment definition,
185+
# which leads to malformed command lines:
186+
# `LD_PRELOAD=$(/usr/bin/clang++-17' '-print-file-name=libclang_rt.asan-x86_64.so)' python (...)`
187+
with open("python-asan-shim", "w") as file:
188+
file.write(
189+
f"#!/usr/bin/env bash\nLD_PRELOAD=$({config.host_cxx} -print-file-name=libclang_rt.asan-{config.host_arch}.so) {python_executable} $@\n"
190+
)
191+
os.chmod(os.path.abspath("python-asan-shim"), 0o700)
192+
python_executable = os.path.abspath("python-asan-shim")
181193
# On Windows the path to python could contains spaces in which case it needs to be provided in quotes.
182194
# This is the equivalent of how %python is setup in llvm/utils/lit/lit/llvm/config.py.
183195
elif "Windows" in config.host_os:

0 commit comments

Comments
 (0)