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
|
|
|
|
|
[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
|
|
|
# Setup config name.
|
|
|
|
config.name = 'UBSan-' + config.name_suffix
|
|
|
|
|
2013-11-14 20:30:09 +08:00
|
|
|
# Setup source root.
|
2014-02-18 16:56:49 +08:00
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
2017-10-07 04:53:40 +08:00
|
|
|
default_ubsan_opts = list(config.default_sanitizer_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":
|
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 = []
|
2017-10-07 09:46:36 +08:00
|
|
|
elif ubsan_lit_test_mode == "StandaloneStatic":
|
|
|
|
config.available_features.add("ubsan-standalone-static")
|
|
|
|
clang_ubsan_cflags = ['-static-libsan']
|
2014-02-18 16:56:49 +08:00
|
|
|
elif ubsan_lit_test_mode == "AddressSanitizer":
|
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.available_features.add("ubsan-msan")
|
|
|
|
clang_ubsan_cflags = ["-fsanitize=memory"]
|
|
|
|
elif ubsan_lit_test_mode == "ThreadSanitizer":
|
|
|
|
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")
|
2017-10-07 04:51:51 +08:00
|
|
|
|
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):
|
[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-18 16:56:49 +08:00
|
|
|
|
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
|
2018-07-01 05:35:05 +08:00
|
|
|
if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows', 'NetBSD', 'SunOS', 'OpenBSD']:
|
2013-11-14 20:30:09 +08:00
|
|
|
config.unsupported = True
|
2014-10-16 15:48:27 +08:00
|
|
|
|
2017-07-29 08:20:02 +08:00
|
|
|
config.available_features.add('arch=' + config.target_arch)
|
2017-11-11 06:09:37 +08:00
|
|
|
|
|
|
|
config.excludes = ['Inputs']
|