[Mlir-commits] [mlir] d344624 - MLIR: asan: Fix python tests under asan on Linux (#123303)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Jan 28 23:36:16 PST 2025
Author: Matthias Gehre
Date: 2025-01-29T08:36:13+01:00
New Revision: d34462409757731e158909250d2a4be4f9d2de80
URL: https://github.com/llvm/llvm-project/commit/d34462409757731e158909250d2a4be4f9d2de80
DIFF: https://github.com/llvm/llvm-project/commit/d34462409757731e158909250d2a4be4f9d2de80.diff
LOG: MLIR: asan: Fix python tests under asan on Linux (#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 <Philipp.Honysz at amd.com>
Added:
Modified:
mlir/test/lit.cfg.py
Removed:
################################################################################
diff --git a/mlir/test/lit.cfg.py b/mlir/test/lit.cfg.py
index f493e5be574a0c..32b2f8b53d5fa5 100644
--- a/mlir/test/lit.cfg.py
+++ b/mlir/test/lit.cfg.py
@@ -82,17 +82,32 @@ def add_runtime(name):
# available. This is darwin specific since it's currently only needed on darwin.
# Stolen from llvm/test/lit.cfg.py with a few modifications
def get_asan_rtlib():
- if not "asan" in config.available_features or not "Darwin" in config.host_os:
+ if not "asan" in config.available_features:
return ""
- # Find the asan rt lib
- resource_dir = (
- subprocess.check_output([config.host_cc.strip(), "-print-resource-dir"])
- .decode("utf-8")
- .strip()
- )
- return os.path.join(
- resource_dir, "lib", "darwin", "libclang_rt.asan_osx_dynamic.dylib"
- )
+
+ if "Darwin" in config.host_os:
+ # Find the asan rt lib
+ resource_dir = (
+ subprocess.check_output([config.host_cc.strip(), "-print-resource-dir"])
+ .decode("utf-8")
+ .strip()
+ )
+ return os.path.join(
+ resource_dir, "lib", "darwin", "libclang_rt.asan_osx_dynamic.dylib"
+ )
+ if "Linux" in config.host_os:
+ return (
+ subprocess.check_output(
+ [
+ config.host_cxx.strip(),
+ f"-print-file-name=libclang_rt.asan-{config.host_arch}.so",
+ ]
+ )
+ .decode("utf-8")
+ .strip()
+ )
+
+ return ""
# On macOS, we can't do the DYLD_INSERT_LIBRARIES trick with a shim python
@@ -247,7 +262,9 @@ def find_real_python_interpreter():
# TODO: detect Windows situation (or mark these tests as unsupported on these platforms).
if "asan" in config.available_features:
if "Linux" in config.host_os:
- python_executable = f"LD_PRELOAD=$({config.host_cxx} -print-file-name=libclang_rt.asan-{config.host_arch}.so) {config.python_executable}"
+ python_executable = (
+ f"env LD_PRELOAD={get_asan_rtlib()} {config.python_executable}"
+ )
if "Darwin" in config.host_os:
# Ensure we use a non-shim Python executable, for the `DYLD_INSERT_LIBRARIES`
# env variable to take effect
More information about the Mlir-commits
mailing list