2016-11-18 19:44:37 +00:00
|
|
|
#!/bin/bash -eu
|
2016-07-20 21:58:10 +00:00
|
|
|
# Copyright 2016 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
################################################################################
|
2016-08-06 17:29:42 +00:00
|
|
|
|
2016-08-08 02:53:25 +00:00
|
|
|
echo "---------------------------------------------------------------"
|
|
|
|
|
2019-06-12 18:08:15 +00:00
|
|
|
if [ "$SANITIZER" = "dataflow" ] && [ "$FUZZING_ENGINE" != "dataflow" ]; then
|
|
|
|
echo "ERROR: 'dataflow' sanitizer can be used with 'dataflow' engine only."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-12-27 17:13:07 +00:00
|
|
|
if [ -z "${SANITIZER_FLAGS-}" ]; then
|
2016-12-02 18:58:51 +00:00
|
|
|
FLAGS_VAR="SANITIZER_FLAGS_${SANITIZER}"
|
2017-05-08 18:17:27 +00:00
|
|
|
export SANITIZER_FLAGS=${!FLAGS_VAR-}
|
2016-12-02 18:58:51 +00:00
|
|
|
fi
|
|
|
|
|
2019-08-12 17:54:18 +00:00
|
|
|
if [[ $ARCHITECTURE == "i386" ]]; then
|
2019-05-13 22:01:25 +00:00
|
|
|
export CFLAGS="-m32 $CFLAGS"
|
2019-05-14 17:18:02 +00:00
|
|
|
cp -R /usr/i386/lib/* /usr/lib
|
2019-05-13 22:01:25 +00:00
|
|
|
fi
|
2018-06-26 20:08:14 +00:00
|
|
|
if [[ $FUZZING_ENGINE != "none" ]]; then
|
|
|
|
# compile script might override environment, use . to call it.
|
|
|
|
. compile_${FUZZING_ENGINE}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $SANITIZER_FLAGS = *sanitize=memory* ]]
|
|
|
|
then
|
2018-01-11 01:56:33 +00:00
|
|
|
# Take all libraries from lib/msan and MSAN_LIBS_PATH
|
2016-12-16 04:57:07 +00:00
|
|
|
# export CXXFLAGS_EXTRA="-L/usr/msan/lib $CXXFLAGS_EXTRA"
|
2016-12-16 04:57:29 +00:00
|
|
|
cp -R /usr/msan/lib/* /usr/lib/
|
2018-01-11 01:56:33 +00:00
|
|
|
|
|
|
|
if [[ -z "${MSAN_LIBS_PATH-}" ]]; then
|
|
|
|
echo 'WARNING: Building without MSan instrumented libraries.'
|
|
|
|
else
|
|
|
|
# Copy all static libraries only. Don't include .so files because they can
|
|
|
|
# break non MSan compiled programs.
|
|
|
|
(cd "$MSAN_LIBS_PATH" && find . -name '*.a' -exec cp --parents '{}' / ';')
|
|
|
|
fi
|
2016-08-15 22:24:03 +00:00
|
|
|
fi
|
|
|
|
|
2017-05-08 18:17:27 +00:00
|
|
|
# Coverage flag overrides.
|
2017-10-21 00:15:02 +00:00
|
|
|
COVERAGE_FLAGS_VAR="COVERAGE_FLAGS_${SANITIZER}"
|
2018-06-26 20:08:14 +00:00
|
|
|
if [[ -n ${!COVERAGE_FLAGS_VAR+x} ]]
|
|
|
|
then
|
2017-05-08 18:17:27 +00:00
|
|
|
export COVERAGE_FLAGS="${!COVERAGE_FLAGS_VAR}"
|
|
|
|
fi
|
|
|
|
|
2019-06-12 18:08:15 +00:00
|
|
|
# Don't need coverage instrumentation for engine-less builds.
|
|
|
|
if [ $FUZZING_ENGINE = "none" ]; then
|
2017-10-31 23:11:00 +00:00
|
|
|
export COVERAGE_FLAGS=
|
|
|
|
fi
|
|
|
|
|
2016-12-13 18:37:03 +00:00
|
|
|
export CFLAGS="$CFLAGS $SANITIZER_FLAGS $COVERAGE_FLAGS"
|
2016-08-08 02:53:25 +00:00
|
|
|
export CXXFLAGS="$CFLAGS $CXXFLAGS_EXTRA"
|
2016-07-22 21:05:53 +00:00
|
|
|
|
|
|
|
echo "CC=$CC"
|
|
|
|
echo "CXX=$CXX"
|
|
|
|
echo "CFLAGS=$CFLAGS"
|
|
|
|
echo "CXXFLAGS=$CXXFLAGS"
|
2016-08-08 02:53:25 +00:00
|
|
|
|
|
|
|
echo "---------------------------------------------------------------"
|
|
|
|
|
2016-12-27 17:39:59 +00:00
|
|
|
BUILD_CMD="bash -eux $SRC/build.sh"
|
2018-06-14 22:00:46 +00:00
|
|
|
|
|
|
|
# We need to preserve source code files for generating a code coverage report.
|
|
|
|
# We need exact files that were compiled, so copy both $SRC and $WORK dirs.
|
2018-08-27 15:25:29 +00:00
|
|
|
COPY_SOURCES_CMD="cp -rL --parents $SRC $WORK /usr/include $OUT"
|
2018-06-14 22:00:46 +00:00
|
|
|
|
2017-03-04 00:37:19 +00:00
|
|
|
if [ "${BUILD_UID-0}" -ne "0" ]; then
|
2017-02-11 15:57:49 +00:00
|
|
|
adduser -u $BUILD_UID --disabled-password --gecos '' builder
|
2016-12-27 21:47:44 +00:00
|
|
|
chown -R builder $SRC $OUT $WORK
|
2016-12-21 23:01:44 +00:00
|
|
|
su -c "$BUILD_CMD" builder
|
2018-10-01 13:43:21 +00:00
|
|
|
if [ "$SANITIZER" = "coverage" ]; then
|
2018-08-22 14:20:09 +00:00
|
|
|
# Some directories have broken symlinks (e.g. honggfuzz), ignore the errors.
|
2019-01-14 21:01:16 +00:00
|
|
|
su -c "$COPY_SOURCES_CMD" builder 2>/dev/null || true
|
2018-06-14 22:00:46 +00:00
|
|
|
fi
|
2016-12-21 23:01:44 +00:00
|
|
|
else
|
|
|
|
$BUILD_CMD
|
2018-10-01 13:43:21 +00:00
|
|
|
if [ "$SANITIZER" = "coverage" ]; then
|
2018-08-22 14:20:09 +00:00
|
|
|
# Some directories have broken symlinks (e.g. honggfuzz), ignore the errors.
|
2019-01-14 21:01:16 +00:00
|
|
|
$COPY_SOURCES_CMD 2>/dev/null || true
|
2018-06-14 22:00:46 +00:00
|
|
|
fi
|
2016-12-21 23:01:44 +00:00
|
|
|
fi
|
2019-06-10 17:00:20 +00:00
|
|
|
|
|
|
|
if [[ "$FUZZING_ENGINE" = "dataflow" ]]; then
|
|
|
|
# Remove seed corpus as it can be huge but is not needed for a dataflow build.
|
2019-06-10 22:32:51 +00:00
|
|
|
rm -f $OUT/*.zip
|
2019-06-10 17:00:20 +00:00
|
|
|
fi
|