Skip to content

Commit 9de187b

Browse files
authored
asan: Preload asan runtime into python interpreter (#4046)
Same as llvm/llvm-project#123303 upstream
1 parent a6415d3 commit 9de187b

File tree

6 files changed

+52
-3
lines changed

6 files changed

+52
-3
lines changed

projects/pt1/python/test/lit.cfg.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,23 @@
3737
# test_exec_root: The root path where tests should be run.
3838
config.test_exec_root = os.path.join(config.torch_mlir_obj_root, "test")
3939

40+
if "asan" in config.available_features and "Linux" in config.host_os:
41+
_asan_rt = (
42+
subprocess.check_output(
43+
[
44+
config.host_cxx.strip(),
45+
f"-print-file-name=libclang_rt.asan-{config.host_arch}.so",
46+
]
47+
)
48+
.decode("utf-8")
49+
.strip()
50+
)
51+
config.python_executable = f"env LD_PRELOAD={_asan_rt} {config.python_executable}"
52+
config.environment["ASAN_OPTIONS"] = "detect_leaks=0"
4053
# On Windows the path to python could contains spaces in which case it needs to
4154
# be provided in quotes. This is the equivalent of how %python is setup in
4255
# llvm/utils/lit/lit/llvm/config.py.
43-
if "Windows" in config.host_os:
56+
elif "Windows" in config.host_os:
4457
config.python_executable = '"%s"' % (config.python_executable)
4558

4659
config.substitutions.append(("%PATH%", config.environment["PATH"]))

projects/pt1/python/test/lit.site.cfg.py.in

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ config.llvm_lib_dir = "@LLVM_LIBRARY_DIR@"
1919
config.llvm_shlib_dir = "@SHLIBDIR@"
2020
config.llvm_shlib_ext = "@SHLIBEXT@"
2121
config.llvm_exe_ext = "@EXEEXT@"
22+
config.host_os = "@HOST_OS@"
23+
config.host_cxx = "@HOST_CXX@"
24+
config.host_arch = "@HOST_ARCH@"
25+
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
2226
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
2327
config.python_executable = "@Python3_EXECUTABLE@"
2428
config.gold_executable = "@GOLD_EXECUTABLE@"

projects/pt1/test/lit.cfg.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,23 @@
6666
"PATH", os.path.join(config.llvm_build_dir, "bin"), append_path=True
6767
)
6868

69+
if "asan" in config.available_features and "Linux" in config.host_os:
70+
_asan_rt = (
71+
subprocess.check_output(
72+
[
73+
config.host_cxx.strip(),
74+
f"-print-file-name=libclang_rt.asan-{config.host_arch}.so",
75+
]
76+
)
77+
.decode("utf-8")
78+
.strip()
79+
)
80+
config.python_executable = f"env LD_PRELOAD={_asan_rt} {config.python_executable}"
81+
config.environment["ASAN_OPTIONS"] = "detect_leaks=0"
6982
# On Windows the path to python could contains spaces in which case it needs to
7083
# be provided in quotes. This is the equivalent of how %python is setup in
7184
# llvm/utils/lit/lit/llvm/config.py.
72-
if "Windows" in config.host_os:
85+
elif "Windows" in config.host_os:
7386
config.python_executable = '"%s"' % (config.python_executable)
7487

7588
tool_dirs = [

projects/pt1/test/lit.site.cfg.py.in

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ config.enable_bindings_python = @MLIR_ENABLE_BINDINGS_PYTHON@
66
config.torch_mlir_obj_root = "@TORCH_MLIR_BINARY_DIR@"
77
config.torch_mlir_python_packages_dir = "@TORCH_MLIR_PYTHON_PACKAGES_DIR@"
88
config.host_os = "@HOST_OS@"
9+
config.host_cxx = "@HOST_CXX@"
10+
config.host_arch = "@HOST_ARCH@"
11+
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
912
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
1013
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
1114
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"

test/lit.cfg.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,23 @@
6666
"PATH", os.path.join(config.llvm_build_dir, "bin"), append_path=True
6767
)
6868

69+
if "asan" in config.available_features and "Linux" in config.host_os:
70+
_asan_rt = (
71+
subprocess.check_output(
72+
[
73+
config.host_cxx.strip(),
74+
f"-print-file-name=libclang_rt.asan-{config.host_arch}.so",
75+
]
76+
)
77+
.decode("utf-8")
78+
.strip()
79+
)
80+
config.python_executable = f"env LD_PRELOAD={_asan_rt} {config.python_executable}"
81+
config.environment["ASAN_OPTIONS"] = "detect_leaks=0"
6982
# On Windows the path to python could contains spaces in which case it needs to
7083
# be provided in quotes. This is the equivalent of how %python is setup in
7184
# llvm/utils/lit/lit/llvm/config.py.
72-
if "Windows" in config.host_os:
85+
elif "Windows" in config.host_os:
7386
config.python_executable = '"%s"' % (config.python_executable)
7487

7588
tool_dirs = [

test/lit.site.cfg.py.in

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ config.torch_mlir_obj_root = "@TORCH_MLIR_BINARY_DIR@"
77
config.torch_mlir_python_packages_dir = "@TORCH_MLIR_PYTHON_PACKAGES_DIR@"
88
config.torch_mlir_enable_refbackend = @TORCH_MLIR_ENABLE_REFBACKEND@
99
config.host_os = "@HOST_OS@"
10+
config.host_cxx = "@HOST_CXX@"
11+
config.host_arch = "@HOST_ARCH@"
12+
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
1013
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
1114
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
1215
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"

0 commit comments

Comments
 (0)