2017-08-22 07:25:50 +08:00
|
|
|
import lit.formats
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
config.name = "LLVMFuzzer"
|
|
|
|
config.test_format = lit.formats.ShTest(True)
|
|
|
|
config.suffixes = ['.test']
|
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
# LeakSanitizer is not supported on OSX right now.
|
lib Fuzzer FreeBSD support
Summary: Patch by David CARLIER
Reviewers: vitalybuka, kcc, dim, emaste, davide, morehouse, george.karpenkov
Reviewed By: morehouse
Subscribers: george.karpenkov, kubamracek, srhines, mgorny, emaste, krytarowski
Differential Revision: https://reviews.llvm.org/D41642
llvm-svn: 322380
2018-01-13 01:15:05 +08:00
|
|
|
if sys.platform.startswith('darwin') or sys.platform.startswith('freebsd'):
|
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')
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True):
|
|
|
|
compiler_cmd = config.c_compiler
|
2018-01-18 04:39:14 +08:00
|
|
|
if config.clang and config.stdlib == 'libc++':
|
2018-03-08 02:14:09 +08:00
|
|
|
link_cmd = '-stdlib=libc++ -Wl,-rpath=%s' % config.llvm_library_dir
|
2018-01-18 04:39:14 +08:00
|
|
|
elif config.clang and config.stdlib == 'static-libc++':
|
2018-03-08 02:14:09 +08:00
|
|
|
link_cmd = '-stdlib=libc++ -lc++abi -static-libstdc++ -Wl,-rpath=%s' % config.llvm_library_dir
|
2018-01-18 04:39:14 +08:00
|
|
|
else:
|
|
|
|
link_cmd = '-lc++' if any(x in config.target_triple for x in ('darwin', 'freebsd')) else '-lstdc++'
|
|
|
|
std_cmd = '--driver-mode=g++ -std=c++11' if is_cpp else ''
|
2017-08-22 07:25:50 +08:00
|
|
|
sanitizers = ['address']
|
|
|
|
if fuzzer_enabled:
|
|
|
|
sanitizers.append('fuzzer')
|
|
|
|
sanitizers_cmd = ('-fsanitize=%s' % ','.join(sanitizers))
|
[libFuzzer] Fix lit files to make running tests more straightforward on Mac OS.
Summary:
Current implementation does not work if CMAKE_OSX_SYSROOT is not specified.
It silently generates invalid command with the following flags:
`-std=c++11 -lc++ -gline-tables-only -isysroot -fsanitize=address,fuzzer`
and then fails with the following error:
```
warning: no such sysroot directory: '-fsanitize=address,fuzzer' [-Wmissing-sysroot]"
<...>/RepeatedBytesTest.cpp:5:10: fatal error: 'assert.h' file not found
#include <assert.h>
^~~~~~~~~~
1 error generated.
```
However, if you have Command Line Tools installed, you have '/usr/include' dir.
In that case, it is not necessary to specify isysroot path.
Also, with the patch, in case of '/usr/include' does not exist, the '-sysroot'
path would be resolved automatically in compiler-rt/cmake/base-config-ix.cmake.
For more context, see the comment at `compiler-rt/cmake/base-config-ix.cmake#L76`
Reviewers: kcc, george.karpenkov
Reviewed By: kcc, george.karpenkov
Differential Revision: https://reviews.llvm.org/D37721
llvm-svn: 313033
2017-09-12 23:02:10 +08:00
|
|
|
isysroot_cmd = config.osx_sysroot_flag if config.osx_sysroot_flag else ''
|
2017-08-22 07:25:50 +08:00
|
|
|
include_cmd = '-I%s' % libfuzzer_src_root
|
2018-03-24 07:35:28 +08:00
|
|
|
return '%s %s %s -O2 -gline-tables-only %s %s %s' % (
|
2017-08-22 07:25:50 +08:00
|
|
|
compiler_cmd, std_cmd, link_cmd, isysroot_cmd, sanitizers_cmd, include_cmd)
|
|
|
|
|
|
|
|
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)
|
|
|
|
))
|