Skip to content

Commit 8d8ec55

Browse files
committed
[lldb/Test] Unify DYLD_INSERT_LIBRARIES solution for ASan and TSan
Add the same fix for loading the sanitizer runtime for TSan as we currently have for ASan and unify the code with a helper function.
1 parent 2247072 commit 8d8ec55

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

lldb/test/API/lit.cfg.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@
2020
config.test_source_root = os.path.dirname(__file__)
2121
config.test_exec_root = config.test_source_root
2222

23-
if 'Address' in config.llvm_use_sanitizer:
24-
config.environment['ASAN_OPTIONS'] = 'detect_stack_use_after_return=1'
25-
# macOS flags needed for LLDB built with address sanitizer.
26-
if 'Darwin' in config.host_os and 'x86' in config.host_triple:
27-
import subprocess
28-
resource_dir = subprocess.check_output(
29-
[config.cmake_cxx_compiler,
30-
'-print-resource-dir']).decode('utf-8').strip()
31-
runtime = os.path.join(resource_dir, 'lib', 'darwin',
32-
'libclang_rt.asan_osx_dynamic.dylib')
33-
config.environment['DYLD_INSERT_LIBRARIES'] = runtime
23+
24+
def find_sanitizer_runtime(name):
25+
import subprocess
26+
resource_dir = subprocess.check_output(
27+
[config.cmake_cxx_compiler,
28+
'-print-resource-dir']).decode('utf-8').strip()
29+
return os.path.join(resource_dir, 'lib', 'darwin', name)
3430

3531

3632
def find_shlibpath_var():
@@ -42,6 +38,17 @@ def find_shlibpath_var():
4238
yield 'PATH'
4339

4440

41+
if 'Address' in config.llvm_use_sanitizer:
42+
config.environment['ASAN_OPTIONS'] = 'detect_stack_use_after_return=1'
43+
if 'Darwin' in config.host_os and 'x86' in config.host_triple:
44+
config.environment['DYLD_INSERT_LIBRARIES'] = find_sanitizer_runtime(
45+
'libclang_rt.asan_osx_dynamic.dylib')
46+
47+
if 'Thread' in config.llvm_use_sanitizer:
48+
if 'Darwin' in config.host_os and 'x86' in config.host_triple:
49+
config.environment['DYLD_INSERT_LIBRARIES'] = find_sanitizer_runtime(
50+
'libclang_rt.tsan_osx_dynamic.dylib')
51+
4552
# Shared library build of LLVM may require LD_LIBRARY_PATH or equivalent.
4653
if config.shared_libs:
4754
for shlibpath_var in find_shlibpath_var():

0 commit comments

Comments
 (0)