2012-09-18 15:23:54 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2013-05-27 17:35:24 +08:00
|
|
|
def get_required_attr(config, attr_name):
|
|
|
|
attr_value = getattr(config, attr_name, None)
|
|
|
|
if not attr_value:
|
2013-08-10 06:14:01 +08:00
|
|
|
lit_config.fatal(
|
|
|
|
"No attribute %r in test configuration! You may need to run "
|
|
|
|
"tests from your build directory or add this attribute "
|
|
|
|
"to lit.site.cfg " % attr_name)
|
2013-05-27 17:35:24 +08:00
|
|
|
return attr_value
|
|
|
|
|
2012-09-18 15:23:54 +08:00
|
|
|
# Setup config name.
|
2016-02-03 02:43:53 +08:00
|
|
|
config.name = 'ThreadSanitizer' + config.name_suffix
|
2012-09-18 15:23:54 +08:00
|
|
|
|
|
|
|
# Setup source root.
|
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
# Setup environment variables for running ThreadSanitizer.
|
2015-11-20 01:28:46 +08:00
|
|
|
default_tsan_opts = "atexit_sleep_ms=0"
|
2012-11-16 18:16:14 +08:00
|
|
|
|
2015-11-06 23:05:34 +08:00
|
|
|
if config.host_os == 'Darwin':
|
|
|
|
# On Darwin, we default to `abort_on_error=1`, which would make tests run
|
|
|
|
# much slower. Let's override this and run lit tests with 'abort_on_error=0'.
|
2015-11-20 01:28:46 +08:00
|
|
|
default_tsan_opts += ':abort_on_error=0'
|
2017-01-25 05:37:50 +08:00
|
|
|
# On Darwin, we default to ignore_noninstrumented_modules=1, which also
|
|
|
|
# suppresses some races the tests are supposed to find. Let's run without this
|
|
|
|
# setting, but turn it back on for Darwin tests (see Darwin/lit.local.cfg).
|
|
|
|
default_tsan_opts += ':ignore_noninstrumented_modules=0'
|
2015-11-20 01:28:46 +08:00
|
|
|
|
|
|
|
# Platform-specific default TSAN_OPTIONS for lit tests.
|
|
|
|
if default_tsan_opts:
|
|
|
|
config.environment['TSAN_OPTIONS'] = default_tsan_opts
|
|
|
|
default_tsan_opts += ':'
|
|
|
|
config.substitutions.append(('%env_tsan_opts=',
|
|
|
|
'env TSAN_OPTIONS=' + default_tsan_opts))
|
2012-09-18 15:23:54 +08:00
|
|
|
|
2014-05-17 04:33:56 +08:00
|
|
|
# GCC driver doesn't add necessary compile/link flags with -fsanitize=thread.
|
|
|
|
if config.compiler_id == 'GNU':
|
2014-05-28 21:13:30 +08:00
|
|
|
extra_cflags = ["-fPIE", "-pthread", "-ldl", "-lstdc++", "-lrt", "-pie"]
|
2014-05-17 04:33:56 +08:00
|
|
|
else:
|
|
|
|
extra_cflags = []
|
|
|
|
|
2016-11-14 19:40:56 +08:00
|
|
|
tsan_incdir = config.test_source_root + "/../"
|
2012-11-06 10:31:42 +08:00
|
|
|
# Setup default compiler flags used with -fsanitize=thread option.
|
2016-02-03 02:43:53 +08:00
|
|
|
clang_tsan_cflags = (["-fsanitize=thread",
|
|
|
|
"-Wall"] +
|
|
|
|
[config.target_cflags] +
|
|
|
|
config.debug_info_flags +
|
2016-11-14 19:40:56 +08:00
|
|
|
extra_cflags +
|
|
|
|
["-I%s" % tsan_incdir])
|
|
|
|
clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags + ["-std=c++11"] + ["-I%s" % tsan_incdir]
|
2014-05-14 06:30:16 +08:00
|
|
|
# Add additional flags if we're using instrumented libc++.
|
2015-11-06 23:05:34 +08:00
|
|
|
# Instrumented libcxx currently not supported on Darwin.
|
|
|
|
if config.has_libcxx and config.host_os != 'Darwin':
|
2014-05-14 06:30:16 +08:00
|
|
|
# FIXME: Dehardcode this path somehow.
|
|
|
|
libcxx_path = os.path.join(config.compiler_rt_obj_root, "lib",
|
2018-03-08 02:14:09 +08:00
|
|
|
"tsan", "libcxx_tsan_%s" % config.target_arch)
|
2014-05-14 06:30:16 +08:00
|
|
|
libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1")
|
|
|
|
libcxx_libdir = os.path.join(libcxx_path, "lib")
|
|
|
|
libcxx_so = os.path.join(libcxx_libdir, "libc++.so")
|
2016-10-19 02:33:42 +08:00
|
|
|
clang_tsan_cxxflags += ["-nostdinc++",
|
2014-05-14 06:30:16 +08:00
|
|
|
"-I%s" % libcxx_incdir,
|
|
|
|
libcxx_so,
|
|
|
|
"-Wl,-rpath=%s" % libcxx_libdir]
|
2014-02-17 21:08:10 +08:00
|
|
|
|
|
|
|
def build_invocation(compile_flags):
|
[ubsan] Re-commit: lit changes for lld testing, future lto testing.
Summary:
As discussed in https://github.com/google/oss-fuzz/issues/933,
it would be really awesome to be able to use ThinLTO for fuzzing.
However, as @kcc has pointed out, it is currently undefined (untested)
whether the sanitizers actually function properly with LLD and/or LTO.
This patch is inspired by the cfi test, which already do test with LTO
(and/or LLD), since LTO is required for CFI to function.
I started with UBSan, because it's cmakelists / lit.* files appeared
to be the cleanest. This patch adds the infrastructure to easily add
LLD and/or LTO sub-variants of the existing lit test configurations.
Also, this patch adds the LLD flavor, that explicitly does use LLD to link.
The check-ubsan does pass on my machine. And to minimize the [initial]
potential buildbot breakage i have put some restrictions on this flavour.
Please review carefully, i have not worked with lit/sanitizer tests before.
The original attempt, r319525 was reverted in r319526 due
to the failures in compiler-rt standalone builds.
Reviewers: eugenis, vitalybuka
Reviewed By: eugenis
Subscribers: #sanitizers, pcc, kubamracek, mgorny, llvm-commits, mehdi_amini, inglorion, kcc
Differential Revision: https://reviews.llvm.org/D39508
llvm-svn: 319575
2017-12-02 03:36:29 +08:00
|
|
|
return " " + " ".join([config.clang] + compile_flags) + " "
|
2014-02-17 21:08:10 +08:00
|
|
|
|
|
|
|
config.substitutions.append( ("%clang_tsan ", build_invocation(clang_tsan_cflags)) )
|
|
|
|
config.substitutions.append( ("%clangxx_tsan ", build_invocation(clang_tsan_cxxflags)) )
|
2012-09-18 15:23:54 +08:00
|
|
|
|
|
|
|
# Define CHECK-%os to check for OS-dependent output.
|
|
|
|
config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
|
|
|
|
|
2016-11-27 03:09:32 +08:00
|
|
|
config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash") + " "))
|
2014-05-30 22:08:51 +08:00
|
|
|
|
2012-09-18 15:23:54 +08:00
|
|
|
# Default test suffixes.
|
2015-11-12 21:27:55 +08:00
|
|
|
config.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm']
|
2012-09-18 15:23:54 +08:00
|
|
|
|
2017-10-26 01:09:05 +08:00
|
|
|
if config.host_os not in ['FreeBSD', 'Linux', 'Darwin', 'NetBSD']:
|
2012-09-18 15:23:54 +08:00
|
|
|
config.unsupported = True
|
2015-08-29 04:40:50 +08:00
|
|
|
|
2017-10-12 05:22:45 +08:00
|
|
|
if config.android:
|
|
|
|
config.unsupported = True
|
|
|
|
|
2018-01-20 10:07:30 +08:00
|
|
|
if config.host_os == 'Darwin':
|
|
|
|
if config.target_arch in ["x86_64", "x86_64h"]:
|
|
|
|
config.parallelism_group = "darwin-64bit-sanitizer"
|
2018-06-20 21:33:42 +08:00
|
|
|
elif config.apple_platform != "osx" and not config.apple_platform.endswith("sim"):
|
2018-01-20 10:07:30 +08:00
|
|
|
config.parallelism_group = "darwin-ios-device-sanitizer"
|