5 def get_required_attr(config, attr_name):
6 attr_value = getattr(config, attr_name, None)
9 "No attribute %r in test configuration! You may need to run "
10 "tests from your build directory or add this attribute "
11 "to lit.site.cfg " % attr_name)
15 config.name = 'ThreadSanitizer'
18 config.test_source_root = os.path.dirname(__file__)
20 # Setup environment variables for running ThreadSanitizer.
21 tsan_options = "atexit_sleep_ms=0"
23 config.environment['TSAN_OPTIONS'] = tsan_options
25 # GCC driver doesn't add necessary compile/link flags with -fsanitize=thread.
26 if config.compiler_id == 'GNU':
27 extra_cflags = ["-fPIE", "-lpthread", "-ldl", "-lstdc++", "-lrt", "-pie"]
31 # Setup default compiler flags used with -fsanitize=thread option.
32 # FIXME: Review the set of required flags and check if it can be reduced.
33 clang_tsan_cflags = ["-fsanitize=thread",
36 "-m64"] + extra_cflags
37 clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags
38 # Add additional flags if we're using instrumented libc++.
40 # FIXME: Dehardcode this path somehow.
41 libcxx_path = os.path.join(config.compiler_rt_obj_root, "lib",
42 "tsan", "libcxx_tsan")
43 libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1")
44 libcxx_libdir = os.path.join(libcxx_path, "lib")
45 libcxx_so = os.path.join(libcxx_libdir, "libc++.so")
46 clang_tsan_cxxflags += ["-std=c++11",
47 "-I%s" % libcxx_incdir,
49 "-Wl,-rpath=%s" % libcxx_libdir]
51 def build_invocation(compile_flags):
52 return " " + " ".join([config.clang] + compile_flags) + " "
54 config.substitutions.append( ("%clang_tsan ", build_invocation(clang_tsan_cflags)) )
55 config.substitutions.append( ("%clangxx_tsan ", build_invocation(clang_tsan_cxxflags)) )
57 # Define CHECK-%os to check for OS-dependent output.
58 config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
60 # Default test suffixes.
61 config.suffixes = ['.c', '.cc', '.cpp']
63 # ThreadSanitizer tests are currently supported on Linux only.
64 if config.host_os not in ['Linux']:
65 config.unsupported = True