• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
21# SwiftShader already has a build/ directory, use something else
22rm -rf build_swiftshader
23mkdir build_swiftshader
24
25cd build_swiftshader
26if [ $SANITIZER == "address" ]; then
27  CMAKE_SANITIZER="SWIFTSHADER_ASAN"
28elif [ $SANITIZER == "memory" ]; then
29  CMAKE_SANITIZER="SWIFTSHADER_MSAN"
30  # oss-fuzz will patch the rpath for this after compilation and linking,
31  # so we only need to set this to appease the Swiftshader build rules check.
32  export SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH="/does/not/matter"
33elif [ $SANITIZER == "undefined" ]; then
34  # The current SwiftShader build needs -fno-sanitize=vptr, but it cannot be
35  # specified here since -fsanitize=undefined will always come after any
36  # user specified flags passed to cmake. SwiftShader does not need to be
37  # built with the undefined sanitizer in order to fuzz Skia, so don't.
38  CMAKE_SANITIZER="SWIFTSHADER_UBSAN_DISABLED"
39elif [ $SANITIZER == "coverage" ]; then
40  CMAKE_SANITIZER="SWIFTSHADER_EMIT_COVERAGE"
41elif [ $SANITIZER == "thread" ]; then
42  CMAKE_SANITIZER="SWIFTSHADER_UBSAN_DISABLED"
43else
44  exit 1
45fi
46# These deprecated warnings get quite noisy and mask other issues.
47CFLAGS= CXXFLAGS="-stdlib=libc++ -Wno-deprecated-declarations" cmake .. -GNinja \
48  -DCMAKE_MAKE_PROGRAM="$SRC/depot_tools/ninja" -D$CMAKE_SANITIZER=1
49
50$SRC/depot_tools/ninja libGLESv2_deprecated libEGL_deprecated
51# Skia is looking for the names w/o the _deprecated tag. The libraries themselves
52# are looking for the _deprecated suffix, so we copy them both ways into the out
53# directory.
54cp libEGL_deprecated.so $OUT/libEGL.so
55cp libGLESv2_deprecated.so $OUT/libGLESv2.so
56mv libGLESv2_deprecated.so libEGL_deprecated.so $OUT
57export SWIFTSHADER_LIB_PATH=$OUT
58
59popd
60# These are any clang warnings we need to silence.
61DISABLE="-Wno-zero-as-null-pointer-constant -Wno-unused-template
62         -Wno-cast-qual"
63# Disable UBSan vptr since target built with -fno-rtti.
64export CFLAGS="$CFLAGS $DISABLE -I$SWIFTSHADER_INCLUDE_PATH -DGR_EGL_TRY_GLES3_THEN_GLES2\
65 -fno-sanitize=vptr -DSK_BUILD_FOR_LIBFUZZER"
66export CXXFLAGS="$CXXFLAGS $DISABLE -I$SWIFTSHADER_INCLUDE_PATH -DGR_EGL_TRY_GLES3_THEN_GLES2\
67 -fno-sanitize=vptr -DSK_BUILD_FOR_LIBFUZZER"
68export LDFLAGS="$LIB_FUZZING_ENGINE $CXXFLAGS -L$SWIFTSHADER_LIB_PATH"
69
70# This splits a space separated list into a quoted, comma separated list for gn.
71export CFLAGS_ARR=`echo $CFLAGS | sed -e "s/\s/\",\"/g"`
72export CXXFLAGS_ARR=`echo $CXXFLAGS | sed -e "s/\s/\",\"/g"`
73export LDFLAGS_ARR=`echo $LDFLAGS | sed -e "s/\s/\",\"/g"`
74
75$SRC/skia/bin/fetch-gn
76
77set +u
78LIMITED_LINK_POOL="link_pool_depth=1"
79if [ "$CIFUZZ" = "true" ]; then
80  echo "Not restricting linking because on CIFuzz"
81  LIMITED_LINK_POOL=""
82fi
83set -u
84
85SKIA_ARGS="skia_build_fuzzers=true
86           skia_enable_fontmgr_custom_directory=false
87           skia_enable_fontmgr_custom_embedded=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           skia_use_libfuzzer_defaults=false"
97
98# Even though GPU is "enabled" for all these builds, none really
99# uses the gpu except for api_mock_gpu_canvas.
100$SRC/skia/bin/gn gen out/Fuzz\
101    --args='cc="'$CC'"
102      cxx="'$CXX'"
103      '"$LIMITED_LINK_POOL"'
104      '"${SKIA_ARGS[*]}"'
105      is_debug=false
106      extra_cflags_c=["'"$CFLAGS_ARR"'"]
107      extra_cflags_cc=["'"$CXXFLAGS_ARR"'"]
108      extra_ldflags=["'"$LDFLAGS_ARR"'"]'
109
110# Some fuzz targets benefit from assertions so we enable SK_DEBUG to allow SkASSERT
111# and SkDEBUGCODE to run. We still enable optimization (via is_debug=false) because
112# faster code means more fuzz tests and deeper coverage.
113$SRC/skia/bin/gn gen out/FuzzDebug\
114    --args='cc="'$CC'"
115      cxx="'$CXX'"
116      '"$LIMITED_LINK_POOL"'
117      '"${SKIA_ARGS[*]}"'
118      is_debug=false
119      extra_cflags_c=["-DSK_DEBUG","'"$CFLAGS_ARR"'"]
120      extra_cflags_cc=["-DSK_DEBUG","'"$CXXFLAGS_ARR"'"]
121      extra_ldflags=["'"$LDFLAGS_ARR"'"]'
122
123$SRC/depot_tools/ninja -C out/Fuzz \
124  android_codec \
125  animated_image_decode \
126  api_create_ddl \
127  api_ddl_threading \
128  api_draw_functions \
129  api_gradients \
130  api_image_filter \
131  api_mock_gpu_canvas \
132  api_null_canvas \
133  api_path_measure \
134  api_pathop \
135  api_polyutils \
136  api_raster_n32_canvas \
137  api_regionop \
138  api_skparagraph \
139  api_svg_canvas \
140  api_triangulation \
141  image_decode \
142  image_decode_incremental \
143  image_filter_deserialize \
144  jpeg_encoder \
145  path_deserialize \
146  png_encoder \
147  region_deserialize \
148  region_set_path \
149  skdescriptor_deserialize \
150  skjson \
151  skottie_json \
152  skp \
153  svg_dom \
154  textblob_deserialize \
155  webp_encoder
156
157$SRC/depot_tools/ninja -C out/FuzzDebug \
158  skruntimeeffect \
159  sksl2glsl \
160  sksl2metal \
161  sksl2pipeline \
162  sksl2spirv \
163
164rm -rf $OUT/data
165mkdir $OUT/data
166
167mv out/Fuzz/region_deserialize $OUT/region_deserialize
168
169mv out/Fuzz/region_set_path $OUT/region_set_path
170mv ../skia_data/region_set_path_seed_corpus.zip $OUT/region_set_path_seed_corpus.zip
171
172mv out/Fuzz/textblob_deserialize $OUT/textblob_deserialize
173mv ../skia_data/textblob_deserialize_seed_corpus.zip $OUT/textblob_deserialize_seed_corpus.zip
174
175mv out/Fuzz/path_deserialize $OUT/path_deserialize
176mv ../skia_data/path_deserialize_seed_corpus.zip $OUT/path_deserialize_seed_corpus.zip
177
178mv out/Fuzz/animated_image_decode $OUT/animated_image_decode
179mv ../skia_data/animated_image_decode_seed_corpus.zip $OUT/animated_image_decode_seed_corpus.zip
180
181# Only create the width version of image_filter_deserialize if building with
182# libfuzzer, since it depends on a libfuzzer specific flag.
183if [ "$FUZZING_ENGINE" == "libfuzzer" ]
184then
185  # Use the same binary as image_filter_deserialize.
186  cp out/Fuzz/image_filter_deserialize $OUT/image_filter_deserialize_width
187  mv ../skia_data/image_filter_deserialize_width.options $OUT/image_filter_deserialize_width.options
188  # Use the same seed corpus as image_filter_deserialize.
189  cp ../skia_data/image_filter_deserialize_seed_corpus.zip $OUT/image_filter_deserialize_width_seed_corpus.zip
190fi
191
192mv out/Fuzz/image_filter_deserialize $OUT/image_filter_deserialize
193mv ../skia_data/image_filter_deserialize_seed_corpus.zip $OUT/image_filter_deserialize_seed_corpus.zip
194
195mv out/Fuzz/api_draw_functions $OUT/api_draw_functions
196mv ../skia_data/api_draw_functions_seed_corpus.zip $OUT/api_draw_functions_seed_corpus.zip
197
198mv out/Fuzz/api_gradients $OUT/api_gradients
199mv ../skia_data/api_gradients_seed_corpus.zip $OUT/api_gradients_seed_corpus.zip
200
201mv out/Fuzz/api_path_measure $OUT/api_path_measure
202mv ../skia_data/api_path_measure_seed_corpus.zip $OUT/api_path_measure_seed_corpus.zip
203
204mv out/Fuzz/api_pathop $OUT/api_pathop
205mv ../skia_data/api_pathop_seed_corpus.zip $OUT/api_pathop_seed_corpus.zip
206
207# These 3 use the same corpus.
208mv out/Fuzz/png_encoder $OUT/png_encoder
209cp ../skia_data/encoder_seed_corpus.zip $OUT/png_encoder_seed_corpus.zip
210
211mv out/Fuzz/jpeg_encoder $OUT/jpeg_encoder
212cp ../skia_data/encoder_seed_corpus.zip $OUT/jpeg_encoder_seed_corpus.zip
213
214mv out/Fuzz/webp_encoder $OUT/webp_encoder
215mv ../skia_data/encoder_seed_corpus.zip $OUT/webp_encoder_seed_corpus.zip
216
217mv out/Fuzz/skottie_json $OUT/skottie_json
218mv ../skia_data/skottie_json_seed_corpus.zip $OUT/skottie_json_seed_corpus.zip
219
220mv out/Fuzz/skjson $OUT/skjson
221mv ../skia_data/json.dict $OUT/skjson.dict
222mv ../skia_data/skjson_seed_corpus.zip $OUT/skjson_seed_corpus.zip
223
224# These 4 use the same canvas_seed_corpus.
225mv out/Fuzz/api_mock_gpu_canvas $OUT/api_mock_gpu_canvas
226cp ../skia_data/canvas_seed_corpus.zip $OUT/api_mock_gpu_canvas_seed_corpus.zip
227
228mv out/Fuzz/api_raster_n32_canvas $OUT/api_raster_n32_canvas
229cp ../skia_data/canvas_seed_corpus.zip $OUT/api_raster_n32_canvas_seed_corpus.zip
230
231mv out/Fuzz/api_svg_canvas $OUT/api_svg_canvas
232cp ../skia_data/canvas_seed_corpus.zip $OUT/api_svg_canvas_seed_corpus.zip
233
234mv out/Fuzz/api_null_canvas $OUT/api_null_canvas
235mv ../skia_data/canvas_seed_corpus.zip $OUT/api_null_canvas_seed_corpus.zip
236
237mv out/Fuzz/api_image_filter $OUT/api_image_filter
238mv ../skia_data/api_image_filter_seed_corpus.zip $OUT/api_image_filter_seed_corpus.zip
239
240mv out/Fuzz/api_polyutils $OUT/api_polyutils
241mv ../skia_data/api_polyutils_seed_corpus.zip $OUT/api_polyutils_seed_corpus.zip
242
243# These 3 use the same corpus.
244mv out/Fuzz/image_decode $OUT/image_decode
245cp ../skia_data/image_decode_seed_corpus.zip $OUT/image_decode_seed_corpus.zip
246
247mv out/Fuzz/android_codec $OUT/android_codec
248cp ../skia_data/image_decode_seed_corpus.zip $OUT/android_codec_seed_corpus.zip.
249
250mv out/Fuzz/image_decode_incremental $OUT/image_decode_incremental
251mv ../skia_data/image_decode_seed_corpus.zip $OUT/image_decode_incremental_seed_corpus.zip
252
253# These 4 use the same sksl_seed_corpus.
254mv out/FuzzDebug/sksl2glsl $OUT/sksl2glsl
255cp ../skia_data/sksl_seed_corpus.zip $OUT/sksl2glsl_seed_corpus.zip
256
257mv out/FuzzDebug/sksl2spirv $OUT/sksl2spirv
258cp ../skia_data/sksl_seed_corpus.zip $OUT/sksl2spirv_seed_corpus.zip
259
260mv out/FuzzDebug/sksl2metal $OUT/sksl2metal
261cp ../skia_data/sksl_seed_corpus.zip $OUT/sksl2metal_seed_corpus.zip
262
263mv out/FuzzDebug/sksl2pipeline $OUT/sksl2pipeline
264mv ../skia_data/sksl_seed_corpus.zip $OUT/sksl2pipeline_seed_corpus.zip
265
266mv out/Fuzz/skdescriptor_deserialize $OUT/skdescriptor_deserialize
267
268mv out/Fuzz/svg_dom $OUT/svg_dom
269mv ../skia_data/svg_dom_seed_corpus.zip $OUT/svg_dom_seed_corpus.zip
270
271
272mv out/FuzzDebug/skruntimeeffect $OUT/skruntimeeffect
273mv ../skia_data/sksl_with_256_padding_seed_corpus.zip $OUT/skruntimeeffect_seed_corpus.zip
274
275mv out/Fuzz/api_create_ddl $OUT/api_create_ddl
276
277mv out/Fuzz/api_ddl_threading $OUT/api_ddl_threading
278
279mv out/Fuzz/skp $OUT/skp
280mv ../skia_data/skp_seed_corpus.zip $OUT/skp_seed_corpus.zip
281
282mv out/Fuzz/api_skparagraph $OUT/api_skparagraph
283
284mv out/Fuzz/api_regionop $OUT/api_regionop
285
286mv out/Fuzz/api_triangulation $OUT/api_triangulation
287