2016-10-07 19:05:55 +00:00
|
|
|
#!/bin/bash -eux
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
2020-08-13 19:58:02 +00:00
|
|
|
NPROC=16 # See issue #4270. The compiler crashes on GCB instance with 32 vCPUs.
|
2020-08-12 23:44:29 +00:00
|
|
|
|
2020-08-22 05:12:46 +00:00
|
|
|
LLVM_DEP_PACKAGES="build-essential make cmake ninja-build git python2.7 g++-multilib binutils-dev"
|
2016-10-07 19:05:55 +00:00
|
|
|
apt-get install -y $LLVM_DEP_PACKAGES
|
|
|
|
|
|
|
|
# Checkout
|
2018-07-27 21:19:32 +00:00
|
|
|
CHECKOUT_RETRIES=10
|
2019-11-22 21:21:29 +00:00
|
|
|
function clone_with_retries {
|
2018-07-27 21:19:32 +00:00
|
|
|
REPOSITORY=$1
|
|
|
|
LOCAL_PATH=$2
|
|
|
|
CHECKOUT_RETURN_CODE=1
|
|
|
|
|
|
|
|
# Disable exit on error since we might encounter some failures while retrying.
|
|
|
|
set +e
|
|
|
|
for i in $(seq 1 $CHECKOUT_RETRIES); do
|
|
|
|
rm -rf $LOCAL_PATH
|
2019-11-22 21:21:29 +00:00
|
|
|
git clone $REPOSITORY $LOCAL_PATH
|
2018-07-27 21:19:32 +00:00
|
|
|
CHECKOUT_RETURN_CODE=$?
|
|
|
|
if [ $CHECKOUT_RETURN_CODE -eq 0 ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Re-enable exit on error. If checkout failed, script will exit.
|
|
|
|
set -e
|
|
|
|
return $CHECKOUT_RETURN_CODE
|
|
|
|
}
|
2017-05-31 19:30:29 +00:00
|
|
|
|
2020-07-17 20:54:36 +00:00
|
|
|
function cmake_llvm {
|
|
|
|
extra_args="$@"
|
|
|
|
cmake -G "Ninja" \
|
|
|
|
-DLIBCXX_ENABLE_SHARED=OFF \
|
|
|
|
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \
|
|
|
|
-DLIBCXXABI_ENABLE_SHARED=OFF \
|
|
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
|
|
-DLLVM_TARGETS_TO_BUILD="$TARGET_TO_BUILD" \
|
|
|
|
-DLLVM_ENABLE_PROJECTS="$PROJECTS_TO_BUILD" \
|
2020-08-22 05:12:46 +00:00
|
|
|
-DLLVM_BINUTILS_INCDIR="/usr/include/" \
|
2020-07-17 20:54:36 +00:00
|
|
|
$extra_args \
|
|
|
|
$LLVM_SRC/llvm
|
|
|
|
}
|
|
|
|
|
2017-05-31 19:30:29 +00:00
|
|
|
# Use chromium's clang revision
|
|
|
|
mkdir $SRC/chromium_tools
|
|
|
|
cd $SRC/chromium_tools
|
|
|
|
git clone https://chromium.googlesource.com/chromium/src/tools/clang
|
|
|
|
cd clang
|
|
|
|
|
2019-11-22 21:21:29 +00:00
|
|
|
LLVM_SRC=$SRC/llvm-project
|
2020-05-14 00:07:18 +00:00
|
|
|
|
|
|
|
# For manual bumping.
|
2020-08-22 05:18:24 +00:00
|
|
|
OUR_LLVM_REVISION=llvmorg-12-init-1771-g1bd7046e
|
2020-05-14 00:07:18 +00:00
|
|
|
|
|
|
|
# To allow for manual downgrades. Set to 0 to use Chrome's clang version (i.e.
|
|
|
|
# *not* force a manual downgrade). Set to 1 to force a manual downgrade.
|
2020-08-22 05:18:24 +00:00
|
|
|
FORCE_OUR_REVISION=1
|
2020-08-07 03:12:58 +00:00
|
|
|
LLVM_REVISION=$(grep -Po "CLANG_REVISION = '\K([^']+)" scripts/update.py)
|
2017-10-11 15:19:21 +00:00
|
|
|
|
2019-11-22 21:21:29 +00:00
|
|
|
clone_with_retries https://github.com/llvm/llvm-project.git $LLVM_SRC
|
|
|
|
|
|
|
|
set +e
|
2020-05-14 00:07:18 +00:00
|
|
|
git -C $LLVM_SRC merge-base --is-ancestor $OUR_LLVM_REVISION $LLVM_REVISION
|
|
|
|
IS_OUR_REVISION_ANCESTOR_RETCODE=$?
|
2019-11-22 21:21:29 +00:00
|
|
|
set -e
|
|
|
|
|
2020-05-14 00:07:18 +00:00
|
|
|
# Use our revision if specified by FORCE_OUR_REVISION or if our revision is a
|
|
|
|
# later revision than Chrome's (i.e. not an ancestor of Chrome's).
|
|
|
|
if [ $IS_OUR_REVISION_ANCESTOR_RETCODE -ne 0 ] || [ $FORCE_OUR_REVISION -eq 1 ] ; then
|
2017-10-11 15:19:21 +00:00
|
|
|
LLVM_REVISION=$OUR_LLVM_REVISION
|
|
|
|
fi
|
|
|
|
|
2019-11-22 21:21:29 +00:00
|
|
|
git -C $LLVM_SRC checkout $LLVM_REVISION
|
2017-05-31 19:30:29 +00:00
|
|
|
echo "Using LLVM revision: $LLVM_REVISION"
|
|
|
|
|
2019-04-11 16:51:19 +00:00
|
|
|
# Build & install. We build clang in two stages because gcc can't build a
|
|
|
|
# static version of libcxxabi
|
|
|
|
# (see https://github.com/google/oss-fuzz/issues/2164).
|
|
|
|
mkdir -p $WORK/llvm-stage2 $WORK/llvm-stage1
|
|
|
|
cd $WORK/llvm-stage1
|
|
|
|
|
2019-02-20 05:16:46 +00:00
|
|
|
TARGET_TO_BUILD=
|
|
|
|
case $(uname -m) in
|
|
|
|
x86_64)
|
|
|
|
TARGET_TO_BUILD=X86
|
|
|
|
;;
|
|
|
|
aarch64)
|
|
|
|
TARGET_TO_BUILD=AArch64
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Error: unsupported target $(uname -m)"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2019-11-22 21:21:29 +00:00
|
|
|
|
2020-04-09 05:03:12 +00:00
|
|
|
PROJECTS_TO_BUILD="libcxx;libcxxabi;compiler-rt;clang;lld"
|
2020-08-22 05:12:46 +00:00
|
|
|
|
2020-07-17 20:54:36 +00:00
|
|
|
cmake_llvm
|
2020-08-12 23:44:29 +00:00
|
|
|
ninja -j $NPROC
|
2019-04-11 16:51:19 +00:00
|
|
|
|
|
|
|
cd $WORK/llvm-stage2
|
|
|
|
export CC=$WORK/llvm-stage1/bin/clang
|
|
|
|
export CXX=$WORK/llvm-stage1/bin/clang++
|
2020-07-17 20:54:36 +00:00
|
|
|
cmake_llvm
|
2020-08-12 23:44:29 +00:00
|
|
|
ninja -j $NPROC
|
2016-10-07 19:05:55 +00:00
|
|
|
ninja install
|
2019-04-11 16:51:19 +00:00
|
|
|
rm -rf $WORK/llvm-stage1 $WORK/llvm-stage2
|
2016-11-18 19:45:51 +00:00
|
|
|
|
2020-07-17 20:54:36 +00:00
|
|
|
# Use the clang we just built from now on.
|
|
|
|
CMAKE_EXTRA_ARGS="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++"
|
|
|
|
|
|
|
|
# 32-bit libraries.
|
2019-08-12 17:54:18 +00:00
|
|
|
mkdir -p $WORK/i386
|
|
|
|
cd $WORK/i386
|
2020-07-17 20:54:36 +00:00
|
|
|
cmake_llvm $CMAKE_EXTRA_ARGS \
|
|
|
|
-DCMAKE_INSTALL_PREFIX=/usr/i386/ \
|
|
|
|
-DCMAKE_C_FLAGS="-m32" \
|
|
|
|
-DCMAKE_CXX_FLAGS="-m32"
|
2019-05-13 22:01:25 +00:00
|
|
|
|
2020-08-12 23:44:29 +00:00
|
|
|
ninja -j $NPROC cxx
|
2019-05-13 22:01:25 +00:00
|
|
|
ninja install-cxx
|
2019-08-12 17:54:18 +00:00
|
|
|
rm -rf $WORK/i386
|
2019-05-13 22:01:25 +00:00
|
|
|
|
2020-07-17 20:54:36 +00:00
|
|
|
# MemorySanitizer instrumented libraries.
|
2016-08-15 22:24:03 +00:00
|
|
|
mkdir -p $WORK/msan
|
|
|
|
cd $WORK/msan
|
2018-02-06 23:51:47 +00:00
|
|
|
|
|
|
|
# https://github.com/google/oss-fuzz/issues/1099
|
|
|
|
cat <<EOF > $WORK/msan/blacklist.txt
|
|
|
|
fun:__gxx_personality_*
|
|
|
|
EOF
|
|
|
|
|
2020-07-17 20:54:36 +00:00
|
|
|
cmake_llvm $CMAKE_EXTRA_ARGS \
|
|
|
|
-DLLVM_USE_SANITIZER=Memory \
|
|
|
|
-DCMAKE_INSTALL_PREFIX=/usr/msan/ \
|
|
|
|
-DCMAKE_CXX_FLAGS="-fsanitize-blacklist=$WORK/msan/blacklist.txt"
|
|
|
|
|
2020-08-12 23:44:29 +00:00
|
|
|
ninja -j $NPROC cxx
|
2016-08-15 22:24:03 +00:00
|
|
|
ninja install-cxx
|
|
|
|
rm -rf $WORK/msan
|
|
|
|
|
2020-07-17 20:54:36 +00:00
|
|
|
# DataFlowSanitizer instrumented libraries.
|
|
|
|
mkdir -p $WORK/dfsan
|
|
|
|
cd $WORK/dfsan
|
|
|
|
|
|
|
|
cmake_llvm $CMAKE_EXTRA_ARGS \
|
|
|
|
-DLLVM_USE_SANITIZER=DataFlow \
|
|
|
|
-DCMAKE_INSTALL_PREFIX=/usr/dfsan/
|
|
|
|
|
2020-08-12 23:44:29 +00:00
|
|
|
ninja -j $NPROC cxx cxxabi
|
2020-07-17 20:54:36 +00:00
|
|
|
ninja install-cxx install-cxxabi
|
|
|
|
rm -rf $WORK/dfsan
|
|
|
|
|
|
|
|
# libFuzzer sources.
|
2019-11-22 21:21:29 +00:00
|
|
|
cp -r $LLVM_SRC/compiler-rt/lib/fuzzer $SRC/libfuzzer
|
2020-07-17 20:54:36 +00:00
|
|
|
|
2016-10-07 19:05:55 +00:00
|
|
|
# Cleanup
|
2019-11-22 21:21:29 +00:00
|
|
|
rm -rf $LLVM_SRC
|
2017-05-31 19:30:29 +00:00
|
|
|
rm -rf $SRC/chromium_tools
|
2016-10-07 19:05:55 +00:00
|
|
|
apt-get remove --purge -y $LLVM_DEP_PACKAGES
|
|
|
|
apt-get autoremove -y
|