2017-08-22 07:25:50 +08:00
|
|
|
import lit.formats
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
2018-06-15 04:46:07 +08:00
|
|
|
config.name = "libFuzzer" + config.name_suffix
|
2017-08-22 07:25:50 +08:00
|
|
|
config.test_format = lit.formats.ShTest(True)
|
|
|
|
config.suffixes = ['.test']
|
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
2019-05-01 01:58:55 +08:00
|
|
|
config.available_features.add(config.target_arch)
|
2017-08-22 07:25:50 +08:00
|
|
|
|
|
|
|
# Choose between lit's internal shell pipeline runner and a real shell. If
|
|
|
|
# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
|
|
|
|
use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
|
|
|
|
if use_lit_shell:
|
|
|
|
# 0 is external, "" is default, and everything else is internal.
|
|
|
|
execute_external = (use_lit_shell == "0")
|
|
|
|
else:
|
|
|
|
# Otherwise we default to internal on Windows and external elsewhere, as
|
|
|
|
# bash on Windows is usually very slow.
|
|
|
|
execute_external = (not sys.platform in ['win32'])
|
|
|
|
|
|
|
|
# testFormat: The test format to use to interpret tests.
|
|
|
|
#
|
|
|
|
# For now we require '&&' between commands, until they get globally killed and
|
|
|
|
# the test runner updated.
|
|
|
|
config.test_format = lit.formats.ShTest(execute_external)
|
|
|
|
|
2019-05-01 01:58:58 +08:00
|
|
|
# LeakSanitizer is not supported on OSX or Windows right now.
|
2018-09-05 01:08:47 +08:00
|
|
|
if (sys.platform.startswith('darwin') or
|
|
|
|
sys.platform.startswith('freebsd') or
|
2018-10-09 18:34:36 +08:00
|
|
|
sys.platform.startswith('netbsd') or
|
2018-09-05 01:08:47 +08:00
|
|
|
sys.platform.startswith('win')):
|
2017-08-22 07:25:50 +08:00
|
|
|
lit_config.note('lsan feature unavailable')
|
|
|
|
else:
|
|
|
|
lit_config.note('lsan feature available')
|
|
|
|
config.available_features.add('lsan')
|
|
|
|
|
2018-09-05 01:08:47 +08:00
|
|
|
# MemorySanitizer is not supported on OSX or Windows right now
|
2019-05-01 01:58:55 +08:00
|
|
|
if (sys.platform.startswith('darwin') or sys.platform.startswith('win') or
|
|
|
|
config.target_arch == 'i386'):
|
2018-07-10 21:35:35 +08:00
|
|
|
lit_config.note('msan feature unavailable')
|
|
|
|
assert 'msan' not in config.available_features
|
|
|
|
else:
|
|
|
|
lit_config.note('msan feature available')
|
|
|
|
config.available_features.add('msan')
|
|
|
|
|
2017-08-22 07:25:50 +08:00
|
|
|
if sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
|
|
|
|
config.available_features.add('windows')
|
|
|
|
|
|
|
|
if sys.platform.startswith('darwin'):
|
|
|
|
config.available_features.add('darwin')
|
|
|
|
|
|
|
|
if sys.platform.startswith('linux'):
|
|
|
|
# Note the value of ``sys.platform`` is not consistent
|
|
|
|
# between python 2 and 3, hence the use of ``.startswith()``.
|
|
|
|
lit_config.note('linux feature available')
|
|
|
|
config.available_features.add('linux')
|
|
|
|
else:
|
|
|
|
lit_config.note('linux feature unavailable')
|
|
|
|
|
|
|
|
config.substitutions.append(('%build_dir', config.cmake_binary_dir))
|
|
|
|
libfuzzer_src_root = os.path.join(config.compiler_rt_src_root, "lib", "fuzzer")
|
|
|
|
config.substitutions.append(('%libfuzzer_src', libfuzzer_src_root))
|
|
|
|
|
2018-07-10 07:51:08 +08:00
|
|
|
def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=False):
|
2018-06-13 05:14:11 +08:00
|
|
|
compiler_cmd = config.clang
|
2018-06-15 04:46:07 +08:00
|
|
|
extra_cmd = config.target_flags
|
2018-06-13 05:14:11 +08:00
|
|
|
|
Use clang driver for libfuzzer tests on Windows
Summary:
There's no real reason to use clang-cl on Windows, the clang driver
works just as well. This fixes a test which uses the -O0 flag, which was
recently removed from clang-cl to match MSVC, which lacks this flag.
While I'm here, remove the explicit -std=c++11 flag. Previously, this
flag was necessary when the default C++ standard was C++98. Now that the
default is C++14, this is no longer necessary. It's problematic on
Windows, because the Visual C++ standard library relies on C++14
features, and attempting to compile it with C++11 results in errors.
Rather than adding logic to conditionally set the standard to C++11 only
on non-Win, this flag can be removed.
See http://lab.llvm.org:8011/builders/clang-x64-windows-msvc and
https://reviews.llvm.org/D64506.
Reviewers: morehouse, thakis
Subscribers: #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D64587
llvm-svn: 365841
2019-07-12 07:20:04 +08:00
|
|
|
if is_cpp:
|
|
|
|
std_cmd = '--driver-mode=g++'
|
2018-09-05 01:08:47 +08:00
|
|
|
else:
|
|
|
|
std_cmd = ''
|
|
|
|
|
2018-07-10 07:51:08 +08:00
|
|
|
if msan_enabled:
|
|
|
|
sanitizers = ['memory']
|
|
|
|
else:
|
|
|
|
sanitizers = ['address']
|
2017-08-22 07:25:50 +08:00
|
|
|
if fuzzer_enabled:
|
|
|
|
sanitizers.append('fuzzer')
|
|
|
|
sanitizers_cmd = ('-fsanitize=%s' % ','.join(sanitizers))
|
2018-06-13 05:14:11 +08:00
|
|
|
return " ".join([
|
|
|
|
compiler_cmd,
|
|
|
|
std_cmd,
|
|
|
|
"-O2 -gline-tables-only",
|
|
|
|
sanitizers_cmd,
|
2018-06-15 04:46:07 +08:00
|
|
|
"-I%s" % libfuzzer_src_root,
|
|
|
|
extra_cmd
|
2018-06-13 05:14:11 +08:00
|
|
|
])
|
2017-08-22 07:25:50 +08:00
|
|
|
|
|
|
|
config.substitutions.append(('%cpp_compiler',
|
|
|
|
generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True)
|
|
|
|
))
|
|
|
|
|
|
|
|
config.substitutions.append(('%c_compiler',
|
|
|
|
generate_compiler_cmd(is_cpp=False, fuzzer_enabled=True)
|
|
|
|
))
|
|
|
|
|
|
|
|
config.substitutions.append(('%no_fuzzer_cpp_compiler',
|
|
|
|
generate_compiler_cmd(is_cpp=True, fuzzer_enabled=False)
|
|
|
|
))
|
|
|
|
|
|
|
|
config.substitutions.append(('%no_fuzzer_c_compiler',
|
|
|
|
generate_compiler_cmd(is_cpp=False, fuzzer_enabled=False)
|
|
|
|
))
|
2018-06-15 04:46:07 +08:00
|
|
|
|
2018-07-10 07:51:08 +08:00
|
|
|
config.substitutions.append(('%msan_compiler',
|
|
|
|
generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=True)
|
|
|
|
))
|
|
|
|
|
2019-01-31 09:24:01 +08:00
|
|
|
default_asan_opts_str = ':'.join(config.default_sanitizer_opts)
|
|
|
|
if default_asan_opts_str:
|
|
|
|
config.environment['ASAN_OPTIONS'] = default_asan_opts_str
|
|
|
|
default_asan_opts_str += ':'
|
|
|
|
config.substitutions.append(('%env_asan_opts=',
|
|
|
|
'env ASAN_OPTIONS=' + default_asan_opts_str))
|
|
|
|
|
2019-03-01 03:26:53 +08:00
|
|
|
if not config.parallelism_group:
|
|
|
|
config.parallelism_group = 'shadow-memory'
|