Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Sanitizers options and usage #2370

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ concurrency:
jobs:
libmamba_static:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.sanitizer != 'no_sanitizer' }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
sanitizer: [ no_sanitizer, asan, ubsan, tsan ]
steps:
- uses: actions/checkout@v3
- name: create build environment
Expand All @@ -40,6 +42,9 @@ jobs:
-DBUILD_STATIC=ON \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DENABLE_ASAN=${{ matrix.sanitizer == 'asan' && 'ON' || 'OFF' }} \
-DENABLE_TSAN=${{ matrix.sanitizer == 'tsan' && 'ON' || 'OFF' }} \
-DENABLE_UBSAN=${{ matrix.sanitizer == 'ubsan' && 'ON' || 'OFF' }} \
-GNinja
ninja
- name: build cache statistics
Expand All @@ -54,9 +59,11 @@ jobs:
libmamba_cpp_tests:
needs: [libmamba_static]
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.sanitizer != 'no_sanitizer' }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
sanitizer: [ no_sanitizer, asan, ubsan, tsan ]
steps:
- uses: actions/checkout@v3
- name: create build environment
Expand All @@ -82,6 +89,9 @@ jobs:
-DBUILD_LIBMAMBA_TESTS=ON \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DENABLE_ASAN=${{ matrix.sanitizer == 'asan' && 'ON' || 'OFF' }} \
-DENABLE_TSAN=${{ matrix.sanitizer == 'tsan' && 'ON' || 'OFF' }} \
-DENABLE_UBSAN=${{ matrix.sanitizer == 'ubsan' && 'ON' || 'OFF' }} \
-GNinja
ninja testing_libmamba_lock
ninja test
Expand All @@ -97,9 +107,11 @@ jobs:
umamba_tests:
needs: [libmamba_static]
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.sanitizer != 'no_sanitizer' }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
sanitizer: [ no_sanitizer, asan, ubsan, tsan ]
steps:
- uses: actions/checkout@v3
- name: create build environment
Expand All @@ -126,6 +138,9 @@ jobs:
-DBUILD_SHARED=ON \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DENABLE_ASAN=${{ matrix.sanitizer == 'asan' && 'ON' || 'OFF' }} \
-DENABLE_TSAN=${{ matrix.sanitizer == 'tsan' && 'ON' || 'OFF' }} \
-DENABLE_UBSAN=${{ matrix.sanitizer == 'ubsan' && 'ON' || 'OFF' }} \
-GNinja
ninja
- name: build cache statistics
Expand Down Expand Up @@ -156,9 +171,11 @@ jobs:
mamba_python_tests:
needs: [libmamba_static]
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.sanitizer != 'no_sanitizer' }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
sanitizer: [ no_sanitizer, asan, ubsan, tsan ]
python_version: ["3.8"]

steps:
Expand Down Expand Up @@ -194,6 +211,9 @@ jobs:
-DBUILD_MAMBA_PACKAGE=ON \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DENABLE_ASAN=${{ matrix.sanitizer == 'asan' && 'ON' || 'OFF' }} \
-DENABLE_TSAN=${{ matrix.sanitizer == 'tsan' && 'ON' || 'OFF' }} \
-DENABLE_UBSAN=${{ matrix.sanitizer == 'ubsan' && 'ON' || 'OFF' }} \
-GNinja
ninja
ninja install
Expand Down
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@ if (MSVC)
# add_definitions("-DUNICODE -D_UNICODE")
endif()


option(ENABLE_ASAN "Enable Address-Sanitizer (currently only supported on GCC and Clang)" OFF)
option(ENABLE_TSAN "Enable Thread-Sanitizer (currently only supported on GCC and Clang)" OFF)
option(ENABLE_UBSAN "Enable Undefined-Behavior-Sanitizer (currently only supported on GCC and Clang)" OFF)

if(ENABLE_ASAN)
message(WARNING "Address-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
set(SANITIZER_FLAGS ${SANITIZER_FLAGS} -fno-omit-frame-pointer -fsanitize=address)
endif()

if(ENABLE_TSAN)
message(WARNING "Thread-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
set(SANITIZER_FLAGS ${SANITIZER_FLAGS} -fno-omit-frame-pointer -fsanitize=thread)
endif()

if(ENABLE_UBSAN)
message(WARNING "Undefined-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
set(SANITIZER_FLAGS ${SANITIZER_FLAGS} -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all)
endif()

if(SANITIZER_FLAGS)
add_compile_options(${SANITIZER_FLAGS})
add_link_options(${SANITIZER_FLAGS})
if(BUILD_STATIC)
# This is necessary because add_link_options() only pass flags to linker, not static cases
set(STATIC_LIBRARY_FLAGS ${STATIC_LIBRARY_FLAGS} ${SANITIZER_FLAGS})
endif()
endif()


# Variants
# ========

Expand Down
21 changes: 0 additions & 21 deletions libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,6 @@ if (WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif ()

option(ENABLE_ASAN "Enable Address-Sanitizer (currently only supported on GCC and Clang)" OFF)

if(ENABLE_ASAN)
message(WARNING "Address-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
add_compile_options(-fno-omit-frame-pointer -fsanitize=address)
add_link_options(-fno-omit-frame-pointer -fsanitize=address)
endif()

if(ENABLE_TSAN)
message(WARNING "Thread-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
add_compile_options(-fno-omit-frame-pointer -fsanitize=thread)
add_link_options(-fno-omit-frame-pointer -fsanitize=thread)
endif()

if(ENABLE_USAN)
message(WARNING "Undefined-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
add_compile_options(-fno-omit-frame-pointer -fsanitize=undefined)
add_link_options(-fno-omit-frame-pointer -fsanitize=undefined)
endif()


# Source files
# ============

Expand Down
1 change: 1 addition & 0 deletions micromamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ else ()
set(MICROMAMBA_LINKAGE "DYNAMIC" CACHE STRING "micromamba linkage against libraries")
endif ()


# Source files
# ============

Expand Down