diff options
author | Roxane <roxane.fruytier@10gen.com> | 2019-06-12 16:35:43 -0400 |
---|---|---|
committer | Roxane <roxane.fruytier@10gen.com> | 2019-06-24 11:05:54 -0400 |
commit | 333af6c9058d072c26d7984ea660b359d2d6ef80 (patch) | |
tree | 2f984f3acc09b7ba9b77e1eafbf269cba729ac0e /SConstruct | |
parent | 68fd498481f7427cc780d270b27636f69bb1add8 (diff) | |
download | mongo-333af6c9058d072c26d7984ea660b359d2d6ef80.tar.gz |
SERVER-41689 Adding Scons support for building with libfuzzer
Diffstat (limited to 'SConstruct')
-rw-r--r-- | SConstruct | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/SConstruct b/SConstruct index 47dae18a609..32fe2f81704 100644 --- a/SConstruct +++ b/SConstruct @@ -260,6 +260,11 @@ add_option('sanitize', metavar='san1,san2,...sanN', ) +add_option('sanitize-coverage', + help='enable selected coverage sanitizers', + metavar='cov1,cov2,...covN', +) + add_option('llvm-symbolizer', default='llvm-symbolizer', help='name of (or path to) the LLVM symbolizer', @@ -658,6 +663,7 @@ def variable_tools_converter(val): "mongo_benchmark", "mongo_integrationtest", "mongo_unittest", + "mongo_libfuzzer", "textfile", ] @@ -1015,6 +1021,8 @@ envDict = dict(BUILD_ROOT=buildDir, # TODO: Move unittests.txt to $BUILD_DIR, but that requires # changes to MCI. UNITTEST_LIST='$BUILD_ROOT/unittests.txt', + LIBFUZZER_TEST_ALIAS='libfuzzer_tests', + LIBFUZZER_TEST_LIST='$BUILD_ROOT/libfuzzer_tests.txt', INTEGRATION_TEST_ALIAS='integration_tests', INTEGRATION_TEST_LIST='$BUILD_ROOT/integration_tests.txt', BENCHMARK_ALIAS='benchmarks', @@ -2633,6 +2641,7 @@ def doConfigure(myenv): using_asan = 'address' in sanitizer_list or using_lsan using_tsan = 'thread' in sanitizer_list using_ubsan = 'undefined' in sanitizer_list + using_fsan = 'fuzzer' in sanitizer_list if env['MONGO_ALLOCATOR'] in ['tcmalloc', 'tcmalloc-experimental'] and (using_lsan or using_asan): # There are multiply defined symbols between the sanitizer and @@ -2654,6 +2663,15 @@ def doConfigure(myenv): if 'address' in sanitizer_list: sanitizer_list.remove('leak') + if using_fsan: + if not myenv.ToolchainIs('clang'): + myenv.FatalError("Using the fuzzer sanitizer requires clang") + # We can't include the fuzzer flag with the other sanitize flags + # The libfuzzer library already has a main function, which will cause the dependencies check + # to fail + sanitizer_list.remove('fuzzer') + sanitizer_list.append('fuzzer-no-link') + sanitizer_option = '-fsanitize=' + ','.join(sanitizer_list) if AddToCCFLAGSIfSupported(myenv, sanitizer_option): @@ -2662,6 +2680,15 @@ def doConfigure(myenv): else: myenv.ConfError('Failed to enable sanitizers with flag: {0}', sanitizer_option ) + if has_option('sanitize-coverage') and using_fsan: + sanitize_coverage_list = get_option('sanitize-coverage') + sanitize_coverage_option = '-fsanitize-coverage=' + sanitize_coverage_list + if AddToCCFLAGSIfSupported(myenv,sanitize_coverage_option): + myenv.Append(LINKFLAGS=[sanitize_coverage_option]) + else: + myenv.ConfError('Failed to enable -fsanitize-coverage with flag: {0}', sanitize_coverage_option ) + + blackfiles_map = { "address" : myenv.File("#etc/asan.blacklist"), "leak" : myenv.File("#etc/asan.blacklist"), @@ -2733,7 +2760,9 @@ def doConfigure(myenv): # By default, undefined behavior sanitizer doesn't stop on # the first error. Make it so. Newer versions of clang # have renamed the flag. - if not AddToCCFLAGSIfSupported(myenv, "-fno-sanitize-recover"): + # However, this flag cannot be included when using the fuzzer sanitizer + # if we want to suppress errors to uncover new ones. + if not using_fsan and not AddToCCFLAGSIfSupported(myenv, "-fno-sanitize-recover"): AddToCCFLAGSIfSupported(myenv, "-fno-sanitize-recover=undefined") myenv.AppendUnique(CPPDEFINES=['UNDEFINED_BEHAVIOR_SANITIZER']) |