2017-08-30 04:03:51 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
def get_required_attr(config, attr_name):
|
|
|
|
attr_value = getattr(config, attr_name, None)
|
|
|
|
if attr_value == None:
|
|
|
|
lit_config.fatal(
|
|
|
|
"No attribute %r in test configuration! You may need to run "
|
|
|
|
"tests from your build directory or add this attribute "
|
2019-06-28 04:56:04 +08:00
|
|
|
"to lit.site.cfg.py " % attr_name)
|
2017-08-30 04:03:51 +08:00
|
|
|
return attr_value
|
|
|
|
|
|
|
|
# Setup source root.
|
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
2017-08-31 08:54:10 +08:00
|
|
|
config.name = 'UBSan-Minimal-' + config.target_arch
|
2017-08-30 04:03:51 +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) + " "
|
2017-08-30 04:03:51 +08:00
|
|
|
|
|
|
|
target_cflags = [get_required_attr(config, "target_cflags")]
|
|
|
|
clang_ubsan_cflags = ["-fsanitize-minimal-runtime"] + target_cflags
|
|
|
|
clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags
|
|
|
|
|
|
|
|
# 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)) )
|
|
|
|
|
|
|
|
# Default test suffixes.
|
2019-08-06 03:25:35 +08:00
|
|
|
config.suffixes = ['.c', '.cpp']
|
2017-08-30 04:03:51 +08:00
|
|
|
|
|
|
|
# Check that the host supports UndefinedBehaviorSanitizerMinimal tests
|
2020-11-20 21:06:25 +08:00
|
|
|
if config.host_os not in ['Linux', 'FreeBSD', 'NetBSD', 'Darwin', 'OpenBSD', 'SunOS']: # TODO: Windows
|
2017-08-30 04:03:51 +08:00
|
|
|
config.unsupported = True
|
|
|
|
|
2017-09-12 08:01:13 +08:00
|
|
|
# Don't target x86_64h if the test machine can't execute x86_64h binaries.
|
2017-09-13 01:32:25 +08:00
|
|
|
if '-arch x86_64h' in target_cflags and 'x86_64h' not in config.available_features:
|
2017-09-12 08:01:13 +08:00
|
|
|
config.unsupported = True
|
|
|
|
|
2017-08-30 04:03:51 +08:00
|
|
|
config.available_features.add('arch=' + config.target_arch)
|