2013-11-14 20:30:09 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
def get_required_attr(config, attr_name):
|
|
|
|
attr_value = getattr(config, attr_name, None)
|
2014-05-01 05:32:30 +08:00
|
|
|
if attr_value == None:
|
2013-11-14 20:30:09 +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)
|
|
|
|
return attr_value
|
|
|
|
|
|
|
|
# Setup source root.
|
2014-02-18 16:56:49 +08:00
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
2015-08-28 04:40:24 +08:00
|
|
|
default_ubsan_opts = []
|
2014-02-18 16:56:49 +08:00
|
|
|
# Choose between standalone and UBSan+ASan modes.
|
|
|
|
ubsan_lit_test_mode = get_required_attr(config, 'ubsan_lit_test_mode')
|
|
|
|
if ubsan_lit_test_mode == "Standalone":
|
2015-02-27 03:19:44 +08:00
|
|
|
config.name = 'UBSan-Standalone-' + config.target_arch
|
2014-09-20 02:33:45 +08:00
|
|
|
config.available_features.add("ubsan-standalone")
|
2014-02-18 16:56:49 +08:00
|
|
|
clang_ubsan_cflags = []
|
|
|
|
elif ubsan_lit_test_mode == "AddressSanitizer":
|
2015-02-27 03:19:44 +08:00
|
|
|
config.name = 'UBSan-ASan-' + config.target_arch
|
2014-09-20 02:33:45 +08:00
|
|
|
config.available_features.add("ubsan-asan")
|
2014-02-18 16:56:49 +08:00
|
|
|
clang_ubsan_cflags = ["-fsanitize=address"]
|
2015-08-28 04:40:24 +08:00
|
|
|
default_ubsan_opts += ['detect_leaks=0']
|
2015-04-28 08:56:48 +08:00
|
|
|
elif ubsan_lit_test_mode == "MemorySanitizer":
|
|
|
|
config.name = 'UBSan-MSan-' + config.target_arch
|
|
|
|
config.available_features.add("ubsan-msan")
|
|
|
|
clang_ubsan_cflags = ["-fsanitize=memory"]
|
|
|
|
elif ubsan_lit_test_mode == "ThreadSanitizer":
|
|
|
|
config.name = 'UBSan-TSan-' + config.target_arch
|
|
|
|
config.available_features.add("ubsan-tsan")
|
|
|
|
clang_ubsan_cflags = ["-fsanitize=thread"]
|
2014-02-18 16:56:49 +08:00
|
|
|
else:
|
|
|
|
lit_config.fatal("Unknown UBSan test mode: %r" % ubsan_lit_test_mode)
|
|
|
|
|
2015-08-28 04:40:24 +08:00
|
|
|
# Platform-specific default for lit tests.
|
2017-05-10 02:07:50 +08:00
|
|
|
if config.target_arch == 's390x':
|
|
|
|
# On SystemZ we need -mbackchain to make the fast unwinder work.
|
|
|
|
clang_ubsan_cflags.append("-mbackchain")
|
2015-08-28 04:40:24 +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'.
|
|
|
|
default_ubsan_opts += ['abort_on_error=0']
|
Reapply: [asan] On OS X, log reports to syslog and os_trace
When ASan currently detects a bug, by default it will only print out the text
of the report to stderr. This patch changes this behavior and writes the full
text of the report to syslog before we terminate the process. It also calls
os_trace (Activity Tracing available on OS X and iOS) with a message saying
that the report is available in syslog. This is useful, because this message
will be shown in the crash log.
For this to work, the patch makes sure we store the full report into
error_message_buffer unconditionally, and it also strips out ANSI escape
sequences from the report (they are used when producing colored reports).
I've initially tried to log to syslog during printing, which is done on Android
right now. The advantage is that if we crash during error reporting or the
produced error does not go through ScopedInErrorReport, we would still get a
(partial) message in the syslog. However, that solution is very problematic on
OS X. One issue is that the logging routine uses GCD, which may spawn a new
thread on its behalf. In many cases, the reporting logic locks threadRegistry,
which leads to deadlocks.
Reviewed at http://reviews.llvm.org/D13452
(In addition, add sanitizer_common_libcdep.cc to buildgo.sh to avoid
build failures on Linux.)
llvm-svn: 253688
2015-11-21 02:41:44 +08:00
|
|
|
default_ubsan_opts += ['log_to_syslog=0']
|
2015-08-28 04:40:24 +08:00
|
|
|
default_ubsan_opts_str = ':'.join(default_ubsan_opts)
|
|
|
|
if default_ubsan_opts_str:
|
|
|
|
config.environment['UBSAN_OPTIONS'] = default_ubsan_opts_str
|
|
|
|
default_ubsan_opts_str += ':'
|
2015-08-26 03:01:44 +08:00
|
|
|
# Substitution to setup UBSAN_OPTIONS in portable way.
|
|
|
|
config.substitutions.append(('%env_ubsan_opts=',
|
2015-08-28 04:40:24 +08:00
|
|
|
'env UBSAN_OPTIONS=' + default_ubsan_opts_str))
|
2015-08-26 03:01:44 +08:00
|
|
|
|
2014-02-18 16:56:49 +08:00
|
|
|
def build_invocation(compile_flags):
|
|
|
|
return " " + " ".join([config.clang] + compile_flags) + " "
|
|
|
|
|
2017-05-16 01:25:10 +08:00
|
|
|
target_cflags = [get_required_attr(config, "target_cflags")]
|
2014-05-14 08:46:01 +08:00
|
|
|
clang_ubsan_cflags += target_cflags
|
2014-02-19 23:13:14 +08:00
|
|
|
clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags
|
2014-02-18 16:56:49 +08:00
|
|
|
|
|
|
|
# Define %clang and %clangxx substitutions to use in test RUN lines.
|
|
|
|
config.substitutions.append( ("%clang ", build_invocation(clang_ubsan_cflags)) )
|
|
|
|
config.substitutions.append( ("%clangxx ", build_invocation(clang_ubsan_cxxflags)) )
|
2017-05-16 01:25:10 +08:00
|
|
|
config.substitutions.append( ("%gmlt ", " ".join(config.debug_info_flags) + " ") )
|
2013-11-14 20:30:09 +08:00
|
|
|
|
|
|
|
# Default test suffixes.
|
|
|
|
config.suffixes = ['.c', '.cc', '.cpp']
|
|
|
|
|
2014-11-10 23:31:56 +08:00
|
|
|
# Check that the host supports UndefinedBehaviorSanitizer tests
|
2017-08-09 04:49:20 +08:00
|
|
|
if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows', 'NetBSD']:
|
2013-11-14 20:30:09 +08:00
|
|
|
config.unsupported = True
|
2014-10-16 15:48:27 +08:00
|
|
|
|
2015-08-18 20:44:55 +08:00
|
|
|
# Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL
|
|
|
|
# because the test hangs or fails on one configuration and not the other.
|
2015-09-18 23:48:32 +08:00
|
|
|
if config.target_arch.startswith('arm') == False and config.target_arch != 'aarch64':
|
2015-08-18 20:44:55 +08:00
|
|
|
config.available_features.add('stable-runtime')
|
2017-07-29 08:20:02 +08:00
|
|
|
|
|
|
|
config.available_features.add('arch=' + config.target_arch)
|