1#!/bin/bash -eu 2# Copyright 2016 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 SwiftShader 19pushd third_party/externals/swiftshader/ 20export SWIFTSHADER_INCLUDE_PATH=$PWD/include 21rm -rf build 22mkdir build 23 24cd build 25if [ $SANITIZER == "coverage" ]; then 26 cmake .. 27else 28 if [ $SANITIZER == "address" ]; then 29 CMAKE_SANITIZER="ASAN" 30 elif [ $SANITIZER == "memory" ]; then 31 CMAKE_SANITIZER="MSAN" 32 elif [ $SANITIZER == "undefined" ]; then 33 CMAKE_SANITIZER="UBSAN" 34 else 35 exit 1 36 fi 37 CFLAGS= CXXFLAGS="-stdlib=libc++" cmake .. -D$CMAKE_SANITIZER=1 38fi 39 40make -j 41cp libGLESv2.so libEGL.so $OUT 42export SWIFTSHADER_LIB_PATH=$OUT 43 44popd 45# These are any clang warnings we need to silence. 46DISABLE="-Wno-zero-as-null-pointer-constant -Wno-unused-template 47 -Wno-cast-qual" 48# Disable UBSan vptr since target built with -fno-rtti. 49# TODO(metzman): Stop using gold when 50# bugs.chromium.org/p/oss-fuzz/issues/detail?id=16777 gets resolved. 51export CFLAGS="$CFLAGS $DISABLE -I$SWIFTSHADER_INCLUDE_PATH -DGR_EGL_TRY_GLES3_THEN_GLES2 -fno-sanitize=vptr" 52export CXXFLAGS="$CXXFLAGS $DISABLE -I$SWIFTSHADER_INCLUDE_PATH -DGR_EGL_TRY_GLES3_THEN_GLES2 -fno-sanitize=vptr "-DIS_FUZZING_WITH_LIBFUZZER"" 53export LDFLAGS="$LIB_FUZZING_ENGINE $CXXFLAGS -L$SWIFTSHADER_LIB_PATH -fuse-ld=gold" 54 55# This splits a space separated list into a quoted, comma separated list for gn. 56export CFLAGS_ARR=`echo $CFLAGS | sed -e "s/\s/\",\"/g"` 57export CXXFLAGS_ARR=`echo $CXXFLAGS | sed -e "s/\s/\",\"/g"` 58export LDFLAGS_ARR=`echo $LDFLAGS | sed -e "s/\s/\",\"/g"` 59 60# Even though GPU is "enabled" for all these builds, none really 61# uses the gpu except for api_mock_gpu_canvas 62 63$SRC/depot_tools/gn gen out/Fuzz\ 64 --args='cc="'$CC'" 65 cxx="'$CXX'" 66 is_debug=false 67 extra_cflags_c=["'"$CFLAGS_ARR"'"] 68 extra_cflags_cc=["'"$CXXFLAGS_ARR"'"] 69 extra_ldflags=["'"$LDFLAGS_ARR"'"] 70 skia_enable_fontmgr_custom=false 71 skia_enable_fontmgr_custom_empty=true 72 skia_enable_gpu=true 73 skia_enable_skottie=true 74 skia_use_egl=true 75 skia_use_fontconfig=false 76 skia_use_freetype=true 77 skia_use_system_freetype2=false 78 skia_use_wuffs=true' 79 80$SRC/depot_tools/gn gen out/Fuzz_mem_constraints\ 81 --args='cc="'$CC'" 82 cxx="'$CXX'" 83 is_debug=false 84 extra_cflags_c=["'"$CFLAGS_ARR"'"] 85 extra_cflags_cc=["'"$CXXFLAGS_ARR"'","-DIS_FUZZING"] 86 extra_ldflags=["'"$LDFLAGS_ARR"'"] 87 skia_enable_fontmgr_custom=false 88 skia_enable_fontmgr_custom_empty=true 89 skia_enable_gpu=true 90 skia_enable_skottie=true 91 skia_use_egl=true 92 skia_use_fontconfig=false 93 skia_use_freetype=true 94 skia_use_system_freetype2=false 95 skia_use_wuffs=true' 96 97$SRC/depot_tools/ninja -C out/Fuzz region_deserialize region_set_path \ 98 path_deserialize image_decode \ 99 animated_image_decode api_draw_functions \ 100 api_gradients api_path_measure png_encoder \ 101 jpeg_encoder webp_encoder skottie_json \ 102 textblob_deserialize skjson \ 103 api_null_canvas api_image_filter api_pathop \ 104 api_polyutils android_codec image_decode_incremental \ 105 sksl2glsl sksl2spirv sksl2metal sksl2pipeline \ 106 api_skdescriptor skdescriptor_deserialize 107 108$SRC/depot_tools/ninja -C out/Fuzz_mem_constraints image_filter_deserialize \ 109 api_raster_n32_canvas \ 110 api_mock_gpu_canvas 111 112cp out/Fuzz/region_deserialize $OUT/region_deserialize 113cp ./region_deserialize.options $OUT/region_deserialize.options 114 115cp out/Fuzz/region_set_path $OUT/region_set_path 116cp ./region_set_path.options $OUT/region_set_path.options 117cp ./region_set_path_seed_corpus.zip $OUT/region_set_path_seed_corpus.zip 118 119cp out/Fuzz/textblob_deserialize $OUT/textblob_deserialize 120cp ./textblob_deserialize.options $OUT/textblob_deserialize.options 121cp ./textblob_deserialize_seed_corpus.zip $OUT/textblob_deserialize_seed_corpus.zip 122 123cp out/Fuzz/path_deserialize $OUT/path_deserialize 124cp ./path_deserialize.options $OUT/path_deserialize.options 125cp ./path_deserialize_seed_corpus.zip $OUT/path_deserialize_seed_corpus.zip 126 127cp out/Fuzz/image_decode $OUT/image_decode 128cp ./image_decode.options $OUT/image_decode.options 129cp ./image_decode_seed_corpus.zip $OUT/image_decode_seed_corpus.zip 130 131cp out/Fuzz/animated_image_decode $OUT/animated_image_decode 132cp ./animated_image_decode.options $OUT/animated_image_decode.options 133cp ./animated_image_decode_seed_corpus.zip $OUT/animated_image_decode_seed_corpus.zip 134 135cp out/Fuzz_mem_constraints/image_filter_deserialize $OUT/image_filter_deserialize 136cp ./image_filter_deserialize.options $OUT/image_filter_deserialize.options 137cp ./image_filter_deserialize_seed_corpus.zip $OUT/image_filter_deserialize_seed_corpus.zip 138 139# Only create the width version of image_filter_deserialize if building with 140# libfuzzer, since it depends on a libfuzzer specific flag. 141if [ "$FUZZING_ENGINE" == "libfuzzer" ] 142then 143 # Use the same binary as image_filter_deserialize. 144 cp out/Fuzz_mem_constraints/image_filter_deserialize $OUT/image_filter_deserialize_width 145 cp ./image_filter_deserialize_width.options $OUT/image_filter_deserialize_width.options 146 # Use the same seed corpus as image_filter_deserialize. 147 cp ./image_filter_deserialize_seed_corpus.zip $OUT/image_filter_deserialize_width_seed_corpus.zip 148fi 149 150cp out/Fuzz/api_draw_functions $OUT/api_draw_functions 151cp ./api_draw_functions.options $OUT/api_draw_functions.options 152cp ./api_draw_functions_seed_corpus.zip $OUT/api_draw_functions_seed_corpus.zip 153 154cp out/Fuzz/api_gradients $OUT/api_gradients 155cp ./api_gradients.options $OUT/api_gradients.options 156cp ./api_gradients_seed_corpus.zip $OUT/api_gradients_seed_corpus.zip 157 158cp out/Fuzz/api_path_measure $OUT/api_path_measure 159cp ./api_path_measure.options $OUT/api_path_measure.options 160cp ./api_path_measure_seed_corpus.zip $OUT/api_path_measure_seed_corpus.zip 161 162cp out/Fuzz/api_pathop $OUT/api_pathop 163cp ./api_pathop.options $OUT/api_pathop.options 164cp ./api_pathop_seed_corpus.zip $OUT/api_pathop_seed_corpus.zip 165 166cp out/Fuzz/png_encoder $OUT/png_encoder 167cp ./encoder.options $OUT/png_encoder.options 168cp ./encoder_seed_corpus.zip $OUT/png_encoder_seed_corpus.zip 169 170cp out/Fuzz/jpeg_encoder $OUT/jpeg_encoder 171cp ./encoder.options $OUT/jpeg_encoder.options 172cp ./encoder_seed_corpus.zip $OUT/jpeg_encoder_seed_corpus.zip 173 174cp out/Fuzz/webp_encoder $OUT/webp_encoder 175cp ./encoder.options $OUT/webp_encoder.options 176cp ./encoder_seed_corpus.zip $OUT/webp_encoder_seed_corpus.zip 177 178cp out/Fuzz/skottie_json $OUT/skottie_json 179cp ./skottie_json_seed_corpus.zip $OUT/skottie_json_seed_corpus.zip 180 181cp out/Fuzz/skjson $OUT/skjson 182cp json.dict $OUT/skjson.dict 183cp ./skjson_seed_corpus.zip $OUT/skjson_seed_corpus.zip 184 185cp out/Fuzz_mem_constraints/api_mock_gpu_canvas $OUT/api_mock_gpu_canvas 186cp ./api_mock_gpu_canvas.options $OUT/api_mock_gpu_canvas.options 187cp ./canvas_seed_corpus.zip $OUT/api_mock_gpu_canvas_seed_corpus.zip 188 189cp out/Fuzz_mem_constraints/api_raster_n32_canvas $OUT/api_raster_n32_canvas 190cp ./api_raster_n32_canvas.options $OUT/api_raster_n32_canvas.options 191cp ./canvas_seed_corpus.zip $OUT/api_raster_n32_canvas_seed_corpus.zip 192 193cp out/Fuzz/api_image_filter $OUT/api_image_filter 194cp ./api_image_filter.options $OUT/api_image_filter.options 195cp ./api_image_filter_seed_corpus.zip $OUT/api_image_filter_seed_corpus.zip 196 197cp out/Fuzz/api_null_canvas $OUT/api_null_canvas 198cp ./api_null_canvas.options $OUT/api_null_canvas.options 199cp ./canvas_seed_corpus.zip $OUT/api_null_canvas_seed_corpus.zip 200 201cp out/Fuzz/api_polyutils $OUT/api_polyutils 202cp ./api_polyutils.options $OUT/api_polyutils.options 203cp ./api_polyutils_seed_corpus.zip $OUT/api_polyutils_seed_corpus.zip 204 205# These 2 can use the same corpus as the (non animated) image_decode. 206cp out/Fuzz/android_codec $OUT/android_codec 207cp ./android_codec.options $OUT/android_codec.options 208cp ./image_decode_seed_corpus.zip $OUT/android_codec_seed_corpus.zip. 209 210cp out/Fuzz/image_decode_incremental $OUT/image_decode_incremental 211cp ./image_decode_incremental.options $OUT/image_decode_incremental.options 212cp ./image_decode_seed_corpus.zip $OUT/image_decode_incremental_seed_corpus.zip 213 214cp out/Fuzz/sksl2glsl $OUT/sksl2glsl 215cp ./sksl2glsl.options $OUT/sksl2glsl.options 216cp ./sksl_seed_corpus.zip $OUT/sksl2glsl_seed_corpus.zip 217 218cp out/Fuzz/sksl2spirv $OUT/sksl2spirv 219cp ./sksl2spirv.options $OUT/sksl2spirv.options 220cp ./sksl_seed_corpus.zip $OUT/sksl2spirv_seed_corpus.zip 221 222cp out/Fuzz/sksl2metal $OUT/sksl2metal 223cp ./sksl2metal.options $OUT/sksl2metal.options 224cp ./sksl_seed_corpus.zip $OUT/sksl2metal_seed_corpus.zip 225 226cp out/Fuzz/sksl2pipeline $OUT/sksl2pipeline 227cp ./sksl2pipeline.options $OUT/sksl2pipeline.options 228cp ./sksl_seed_corpus.zip $OUT/sksl2pipeline_seed_corpus.zip 229 230cp out/Fuzz/api_skdescriptor $OUT/api_skdescriptor 231cp ./api_skdescriptor.options $OUT/api_skdescriptor.options 232cp ./api_skdescriptor_seed_corpus.zip $OUT/api_skdescriptor_seed_corpus.zip 233 234# Don't have any examples of an SkDescriptor atm, so some random bytes is all we have. 235cp out/Fuzz/skdescriptor_deserialize $OUT/skdescriptor_deserialize 236cp ./skdescriptor_deserialize.options $OUT/skdescriptor_deserialize.options 237cp ./api_skdescriptor_seed_corpus.zip $OUT/skdescriptor_deserialize_seed_corpus.zip