1# Copyright © 2020, VideoLAN and dav1d authors 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are met: 6# 7# 1. Redistributions of source code must retain the above copyright notice, this 8# list of conditions and the following disclaimer. 9# 10# 2. Redistributions in binary form must reproduce the above copyright notice, 11# this list of conditions and the following disclaimer in the documentation 12# and/or other materials provided with the distribution. 13# 14# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 25# 26# Build definition for the dav1d fuzzing binaries 27# 28 29if fuzzing_engine == 'none' and not have_fseeko 30 subdir_done() 31endif 32 33dav1d_fuzzer_sources = files('dav1d_fuzzer.c') 34fuzzer_ldflags = [] 35fuzzer_link_lang = {} 36 37if get_option('fuzzer_ldflags') != '' 38 fuzzer_ldflags += [get_option('fuzzer_ldflags')] 39endif 40 41if fuzzing_engine == 'none' 42 dav1d_fuzzer_sources += files('main.c') 43elif fuzzing_engine == 'libfuzzer' 44 fuzzer_ldflags += ['-fsanitize=fuzzer'] 45elif fuzzing_engine == 'oss-fuzz' 46 # libFuzzingEngine needs c++ 47 add_languages('cpp') 48 fuzzer_link_lang = {'link_language': 'cpp'} 49endif 50 51dav1d_fuzzer = executable('dav1d_fuzzer', 52 dav1d_fuzzer_sources, 53 include_directories: dav1d_inc_dirs, 54 link_args: fuzzer_ldflags, 55 link_with : libdav1d, 56 build_by_default: true, 57 dependencies : [thread_dependency], 58 kwargs: fuzzer_link_lang 59 ) 60 61dav1d_fuzzer_mt = executable('dav1d_fuzzer_mt', 62 dav1d_fuzzer_sources, 63 include_directories: dav1d_inc_dirs, 64 c_args: ['-DDAV1D_MT_FUZZING'], 65 link_args: fuzzer_ldflags, 66 link_with : libdav1d, 67 build_by_default: true, 68 dependencies : [thread_dependency], 69 kwargs: fuzzer_link_lang 70 ) 71 72objcopy = find_program('objcopy', 73 required: false) 74if (objcopy.found() and 75 not get_option('b_lto') and 76 get_option('default_library') == 'static' and 77 cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test_args)) 78 79 libdav1d_af = custom_target('libdav1d_af', 80 input: libdav1d, 81 output: 'libdav1d_af.a', 82 depends: libdav1d, 83 command: [objcopy, 84 '--redefine-sym', 'malloc=__wrap_malloc', 85 '--redefine-sym', 'posix_memalign=__wrap_posix_memalign', 86 '--redefine-sym', 'pthread_create=__wrap_pthread_create', 87 '--redefine-sym', 'pthread_cond_init=__wrap_pthread_cond_init', 88 '--redefine-sym', 'pthread_mutex_init=__wrap_pthread_mutex_init', 89 '@INPUT@', '@OUTPUT@']) 90 91 dav1d_fuzzer_mem = executable('dav1d_fuzzer_mem', 92 dav1d_fuzzer_sources + ['alloc_fail.c'], 93 include_directories: dav1d_inc_dirs, 94 c_args: ['-DDAV1D_ALLOC_FAIL'], 95 link_args: fuzzer_ldflags + [join_paths(libdav1d_af.full_path())], 96 link_depends: libdav1d_af, 97 build_by_default: false, 98 dependencies : [thread_dependency], 99 kwargs: fuzzer_link_lang 100 ) 101endif 102