Skip to content

Commit d344624

Browse files
MLIR: asan: Fix python tests under asan on Linux (llvm#123303)
Running MLIR python tests unders asan currently fails with ``` executed command: 'LD_PRELOAD=$(/usr/bin/clang++-17' '-print-file-name=libclang_rt.asan-x86_64.so)' /scratch/slx-llvm/.venv-3.10/bin/python3.10 /scratch/slx-llvm/mlir/test/python/ir/context_lifecycle.py | 'LD_PRELOAD=$(/usr/bin/clang++-17': command not found ``` because lit doesn't quite understand the syntax. To fix, we resolve the path to `libclang_rt.asan-x86_64.so` within the lit configuration. This has the additional benefit that we don't have to call `clang++` for every test. Co-authored-by: Philipp-Jan Honysz <[email protected]>
1 parent 2ec2784 commit d344624

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

mlir/test/lit.cfg.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,32 @@ def add_runtime(name):
8282
# available. This is darwin specific since it's currently only needed on darwin.
8383
# Stolen from llvm/test/lit.cfg.py with a few modifications
8484
def get_asan_rtlib():
85-
if not "asan" in config.available_features or not "Darwin" in config.host_os:
85+
if not "asan" in config.available_features:
8686
return ""
87-
# Find the asan rt lib
88-
resource_dir = (
89-
subprocess.check_output([config.host_cc.strip(), "-print-resource-dir"])
90-
.decode("utf-8")
91-
.strip()
92-
)
93-
return os.path.join(
94-
resource_dir, "lib", "darwin", "libclang_rt.asan_osx_dynamic.dylib"
95-
)
87+
88+
if "Darwin" in config.host_os:
89+
# Find the asan rt lib
90+
resource_dir = (
91+
subprocess.check_output([config.host_cc.strip(), "-print-resource-dir"])
92+
.decode("utf-8")
93+
.strip()
94+
)
95+
return os.path.join(
96+
resource_dir, "lib", "darwin", "libclang_rt.asan_osx_dynamic.dylib"
97+
)
98+
if "Linux" in config.host_os:
99+
return (
100+
subprocess.check_output(
101+
[
102+
config.host_cxx.strip(),
103+
f"-print-file-name=libclang_rt.asan-{config.host_arch}.so",
104+
]
105+
)
106+
.decode("utf-8")
107+
.strip()
108+
)
109+
110+
return ""
96111

97112

98113
# On macOS, we can't do the DYLD_INSERT_LIBRARIES trick with a shim python
@@ -247,7 +262,9 @@ def find_real_python_interpreter():
247262
# TODO: detect Windows situation (or mark these tests as unsupported on these platforms).
248263
if "asan" in config.available_features:
249264
if "Linux" in config.host_os:
250-
python_executable = f"LD_PRELOAD=$({config.host_cxx} -print-file-name=libclang_rt.asan-{config.host_arch}.so) {config.python_executable}"
265+
python_executable = (
266+
f"env LD_PRELOAD={get_asan_rtlib()} {config.python_executable}"
267+
)
251268
if "Darwin" in config.host_os:
252269
# Ensure we use a non-shim Python executable, for the `DYLD_INSERT_LIBRARIES`
253270
# env variable to take effect

0 commit comments

Comments
 (0)