From 05bafd4fcf14411a55a0d868eaf3408c1f4ef012 Mon Sep 17 00:00:00 2001 From: Max Moroz Date: Fri, 17 Jul 2020 13:54:36 -0700 Subject: [PATCH] [infra] Build libc++ and libc++abi with DFSan (#3388, #1632). (#4153) * [infra] Build libc++ and libc++abi with DFSan (#3388, #1632). * create a common function to reduce code duplication --- .../base-clang/checkout_build_install_llvm.sh | 69 ++++++++++++------- 1 file changed, 43 insertions(+), 26 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 44e512b7e..c733eb3ac 100755 --- a/infra/base-images/base-clang/checkout_build_install_llvm.sh +++ b/infra/base-images/base-clang/checkout_build_install_llvm.sh @@ -41,6 +41,19 @@ function clone_with_retries { return $CHECKOUT_RETURN_CODE } +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" \ + $extra_args \ + $LLVM_SRC/llvm +} + # Use chromium's clang revision mkdir $SRC/chromium_tools cd $SRC/chromium_tools @@ -94,40 +107,33 @@ case $(uname -m) in esac PROJECTS_TO_BUILD="libcxx;libcxxabi;compiler-rt;clang;lld" -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 \ - $LLVM_SRC/llvm +cmake_llvm ninja cd $WORK/llvm-stage2 export CC=$WORK/llvm-stage1/bin/clang export CXX=$WORK/llvm-stage1/bin/clang++ -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 \ - $LLVM_SRC/llvm +cmake_llvm ninja ninja install rm -rf $WORK/llvm-stage1 $WORK/llvm-stage2 +# Use the clang we just built from now on. +CMAKE_EXTRA_ARGS="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++" + +# 32-bit libraries. mkdir -p $WORK/i386 cd $WORK/i386 -cmake -G "Ninja" \ - -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ - -DCMAKE_INSTALL_PREFIX=/usr/i386/ -DLIBCXX_ENABLE_SHARED=OFF \ - -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_C_FLAGS="-m32" -DCMAKE_CXX_FLAGS="-m32" \ - -DLLVM_TARGETS_TO_BUILD="$TARGET_TO_BUILD" \ - -DLLVM_ENABLE_PROJECTS=$PROJECTS_TO_BUILD \ - $LLVM_SRC/llvm +cmake_llvm $CMAKE_EXTRA_ARGS \ + -DCMAKE_INSTALL_PREFIX=/usr/i386/ \ + -DCMAKE_C_FLAGS="-m32" \ + -DCMAKE_CXX_FLAGS="-m32" ninja cxx ninja install-cxx rm -rf $WORK/i386 +# MemorySanitizer instrumented libraries. mkdir -p $WORK/msan cd $WORK/msan @@ -136,19 +142,30 @@ cat < $WORK/msan/blacklist.txt fun:__gxx_personality_* EOF -cmake -G "Ninja" \ - -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ - -DLLVM_USE_SANITIZER=Memory -DCMAKE_INSTALL_PREFIX=/usr/msan/ \ - -DLIBCXX_ENABLE_SHARED=OFF -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \ - -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="$TARGET_TO_BUILD" \ - -DCMAKE_CXX_FLAGS="-fsanitize-blacklist=$WORK/msan/blacklist.txt" \ - -DLLVM_ENABLE_PROJECTS=$PROJECTS_TO_BUILD \ - $LLVM_SRC/llvm +cmake_llvm $CMAKE_EXTRA_ARGS \ + -DLLVM_USE_SANITIZER=Memory \ + -DCMAKE_INSTALL_PREFIX=/usr/msan/ \ + -DCMAKE_CXX_FLAGS="-fsanitize-blacklist=$WORK/msan/blacklist.txt" + ninja cxx ninja install-cxx rm -rf $WORK/msan +# DataFlowSanitizer instrumented libraries. +mkdir -p $WORK/dfsan +cd $WORK/dfsan + +cmake_llvm $CMAKE_EXTRA_ARGS \ + -DLLVM_USE_SANITIZER=DataFlow \ + -DCMAKE_INSTALL_PREFIX=/usr/dfsan/ + +ninja cxx cxxabi +ninja install-cxx install-cxxabi +rm -rf $WORK/dfsan + +# libFuzzer sources. cp -r $LLVM_SRC/compiler-rt/lib/fuzzer $SRC/libfuzzer + # Cleanup rm -rf $LLVM_SRC rm -rf $SRC/chromium_tools