2021-02-19 19:51:46 +00:00
|
|
|
#!/bin/bash -eu
|
|
|
|
# Copyright 2021 Google LLC
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
2023-03-20 15:04:25 +00:00
|
|
|
# Clean up potentially persistent build directory.
|
|
|
|
[[ -e $SRC/tarantool/build ]] && rm -rf $SRC/tarantool/build
|
2022-01-06 22:54:14 +00:00
|
|
|
|
2023-03-20 15:04:25 +00:00
|
|
|
# Build ICU for linking statically.
|
|
|
|
mkdir -p $SRC/tarantool/build/icu && cd $SRC/tarantool/build/icu
|
2022-01-06 22:54:14 +00:00
|
|
|
|
2023-03-20 15:04:25 +00:00
|
|
|
[ ! -e config.status ] && LDFLAGS="-lpthread" CXXFLAGS="$CXXFLAGS -lpthread" \
|
|
|
|
$SRC/icu/source/configure --disable-shared --enable-static --disable-layoutex \
|
|
|
|
--disable-tests --disable-samples --with-data-packaging=static
|
|
|
|
make install -j$(nproc)
|
2022-01-06 22:54:14 +00:00
|
|
|
|
|
|
|
cd $SRC/tarantool
|
|
|
|
|
2022-11-24 23:31:33 +00:00
|
|
|
# Avoid compilation issue due to some undefined references. They are defined in
|
|
|
|
# libc++ and used by Centipede so -lc++ needs to come after centipede's lib.
|
|
|
|
if [[ $FUZZING_ENGINE == centipede ]]
|
|
|
|
then
|
|
|
|
sed -i \
|
|
|
|
'/$ENV{LIB_FUZZING_ENGINE}/a \ \ \ \ \ \ \ \ -lc++' \
|
|
|
|
test/fuzz/CMakeLists.txt
|
|
|
|
fi
|
2022-01-06 22:54:14 +00:00
|
|
|
|
2021-02-19 19:51:46 +00:00
|
|
|
case $SANITIZER in
|
|
|
|
address) SANITIZERS_ARGS="-DENABLE_ASAN=ON" ;;
|
|
|
|
undefined) SANITIZERS_ARGS="-DENABLE_UB_SANITIZER=ON" ;;
|
|
|
|
*) SANITIZERS_ARGS="" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
: ${LD:="${CXX}"}
|
|
|
|
: ${LDFLAGS:="${CXXFLAGS}"} # to make sure we link with sanitizer runtime
|
|
|
|
|
|
|
|
cmake_args=(
|
|
|
|
# Specific to Tarantool
|
2022-01-10 15:37:56 +00:00
|
|
|
-DENABLE_BACKTRACE=OFF
|
2021-02-19 19:51:46 +00:00
|
|
|
-DENABLE_FUZZER=ON
|
|
|
|
-DOSS_FUZZ=ON
|
|
|
|
$SANITIZERS_ARGS
|
|
|
|
|
|
|
|
# C compiler
|
|
|
|
-DCMAKE_C_COMPILER="${CC}"
|
|
|
|
-DCMAKE_C_FLAGS="${CFLAGS}"
|
|
|
|
|
|
|
|
# C++ compiler
|
|
|
|
-DCMAKE_CXX_COMPILER="${CXX}"
|
|
|
|
-DCMAKE_CXX_FLAGS="${CXXFLAGS}"
|
|
|
|
|
|
|
|
# Linker
|
|
|
|
-DCMAKE_LINKER="${LD}"
|
|
|
|
-DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}"
|
|
|
|
-DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}"
|
|
|
|
-DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}"
|
2022-11-17 20:19:44 +00:00
|
|
|
|
|
|
|
# Dependencies
|
|
|
|
-DENABLE_BUNDLED_LIBCURL=OFF
|
|
|
|
-DENABLE_BUNDLED_LIBUNWIND=OFF
|
|
|
|
-DENABLE_BUNDLED_ZSTD=OFF
|
2021-02-19 19:51:46 +00:00
|
|
|
)
|
|
|
|
|
2023-03-20 15:04:25 +00:00
|
|
|
# To deal with a host filesystem from inside of container.
|
|
|
|
git config --global --add safe.directory '*'
|
|
|
|
|
2021-02-19 19:51:46 +00:00
|
|
|
# Build the project and fuzzers.
|
|
|
|
[[ -e build ]] && rm -rf build
|
2022-11-16 13:32:55 +00:00
|
|
|
cmake "${cmake_args[@]}" -S . -B build -G Ninja
|
|
|
|
cmake --build build --target fuzzers --parallel
|
2021-02-19 19:51:46 +00:00
|
|
|
|
|
|
|
# Archive and copy to $OUT seed corpus if the build succeeded.
|
2023-03-20 15:04:25 +00:00
|
|
|
for f in $(find build/test/fuzz/ -name '*_fuzzer' -type f);
|
2021-02-19 19:51:46 +00:00
|
|
|
do
|
|
|
|
name=$(basename $f);
|
|
|
|
module=$(echo $name | sed 's/_fuzzer//')
|
|
|
|
corpus_dir="test/static/corpus/$module"
|
|
|
|
echo "Copying for $module";
|
|
|
|
cp $f $OUT/
|
|
|
|
[[ -e $corpus_dir ]] && zip -j $OUT/"$module"_fuzzer_seed_corpus.zip $corpus_dir/*
|
|
|
|
done
|