aboutsummaryrefslogtreecommitdiff
path: root/infra
diff options
context:
space:
mode:
authorjonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2021-03-18 06:38:46 -0700
committerGitHub <noreply@github.com>2021-03-18 06:38:46 -0700
commitccea7f4ad99adba7d17fe98e37dc80d6be1b7f29 (patch)
tree58da388fcfa9a4e45d0c79c56b784e06545eaf8e /infra
parent562e0b906ea355a1fb53725d68351536db68f6cf (diff)
downloadoss-fuzz-ccea7f4ad99adba7d17fe98e37dc80d6be1b7f29.tar.gz
[base-clang] Reduce base-clang size by deleting unneeded binaries+libraries (#5282)
Delete unneeded LLVM tools, clang libraries and testing tools. This reduces the image size from 1.71 GB to 901 MB. It may be possible to improve on this by deleting some LLVM libraries though I don't know which ones we should delete because AFL++ might use some). Related https://github.com/google/oss-fuzz/issues/5170
Diffstat (limited to 'infra')
-rwxr-xr-xinfra/base-images/base-clang/checkout_build_install_llvm.sh51
1 files changed, 51 insertions, 0 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 60429106b..f6e8ca99c 100755
--- a/infra/base-images/base-clang/checkout_build_install_llvm.sh
+++ b/infra/base-images/base-clang/checkout_build_install_llvm.sh
@@ -174,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/