From 342409126b46dd7a33dc55f02d398bc43ba6b53b Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Fri, 4 Jun 2021 11:06:38 +0100 Subject: [PATCH] Use modern clang/libc++ for sanitizers (#1171) * Use modern clang/libc++ for sanitizers * update ubuntu * new llvm builds differently * clang, not clang-3.8 * just build what we need --- .github/.libcxx-setup.sh | 24 ++++++++++++++++++++++++ .github/workflows/sanitizer.yml | 19 +++++++------------ .libcxx-setup.sh | 28 ---------------------------- 3 files changed, 31 insertions(+), 40 deletions(-) create mode 100755 .github/.libcxx-setup.sh delete mode 100755 .libcxx-setup.sh diff --git a/.github/.libcxx-setup.sh b/.github/.libcxx-setup.sh new file mode 100755 index 00000000..56008403 --- /dev/null +++ b/.github/.libcxx-setup.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Checkout LLVM sources +git clone --depth=1 https://github.com/llvm/llvm-project.git llvm-project + +# Setup libc++ options +if [ -z "$BUILD_32_BITS" ]; then + export BUILD_32_BITS=OFF && echo disabling 32 bit build +fi + +# Build and install libc++ (Use unstable ABI for better sanitizer coverage) +cd ./llvm-project +cmake -DCMAKE_C_COMPILER=${C_COMPILER} \ + -DCMAKE_CXX_COMPILER=${COMPILER} \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DLIBCXX_ABI_UNSTABLE=OFF \ + -DLLVM_USE_SANITIZER=${LIBCXX_SANITIZER} \ + -DLLVM_BUILD_32_BITS=${BUILD_32_BITS} \ + -DLLVM_ENABLE_PROJECTS='libcxx;libcxxabi' \ + -S llvm -B llvm-build -G "Unix Makefiles" +make -C llvm-build -j3 cxx cxxabi +sudo make -C llvm-build install-cxx install-cxxabi +cd .. diff --git a/.github/workflows/sanitizer.yml b/.github/workflows/sanitizer.yml index 9543e16f..fbc98449 100644 --- a/.github/workflows/sanitizer.yml +++ b/.github/workflows/sanitizer.yml @@ -5,15 +5,15 @@ on: pull_request: {} env: - CC: clang-3.8 - CXX: clang++-3.8 + CC: clang + CXX: clang++ EXTRA_CXX_FLAGS: "-stdlib=libc++" UBSAN_OPTIONS: "print_stacktrace=1" jobs: job: name: ${{ matrix.sanitizer }}.${{ matrix.build_type }} - runs-on: ubuntu-16.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -28,7 +28,7 @@ jobs: run: | echo "EXTRA_FLAGS=-g -O2 -fno-omit-frame-pointer -fsanitize=memory -fsanitize-memory-track-origins" >> $GITHUB_ENV echo "LIBCXX_SANITIZER=MemoryWithOrigins" >> $GITHUB_ENV - + - name: configure ubsan env if: matrix.sanitizer == 'ubsan' run: | @@ -47,13 +47,8 @@ jobs: echo "EXTRA_FLAGS=-g -O2 -fno-omit-frame-pointer -fsanitize=thread -fno-sanitize-recover=all" >> $GITHUB_ENV echo "LIBCXX_SANITIZER=Thread" >> $GITHUB_ENV - - name: install clang-3.8 - run: | - sudo apt update - sudo apt -y install clang-3.8 - - - name: install libc++ - run: "${GITHUB_WORKSPACE}/.libcxx-setup.sh" + - name: install llvm stuff + run: "${GITHUB_WORKSPACE}/.github/.libcxx-setup.sh" - name: create build environment run: cmake -E make_directory ${{ runner.workspace }}/_build @@ -76,7 +71,7 @@ jobs: shell: bash working-directory: ${{ runner.workspace }}/_build run: cmake --build . --config ${{ matrix.build_type }} - + - name: test shell: bash working-directory: ${{ runner.workspace }}/_build diff --git a/.libcxx-setup.sh b/.libcxx-setup.sh deleted file mode 100755 index 44146006..00000000 --- a/.libcxx-setup.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -# Install a newer CMake version -curl -sSL https://cmake.org/files/v3.6/cmake-3.6.1-Linux-x86_64.sh -o install-cmake.sh -chmod +x install-cmake.sh -sudo ./install-cmake.sh --prefix=/usr/local --skip-license - -# Checkout LLVM sources -git clone --depth=1 https://github.com/llvm-mirror/llvm.git llvm-source -git clone --depth=1 https://github.com/llvm-mirror/libcxx.git llvm-source/projects/libcxx -git clone --depth=1 https://github.com/llvm-mirror/libcxxabi.git llvm-source/projects/libcxxabi - -# Setup libc++ options -if [ -z "$BUILD_32_BITS" ]; then - export BUILD_32_BITS=OFF && echo disabling 32 bit build -fi - -# Build and install libc++ (Use unstable ABI for better sanitizer coverage) -mkdir llvm-build && cd llvm-build -cmake -DCMAKE_C_COMPILER=${C_COMPILER} -DCMAKE_CXX_COMPILER=${COMPILER} \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr \ - -DLIBCXX_ABI_UNSTABLE=OFF \ - -DLLVM_USE_SANITIZER=${LIBCXX_SANITIZER} \ - -DLLVM_BUILD_32_BITS=${BUILD_32_BITS} \ - ../llvm-source -make cxx -j2 -sudo make install-cxxabi install-cxx -cd ../