Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asan: Preload asan runtime into python interpreter #4046

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion projects/pt1/python/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@

# Configuration file for the 'lit' test runner.


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


# name: The name of this test suite.
config.name = "TORCH_MLIR_PYTHON"

Expand All @@ -37,10 +55,15 @@
# test_exec_root: The root path where tests should be run.
config.test_exec_root = os.path.join(config.torch_mlir_obj_root, "test")

# Python configuration with sanitizer requires some magic preloading. This will only work on clang/linux.
# TODO: detect Darwin/Windows situation (or mark these tests as unsupported on these platforms).
if "asan" in config.available_features and "Linux" in config.host_os:
_asan_rt = find_asan_runtime()
config.python_executable = f"env LD_PRELOAD={_asan_rt} {config.python_executable}"
# On Windows the path to python could contains spaces in which case it needs to
# be provided in quotes. This is the equivalent of how %python is setup in
# llvm/utils/lit/lit/llvm/config.py.
if "Windows" in config.host_os:
elif "Windows" in config.host_os:
config.python_executable = '"%s"' % (config.python_executable)

config.substitutions.append(("%PATH%", config.environment["PATH"]))
Expand Down
Loading