• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 Google Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15################################################################################
16
17readonly EXTRA_BAZEL_FLAGS="$(
18for f in ${CFLAGS}; do
19  echo "--conlyopt=${f}" "--linkopt=${f}"
20done
21for f in ${CXXFLAGS}; do
22  echo "--cxxopt=${f}" "--linkopt=${f}"
23done
24
25if [ "$SANITIZER" = "undefined" ]
26then
27  # Bazel uses clang to link binary, which does not link clang_rt ubsan library for C++ automatically.
28  # See issue: https://github.com/bazelbuild/bazel/issues/8777
29  echo "--linkopt=\"$(find $(llvm-config --libdir) -name libclang_rt.ubsan_standalone_cxx-x86_64.a | head -1)\""
30fi
31)"
32
33declare FUZZ_TARGETS=("string_escape_fuzzer" "string_utilities_fuzzer")
34
35bazel build \
36	--verbose_failures \
37	--dynamic_mode=off \
38	--spawn_strategy=standalone \
39	--genrule_strategy=standalone \
40	--strip=never \
41	--linkopt=-pthread \
42	--copt=${LIB_FUZZING_ENGINE} \
43	--linkopt=${LIB_FUZZING_ENGINE} \
44	--linkopt=-lc++ \
45	${EXTRA_BAZEL_FLAGS} \
46	${FUZZ_TARGETS[*]}
47
48
49if [ "$SANITIZER" = "coverage" ]
50then
51  # The build invoker looks for sources in $SRC, but it turns out that we need
52  # to not be buried under src/, paths are expected at out/proc/self/cwd by
53  # the profiler.
54  declare -r REMAP_PATH="${OUT}/proc/self/cwd"
55  mkdir -p "${REMAP_PATH}"
56  mkdir -p "${REMAP_PATH}/external/com_google_absl"
57  rsync -av "${SRC}"/abseil-cpp/absl "${REMAP_PATH}/external/com_google_absl"
58
59  declare -r RSYNC_FILTER_ARGS=("--include" "*.h" "--include" "*.cc" "--include" \
60    "*.hpp" "--include" "*.cpp" "--include" "*.c" "--include" "*/" "--exclude" "*")
61  rsync -avLk "${RSYNC_FILTER_ARGS[@]}" "${SRC}"/bazel-out "${REMAP_PATH}"
62  rsync -avLkR "${RSYNC_FILTER_ARGS[@]}" "${HOME}" "${OUT}"
63  rsync -avLkR "${RSYNC_FILTER_ARGS[@]}" /tmp "${OUT}"
64
65  cp *fuzzer.cc "${OUT}/proc/self/cwd"
66fi
67
68cp "./bazel-bin/"*fuzzer "${OUT}/"
69