Skip to content

Commit

Permalink
Add memory sanitizer CI
Browse files Browse the repository at this point in the history
  • Loading branch information
vrabaud committed Jul 11, 2024
1 parent 508f00f commit 5936cde
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .github/actions/setup-common/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ runs:
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: '3.x'
- name: Set up CMake < 3.18
- name: Set up CMake < 3.20
if: ${{ runner.os == 'Linux' && inputs.recent-cmake == 'false' }}
uses: jwlawson/actions-setup-cmake@802fa1a2c4e212495c05bf94dba2704a92a472be # v2.0.2
with:
cmake-version: '3.13.x'
- name: Set up CMake >= 3.18
- name: Set up CMake >= 3.20
if: ${{ runner.os == 'Linux' && inputs.recent-cmake == 'true' }}
uses: jwlawson/actions-setup-cmake@802fa1a2c4e212495c05bf94dba2704a92a472be # v2.0.2
with:
cmake-version: '3.18.x'
cmake-version: '3.20.x'
- name: Print CMake version
run: cmake --version
shell: bash
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci-unix-shared-installed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# with an additional build configuration (using installed deps and dav1d).

name: CI Unix Shared Installed
on: [push, pull_request]
on:
push:
pull_request:
paths:
- '.github/workflows/ci-unix-shared-installed.yml'

permissions:
contents: read
Expand Down
74 changes: 44 additions & 30 deletions .github/workflows/ci-unix-static-sanitized.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
sanitizer: [ address, thread, undefined ] # TODO(yguyon): Add memory
os: [ubuntu-24.04, macos-latest]
sanitizer: [ address, memory, thread, undefined ]
exclude:
- os: macos-latest
sanitizer: memory

env:
CC: clang
Expand All @@ -45,41 +48,51 @@ jobs:
- id: cache-hit
run: echo "hit=${{ (runner.os == 'Linux' && steps.setup_linux.outputs.ext-cache-hit == 'true') || (runner.os == 'macOS' && steps.setup_macos.outputs.ext-cache-hit == 'true') }}" >> "$GITHUB_OUTPUT"

- name: Build aom
if: ${{ steps.cache-hit.outputs.hit == 'false' }}
working-directory: ./ext
run: >
sed -i -e 's/cmake -G Ninja \(.*\) \.\./cmake -G Ninja \1 -DSANITIZE=${{ matrix.sanitizer }} ../g' aom.cmd
./aom.cmd
- name: Build dav1d
if: ${{ steps.cache-hit.outputs.hit == 'false' }}
working-directory: ./ext
run: >
sed -i -e 's/meson setup \(.*\) \.\./meson setup \1 -Db_sanitize=${{ matrix.sanitizer }} -Db_lundef=false ../g' dav1d.cmd
./dav1d.cmd
- name: Build libyuv
if: ${{ steps.cache-hit.outputs.hit == 'false' }}
working-directory: ./ext
run: ./libyuv.cmd
env:
CFLAGS: -fsanitize=${{ matrix.sanitizer }}
CXXFLAGS: -fsanitize=${{ matrix.sanitizer }}
LDFLAGS: -fsanitize=${{ matrix.sanitizer }}
- name: Build cxx and cxxabi
if: ${{ matrix.sanitizer == 'memory' }}
run: |
# clone LLVM
git clone --depth=1 --branch llvmorg-18.1.8 https://github.com/llvm/llvm-project
# configure cmake
cmake -G Ninja -S llvm-project/runtimes -B llvm-project/msan_out \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DLLVM_USE_SANITIZER=MemoryWithOrigins
# build the libraries
cmake --build llvm-project/msan_out -- cxx cxxabi unwind
- name: Set FLAGS for memory sanitizer
if: ${{ matrix.sanitizer == 'memory' }}
run: |
echo "CI_CFLAGS=-fsanitize=memory -L${{ github.workspace }}/llvm-project/msan_out/lib -I${{ github.workspace }}/llvm-project/msan_out/include" >> $GITHUB_ENV
echo "CI_CXXFLAGS=-fsanitize=memory -stdlib=libc++ -L${{ github.workspace }}/llvm-project/msan_out/lib -I${{ github.workspace }}/llvm-project/msan_out/include -I${{ github.workspace }}/llvm-project/msan_out/include/c++/v1" >> $GITHUB_EN
echo "CI_LDLAGS=-fsanitize=memory -L${{ github.workspace }}/llvm-project/msan_out/lib -lc++abi" >> $GITHUB_ENV
echo "CI_LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${{ github.workspace }}/llvm-project/msan_out/lib" >> $GITHUB_ENV
- name: Set FLAGS for other sanitizers
if: ${{ matrix.sanitizer != 'memory' }}
run: |
echo "CI_CFLAGS=-fsanitize=${{ matrix.sanitizer }}" >> $GITHUB_ENV
echo "CI_CXXFLAGS=-fsanitize=${{ matrix.sanitizer }}" >> $GITHUB_ENV
echo "CI_LDFLAGS=-fsanitize=${{ matrix.sanitizer }}" >> $GITHUB_ENV
echo "CI_LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $GITHUB_ENV
- name: Build libsharpyuv
if: ${{ steps.cache-hit.outputs.hit == 'false' }}
working-directory: ./ext
run: ./libsharpyuv.cmd
env:
CFLAGS: -fsanitize=${{ matrix.sanitizer }}
CXXFLAGS: -fsanitize=${{ matrix.sanitizer }}
LDFLAGS: -fsanitize=${{ matrix.sanitizer }}
CFLAGS: ${{ env.CI_CFLAGS }}
CXXFLAGS: ${{ env.CI_CXXFLAGS }}
LDFLAGS: ${{ env.CI_LDFLAGS }}
- name: Build GoogleTest
if: ${{ steps.cache-hit.outputs.hit == 'false' }}
working-directory: ./ext
# Note: "apt install googletest" is sometimes insufficient for find_package(GTest) so build in ext/ instead.
run: bash -e googletest.cmd
env:
CFLAGS: ${{ env.CI_CFLAGS }}
CXXFLAGS: ${{ env.CI_CXXFLAGS }}
LDFLAGS: ${{ env.CI_LDFLAGS }}

- name: Prepare libavif (cmake)
run: >
Expand All @@ -90,9 +103,9 @@ jobs:
-DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_GTEST=LOCAL
env:
CFLAGS: -fsanitize=${{ matrix.sanitizer }}
CXXFLAGS: -fsanitize=${{ matrix.sanitizer }}
LDFLAGS: -fsanitize=${{ matrix.sanitizer }}
CFLAGS: ${{ env.CI_CFLAGS }}
CXXFLAGS: ${{ env.CI_CXXFLAGS }}
LDFLAGS: ${{ env.CI_LDFLAGS }}
- name: Build libavif (ninja)
working-directory: ./build
run: ninja
Expand All @@ -102,3 +115,4 @@ jobs:
env:
ASAN_OPTIONS: allocator_may_return_null=1
TSAN_OPTIONS: allocator_may_return_null=1
LD_LIBRARY_PATH: ${{ env.CI_LD_LIBRARY_PATH }}

0 comments on commit 5936cde

Please sign in to comment.