diff options
Diffstat (limited to 'infra/base-images/base-clang/checkout_build_install_llvm.sh')
-rwxr-xr-x | infra/base-images/base-clang/checkout_build_install_llvm.sh | 72 |
1 files changed, 61 insertions, 11 deletions
diff --git a/infra/base-images/base-clang/checkout_build_install_llvm.sh b/infra/base-images/base-clang/checkout_build_install_llvm.sh index c5d97d5bf..f6e8ca99c 100755 --- a/infra/base-images/base-clang/checkout_build_install_llvm.sh +++ b/infra/base-images/base-clang/checkout_build_install_llvm.sh @@ -15,10 +15,14 @@ # ################################################################################ -NPROC=16 # See issue #4270. The compiler crashes on GCB instance with 32 vCPUs. +# See issue #4270. The compiler crashes on GCB instance with 32 vCPUs, so when +# we compile on GCB we want 16 cores. But locally we want more (so use nproc / +# 2). +NPROC=$(expr $(nproc) / 2) -LLVM_DEP_PACKAGES="build-essential make cmake ninja-build git python3 g++-multilib binutils-dev" -apt-get install -y $LLVM_DEP_PACKAGES +# zlib1g-dev is needed for llvm-profdata to handle coverage data from rust compiler +LLVM_DEP_PACKAGES="build-essential make cmake ninja-build git python3 g++-multilib binutils-dev zlib1g-dev" +apt-get install -y $LLVM_DEP_PACKAGES --no-install-recommends # Checkout CHECKOUT_RETRIES=10 @@ -60,7 +64,7 @@ function cmake_llvm { # Use chromium's clang revision mkdir $SRC/chromium_tools cd $SRC/chromium_tools -git clone https://chromium.googlesource.com/chromium/src/tools/clang +git clone https://chromium.googlesource.com/chromium/src/tools/clang --depth 1 cd clang LLVM_SRC=$SRC/llvm-project @@ -89,11 +93,9 @@ fi git -C $LLVM_SRC checkout $LLVM_REVISION echo "Using LLVM revision: $LLVM_REVISION" -# 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). +# Build & install. mkdir -p $WORK/llvm-stage2 $WORK/llvm-stage1 -cd $WORK/llvm-stage1 +python3 $SRC/chromium_tools/clang/scripts/update.py --output-dir $WORK/llvm-stage1 TARGET_TO_BUILD= case $(uname -m) in @@ -111,9 +113,6 @@ esac PROJECTS_TO_BUILD="libcxx;libcxxabi;compiler-rt;clang;lld" -cmake_llvm -ninja -j $NPROC - cd $WORK/llvm-stage2 export CC=$WORK/llvm-stage1/bin/clang export CXX=$WORK/llvm-stage1/bin/clang++ @@ -175,3 +174,54 @@ rm -rf $LLVM_SRC rm -rf $SRC/chromium_tools apt-get remove --purge -y $LLVM_DEP_PACKAGES apt-get autoremove -y + +# Delete unneeded parts of LLVM to reduce image size. +# See https://github.com/google/oss-fuzz/issues/5170 +LLVM_TOOLS_TMPDIR=/tmp/llvm-tools +mkdir $LLVM_TOOLS_TMPDIR +# Move binaries with llvm- prefix that we want into LLVM_TOOLS_TMPDIR +mv \ + /usr/local/bin/llvm-ar \ + /usr/local/bin/llvm-as \ + /usr/local/bin/llvm-config \ + /usr/local/bin/llvm-cov \ + /usr/local/bin/llvm-objcopy \ + /usr/local/bin/llvm-profdata \ + /usr/local/bin/llvm-ranlib \ + /usr/local/bin/llvm-symbolizer \ + /usr/local/bin/llvm-undname \ + $LLVM_TOOLS_TMPDIR +# Delete remaining llvm- binaries. +rm -rf /usr/local/bin/llvm-* +# Restore the llvm- binaries we want to keep. +mv $LLVM_TOOLS_TMPDIR/* /usr/local/bin/ +rm -rf $LLVM_TOOLS_TMPDIR + +# Remove binaries from LLVM buld that we don't need. +rm -f \ + /usr/local/bin/bugpoint \ + /usr/local/bin/llc \ + /usr/local/bin/lli \ + /usr/local/bin/clang-check \ + /usr/local/bin/clang-refactor \ + /usr/local/bin/clang-offload-wrapper \ + /usr/local/bin/clang-offload-bundler \ + /usr/local/bin/clang-check \ + /usr/local/bin/clang-refactor \ + /usr/local/bin/c-index-test \ + /usr/local/bin/clang-rename \ + /usr/local/bin/clang-scan-deps \ + /usr/local/bin/clang-extdef-mapping \ + /usr/local/bin/diagtool \ + /usr/local/bin/sanstats \ + /usr/local/bin/dsymutil \ + /usr/local/bin/verify-uselistorder \ + /usr/local/bin/clang-format + +# Remove unneeded clang libs, CMake files from LLVM build, lld libs, and the +# libraries. +# Note: we need fuzzer_no_main libraries for atheris. Don't delete. +rm -rf \ + /usr/local/lib/libclang* \ + /usr/local/lib/liblld* \ + /usr/local/lib/cmake/ |