2017-08-23 21:17:03 +00:00
|
|
|
#!/bin/bash -eux
|
|
|
|
#
|
|
|
|
# Copyright 2017 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.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
2017-10-12 23:20:00 +00:00
|
|
|
build_protobuf() {
|
|
|
|
./autogen.sh
|
|
|
|
./configure --disable-shared
|
|
|
|
make -j $(nproc)
|
|
|
|
make check -j $(nproc)
|
|
|
|
make install
|
|
|
|
ldconfig
|
|
|
|
}
|
|
|
|
|
|
|
|
(cd protobuf-3.3.0 && build_protobuf)
|
2017-08-23 21:17:03 +00:00
|
|
|
|
2017-10-12 23:20:00 +00:00
|
|
|
readonly FUZZERS=( \
|
|
|
|
clang-fuzzer \
|
|
|
|
clang-proto-fuzzer \
|
|
|
|
clang-format-fuzzer \
|
2017-10-26 16:47:16 +00:00
|
|
|
clangd-fuzzer \
|
2017-10-13 18:40:39 +00:00
|
|
|
llvm-demangle-fuzzer \
|
2017-10-12 23:20:00 +00:00
|
|
|
llvm-dwarfdump-fuzzer \
|
|
|
|
llvm-isel-fuzzer \
|
2017-10-17 18:38:21 +00:00
|
|
|
llvm-special-case-list-fuzzer \
|
2017-11-13 22:43:56 +00:00
|
|
|
llvm-opt-fuzzer \
|
2017-10-12 23:20:00 +00:00
|
|
|
)
|
|
|
|
case $SANITIZER in
|
|
|
|
address) LLVM_SANITIZER="Address" ;;
|
|
|
|
undefined) LLVM_SANITIZER="Undefined" ;;
|
|
|
|
memory) LLVM_SANITIZER="MemoryWithOrigins" ;;
|
|
|
|
*) LLVM_SANITIZER="" ;;
|
|
|
|
esac
|
2017-08-23 21:17:03 +00:00
|
|
|
|
2017-10-12 23:20:00 +00:00
|
|
|
mkdir build
|
|
|
|
cd build
|
2017-08-23 21:17:03 +00:00
|
|
|
cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../llvm \
|
|
|
|
-DLLVM_ENABLE_ASSERTIONS=ON \
|
2017-10-12 23:20:00 +00:00
|
|
|
-DCMAKE_C_COMPILER="${CC}" \
|
|
|
|
-DCMAKE_CXX_COMPILER="${CXX}" \
|
|
|
|
-DCMAKE_C_FLAGS="${CFLAGS}" \
|
|
|
|
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
|
|
|
|
-DLLVM_LIB_FUZZING_ENGINE="${LIB_FUZZING_ENGINE}" \
|
2017-12-19 20:47:30 +00:00
|
|
|
-DLLVM_NO_DEAD_STRIP=ON \
|
2017-10-12 23:20:00 +00:00
|
|
|
-DCLANG_ENABLE_PROTO_FUZZER=ON \
|
|
|
|
-DLLVM_USE_SANITIZER="${LLVM_SANITIZER}"
|
|
|
|
for fuzzer in "${FUZZERS[@]}"; do
|
2017-08-29 01:45:58 +00:00
|
|
|
ninja $fuzzer
|
|
|
|
cp bin/$fuzzer $OUT
|
|
|
|
done
|
2017-12-18 15:25:06 +00:00
|
|
|
ninja llvm-as
|
2017-10-12 05:13:23 +00:00
|
|
|
|
2017-10-12 23:20:00 +00:00
|
|
|
# isel-fuzzer encodes its default flags in the name.
|
2017-10-16 21:02:49 +00:00
|
|
|
cp $OUT/llvm-isel-fuzzer $OUT/llvm-isel-fuzzer--aarch64-O2
|
2017-10-17 02:56:11 +00:00
|
|
|
cp $OUT/llvm-isel-fuzzer $OUT/llvm-isel-fuzzer--x86_64-O2
|
2017-10-13 00:40:47 +00:00
|
|
|
mv $OUT/llvm-isel-fuzzer $OUT/llvm-isel-fuzzer--aarch64-gisel
|
2017-11-13 22:43:56 +00:00
|
|
|
# Same for llvm-opt-fuzzer
|
2018-01-24 19:04:24 +00:00
|
|
|
cp $OUT/llvm-opt-fuzzer $OUT/llvm-opt-fuzzer--x86_64-earlycse
|
2018-01-26 15:35:53 +00:00
|
|
|
cp $OUT/llvm-opt-fuzzer $OUT/llvm-opt-fuzzer--x86_64-simplifycfg
|
2018-02-05 15:53:27 +00:00
|
|
|
cp $OUT/llvm-opt-fuzzer $OUT/llvm-opt-fuzzer--x86_64-gvn
|
2017-11-13 22:43:56 +00:00
|
|
|
mv $OUT/llvm-opt-fuzzer $OUT/llvm-opt-fuzzer--x86_64-instcombine
|
2017-12-18 15:25:06 +00:00
|
|
|
|
|
|
|
# Build corpus for the llvm-opt-fuzzer
|
|
|
|
function build_corpus {
|
|
|
|
local lit_path="${1}"
|
|
|
|
local fuzzer_name="${2}"
|
|
|
|
|
|
|
|
[[ -e "${WORK}/corpus-tmp" ]] && rm -r "${WORK}/corpus-tmp"
|
|
|
|
mkdir "${WORK}/corpus-tmp"
|
|
|
|
|
|
|
|
cd "${SRC}"
|
|
|
|
|
|
|
|
# Compile all lit tests into bitcode. Ignore possible llvm-as failures.
|
|
|
|
find "${lit_path}" -name "*.ll" -print0 |
|
|
|
|
xargs -t -i -0 -n1 sh -c "build/bin/llvm-as "{}" || true"
|
|
|
|
|
|
|
|
# Move freshly created bitcode into temp directory.
|
|
|
|
find "${lit_path}" -name "*.bc" -print0 |
|
|
|
|
xargs -t -i -0 -n1 mv "{}" "${WORK}/corpus-tmp"
|
|
|
|
|
|
|
|
# Archive the corpus.
|
|
|
|
zip -j "${OUT}/${fuzzer_name}_seed_corpus.zip" "${WORK}"/corpus-tmp/*
|
|
|
|
|
|
|
|
rm -r "${WORK}/corpus-tmp"
|
2018-01-17 15:55:14 +00:00
|
|
|
|
|
|
|
echo -e "[libfuzzer]\nmax_len = 0" > "${OUT}"/"${fuzzer_name}".options
|
2017-12-18 15:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
build_corpus "llvm/test/Transforms/InstCombine/" "llvm-opt-fuzzer--x86_64-instcombine"
|
2018-01-24 19:04:24 +00:00
|
|
|
build_corpus "llvm/test/Transforms/EarlyCSE/" "llvm-opt-fuzzer--x86_64-earlycse"
|
2018-01-26 15:35:53 +00:00
|
|
|
build_corpus "llvm/test/Transforms/SimplifyCFG/" "llvm-opt-fuzzer--x86_64-simplifycfg"
|
2018-02-05 15:53:27 +00:00
|
|
|
build_corpus "llvm/test/Transforms/GVN/" "llvm-opt-fuzzer--x86_64-gvn"
|