1#!/bin/bash -eu 2# Copyright 2018 Google Inc. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16################################################################################ 17 18# Build libaom 19build_dir=$WORK/build 20mkdir -p ${build_dir} 21pushd ${build_dir} 22# Remove files generated by the previous build. 23rm -rf ./* 24 25# oss-fuzz has 2 GB total memory allocation limit. So, we limit per-allocation 26# limit in libaom to 1 GB to avoid OOM errors. A smaller per-allocation is 27# needed for MemorySanitizer (see bug oss-fuzz:9497 and bug oss-fuzz:9499). 28if [[ $CFLAGS = *sanitize=memory* ]]; then 29 extra_c_flags='-DAOM_MAX_ALLOCABLE_MEMORY=536870912' 30else 31 extra_c_flags='-DAOM_MAX_ALLOCABLE_MEMORY=1073741824' 32fi 33# Also, enable DO_RANGE_CHECK_CLAMP to suppress the noise of integer overflows 34# in the transform functions. 35extra_c_flags+=' -DDO_RANGE_CHECK_CLAMP=1' 36 37extra_cmake_flags= 38# MemorySanitizer requires that all program code is instrumented. Therefore we 39# need to replace all inline assembly code that writes to memory with pure C 40# code. Disable all assembly code for MemorySanitizer. 41if [[ $CFLAGS = *sanitize=memory* ]]; then 42 extra_cmake_flags+="-DAOM_TARGET_CPU=generic" 43fi 44 45cmake $SRC/aom -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE='-O3 -g' \ 46 -DCMAKE_CXX_FLAGS_RELEASE='-O3 -g' -DCONFIG_PIC=1 -DCONFIG_LOWBITDEPTH=1 \ 47 -DCONFIG_AV1_ENCODER=0 -DENABLE_EXAMPLES=0 -DENABLE_DOCS=0 -DENABLE_TESTS=0 \ 48 -DCONFIG_SIZE_LIMIT=1 -DDECODE_HEIGHT_LIMIT=12288 -DDECODE_WIDTH_LIMIT=12288 \ 49 -DAOM_EXTRA_C_FLAGS="${extra_c_flags}" \ 50 -DAOM_EXTRA_CXX_FLAGS="${extra_c_flags}" ${extra_cmake_flags} 51make -j$(nproc) 52popd 53 54# build fuzzers 55fuzzer_src_name=av1_dec_fuzzer 56fuzzer_name=${fuzzer_src_name} 57 58$CXX $CXXFLAGS -std=c++11 \ 59 -I$SRC/aom \ 60 -I${build_dir} \ 61 -Wl,--start-group \ 62 $LIB_FUZZING_ENGINE \ 63 $SRC/aom/examples/${fuzzer_src_name}.cc -o $OUT/${fuzzer_name} \ 64 ${build_dir}/libaom.a -Wl,--end-group 65 66# copy seed corpus. 67cp $SRC/dec_fuzzer_seed_corpus.zip $OUT/${fuzzer_name}_seed_corpus.zip 68cp $SRC/av1_dec_fuzzer.dict $OUT/${fuzzer_name}.dict 69 70