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 Dec 9, 2024
1 parent 3196438 commit b94793a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 30 deletions.
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
72 changes: 43 additions & 29 deletions .github/workflows/ci-unix-static-sanitized.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
sanitizer: [address, thread, undefined] # TODO(yguyon): Add memory
sanitizer: [address, memory, thread, undefined]
exclude:
- os: macos-latest
sanitizer: memory

env:
CC: clang
Expand All @@ -44,41 +47,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_ENV
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 @@ -89,9 +102,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 @@ -101,3 +114,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 b94793a

Please sign in to comment.