From: Andrew Bartlett Date: Tue, 5 Nov 2019 23:24:18 +0000 (+1300) Subject: lib/fuzzing: Use --fuzz-target-ldflags if specified X-Git-Tag: ldb-2.1.0~649 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=92ee647858331db012db06314d98e08fe1e5eb5b;p=thirdparty%2Fsamba.git lib/fuzzing: Use --fuzz-target-ldflags if specified This makes integration with oss-fuzz possible. Only the fuzzer binaries should be linked with libFuzzer, not things like asn1_compile, so this can not be done via the global ADDITIONAL_LDFLAGS. Signed-off-by: Andrew Bartlett Reviewed-by: Douglas Bagnall Reviewed-by: Uri Simchoni --- diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py index 3e19b832e11..7460fbae020 100644 --- a/buildtools/wafsamba/wafsamba.py +++ b/buildtools/wafsamba/wafsamba.py @@ -377,6 +377,8 @@ def SAMBA_BINARY(bld, binname, source, if fuzzer: install = False + if ldflags is None: + ldflags = bld.env['FUZZ_TARGET_LDFLAGS'] if not SET_TARGET_TYPE(bld, binname, 'BINARY'): return diff --git a/buildtools/wafsamba/wscript b/buildtools/wafsamba/wscript index b601dd2596d..9987c6e4fcc 100644 --- a/buildtools/wafsamba/wscript +++ b/buildtools/wafsamba/wscript @@ -130,9 +130,16 @@ def options(opt): dest='undefined_sanitizer', default=False) gr.add_option('--enable-libfuzzer', - help=("Build fuzzing binaries (requires compiler options for libFuzzer or compiler wrapper such as honggfuzz/hfuzz-cc)"), + help=("Build fuzzing binaries (use ADDITIONAL_CFLAGS to specify compiler options for libFuzzer or use a compiler wrapper such as honggfuzz/hfuzz-cc)"), action="store_true", dest='enable_libfuzzer', default=False) + # Fuzz targets may need additional LDFLAGS that we can't use on + # internal binaries like asn1_compile + + gr.add_option('--fuzz-target-ldflags', + help=("Linker flags to be used when building fuzz targets"), + action="store", dest='FUZZ_TARGET_LDFLAGS', default='') + gr.add_option('--abi-check', help=("Check ABI signatures for libraries"), action='store_true', dest='ABI_CHECK', default=False) @@ -596,6 +603,7 @@ struct foo bar = { .y = 'X', .x = 1 }; conf.env.enable_libfuzzer = Options.options.enable_libfuzzer if conf.env.enable_libfuzzer: conf.DEFINE('ENABLE_LIBFUZZER', 1) + conf.env.FUZZ_TARGET_LDFLAGS = Options.options.FUZZ_TARGET_LDFLAGS conf.load('clang_compilation_database') diff --git a/lib/fuzzing/wscript_build b/lib/fuzzing/wscript_build index 00a263ef877..386145c43b2 100644 --- a/lib/fuzzing/wscript_build +++ b/lib/fuzzing/wscript_build @@ -3,7 +3,7 @@ bld.SAMBA_SUBSYSTEM('fuzzing', source='fuzzing.c', deps='talloc', - enabled=bld.env.enable_libfuzzer, + enabled=bld.env.enable_libfuzzer ) bld.SAMBA_BINARY('fuzz_tiniparser',