Skip to content

Commit 0bb32bf

Browse files
committed
replace shim script with env+prefound asan so
1 parent ed3a469 commit 0bb32bf

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

mlir/test/lit.cfg.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ def find_runtime(name):
7070
break
7171
return path
7272

73+
# Find path to the ASan runtime required for the Python interpreter.
74+
def find_asan_runtime():
75+
if not "asan" in config.available_features or not "Linux" in config.host_os:
76+
return ""
77+
# Find the asan rt lib
78+
return (
79+
subprocess.check_output([config.host_cxx.strip(), f"-print-file-name=libclang_rt.asan-{config.host_arch}.so"])
80+
.decode("utf-8")
81+
.strip()
82+
)
7383

7484
# Searches for a runtime library with the given name and returns a tool
7585
# substitution of the same name and the found path.
@@ -177,19 +187,8 @@ def add_runtime(name):
177187
# Python configuration with sanitizer requires some magic preloading. This will only work on clang/linux.
178188
# TODO: detect Darwin/Windows situation (or mark these tests as unsupported on these platforms).
179189
if "asan" in config.available_features and "Linux" in config.host_os:
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")
190+
_asan_rt = find_asan_runtime()
191+
python_executable = f"env LD_PRELOAD={_asan_rt} {config.python_executable}"
193192
# On Windows the path to python could contains spaces in which case it needs to be provided in quotes.
194193
# This is the equivalent of how %python is setup in llvm/utils/lit/lit/llvm/config.py.
195194
elif "Windows" in config.host_os:

0 commit comments

Comments
 (0)