From c19eae50b8dab42ee94ea48253ab2ceae27eb753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Lamotte=20=28Klaim=29?= Date: Thu, 9 Mar 2023 15:40:04 +0100 Subject: [PATCH 1/7] ASAN option fixed --- libmamba/CMakeLists.txt | 5 +++++ micromamba/CMakeLists.txt | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/libmamba/CMakeLists.txt b/libmamba/CMakeLists.txt index 20c4c54053..5b42d588fa 100644 --- a/libmamba/CMakeLists.txt +++ b/libmamba/CMakeLists.txt @@ -69,6 +69,11 @@ 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) + 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} -fsanitize=address) + endif() + endif() if(ENABLE_TSAN) diff --git a/micromamba/CMakeLists.txt b/micromamba/CMakeLists.txt index 199a7659c3..23c7306908 100644 --- a/micromamba/CMakeLists.txt +++ b/micromamba/CMakeLists.txt @@ -19,6 +19,33 @@ else () set(MICROMAMBA_LINKAGE "DYNAMIC" CACHE STRING "micromamba linkage against libraries") 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) + 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} -fsanitize=address) + endif() + +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 # ============ From 4bccaf5276b43ee4084115c46fd40d0fe733eba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Lamotte=20=28Klaim=29?= Date: Fri, 10 Mar 2023 16:42:08 +0100 Subject: [PATCH 2/7] Improved ASAN support --- CMakeLists.txt | 28 ++++++++++++++++++++++++++++ libmamba/CMakeLists.txt | 26 -------------------------- micromamba/CMakeLists.txt | 26 -------------------------- 3 files changed, 28 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34614d8b6b..a09ec52508 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,34 @@ if (MSVC) # add_definitions("-DUNICODE -D_UNICODE") 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) + 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} -fno-omit-frame-pointer -fsanitize=address) + endif() + +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() + + + # Variants # ======== diff --git a/libmamba/CMakeLists.txt b/libmamba/CMakeLists.txt index 5b42d588fa..08686844b5 100644 --- a/libmamba/CMakeLists.txt +++ b/libmamba/CMakeLists.txt @@ -63,32 +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) - 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} -fsanitize=address) - endif() - -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 # ============ diff --git a/micromamba/CMakeLists.txt b/micromamba/CMakeLists.txt index 23c7306908..cf1ef61165 100644 --- a/micromamba/CMakeLists.txt +++ b/micromamba/CMakeLists.txt @@ -20,32 +20,6 @@ else () 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) - 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} -fsanitize=address) - endif() - -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 # ============ From 7a3a657c1a20dfee585c39220a65ca9784008dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Lamotte=20=28Klaim=29?= Date: Fri, 10 Mar 2023 18:20:47 +0100 Subject: [PATCH 3/7] ci: add ASAN builds and tests for ubuntu/macos --- .github/workflows/main.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cff0012c29..8209ce0023 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,6 +18,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] + address-sanitizer: [ OFF, ON ] steps: - uses: actions/checkout@v3 - name: create build environment @@ -40,6 +41,7 @@ jobs: -DBUILD_STATIC=ON \ -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ -DCMAKE_C_COMPILER_LAUNCHER=sccache \ + -DENABLE_ASAN=${{ matrix.address-sanitizer }} \ -GNinja ninja - name: build cache statistics @@ -57,6 +59,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] + address-sanitizer: [ OFF, ON ] steps: - uses: actions/checkout@v3 - name: create build environment @@ -82,6 +85,7 @@ jobs: -DBUILD_LIBMAMBA_TESTS=ON \ -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ -DCMAKE_C_COMPILER_LAUNCHER=sccache \ + -DENABLE_ASAN=${{ matrix.address-sanitizer }} \ -GNinja ninja testing_libmamba_lock ninja test @@ -100,6 +104,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] + address-sanitizer: [ OFF, ON ] steps: - uses: actions/checkout@v3 - name: create build environment @@ -126,6 +131,7 @@ jobs: -DBUILD_SHARED=ON \ -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ -DCMAKE_C_COMPILER_LAUNCHER=sccache \ + -DENABLE_ASAN=${{ matrix.address-sanitizer }} \ -GNinja ninja - name: build cache statistics @@ -159,6 +165,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] + address-sanitizer: [ OFF, ON ] python_version: ["3.8"] steps: @@ -194,6 +201,7 @@ jobs: -DBUILD_MAMBA_PACKAGE=ON \ -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ -DCMAKE_C_COMPILER_LAUNCHER=sccache \ + -DENABLE_ASAN=${{ matrix.address-sanitizer }} \ -GNinja ninja ninja install From 0432246e02f82b3c10dd8972d5c9d7309e945bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Lamotte=20=28Klaim=29?= Date: Wed, 15 Mar 2023 16:29:10 +0100 Subject: [PATCH 4/7] Fixed TSAN and UBSAN definitions --- CMakeLists.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a09ec52508..71793093d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,12 +52,20 @@ 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) + 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} -fno-omit-frame-pointer -fsanitize=thread) + endif() endif() -if(ENABLE_USAN) +if(ENABLE_UBSAN) 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) + add_compile_options(-fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) + add_link_options(-fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) + 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} -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) + endif() endif() From 7c24e6d2d55a6f1c6f1cf042fac377deecb88b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Lamotte=20=28Klaim=29?= Date: Wed, 15 Mar 2023 16:38:14 +0100 Subject: [PATCH 5/7] ci: added the 2 other sanitizers to the CI --- .github/workflows/main.yml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8209ce0023..503cf3e646 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - address-sanitizer: [ OFF, ON ] + sanitizer: [ no_sanitizer, asan, ubsan, tsan ] steps: - uses: actions/checkout@v3 - name: create build environment @@ -41,7 +41,9 @@ jobs: -DBUILD_STATIC=ON \ -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ -DCMAKE_C_COMPILER_LAUNCHER=sccache \ - -DENABLE_ASAN=${{ matrix.address-sanitizer }} \ + -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 @@ -59,7 +61,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - address-sanitizer: [ OFF, ON ] + sanitizer: [ no_sanitizer, asan, ubsan, tsan ] steps: - uses: actions/checkout@v3 - name: create build environment @@ -85,7 +87,9 @@ jobs: -DBUILD_LIBMAMBA_TESTS=ON \ -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ -DCMAKE_C_COMPILER_LAUNCHER=sccache \ - -DENABLE_ASAN=${{ matrix.address-sanitizer }} \ + -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 @@ -104,7 +108,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - address-sanitizer: [ OFF, ON ] + sanitizer: [ no_sanitizer, asan, ubsan, tsan ] steps: - uses: actions/checkout@v3 - name: create build environment @@ -131,7 +135,9 @@ jobs: -DBUILD_SHARED=ON \ -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ -DCMAKE_C_COMPILER_LAUNCHER=sccache \ - -DENABLE_ASAN=${{ matrix.address-sanitizer }} \ + -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 @@ -165,7 +171,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - address-sanitizer: [ OFF, ON ] + sanitizer: [ no_sanitizer, asan, ubsan, tsan ] python_version: ["3.8"] steps: @@ -201,7 +207,9 @@ jobs: -DBUILD_MAMBA_PACKAGE=ON \ -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ -DCMAKE_C_COMPILER_LAUNCHER=sccache \ - -DENABLE_ASAN=${{ matrix.address-sanitizer }} \ + -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 From b3f7e963976d11081a96522dfff9ccdfb586f5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Lamotte=20=28Klaim=29?= Date: Wed, 15 Mar 2023 16:45:19 +0100 Subject: [PATCH 6/7] ci: continue on error if build is with sanitizer --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 503cf3e646..84366c2325 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,6 +15,7 @@ concurrency: jobs: libmamba_static: runs-on: ${{ matrix.os }} + continue-on-error: ${{ matrix.sanitizer != 'no_sanitizer' }} strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -58,6 +59,7 @@ 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] @@ -105,6 +107,7 @@ jobs: umamba_tests: needs: [libmamba_static] runs-on: ${{ matrix.os }} + continue-on-error: ${{ matrix.sanitizer != 'no_sanitizer' }} strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -168,6 +171,7 @@ 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] From 81b03bdfd7c7e048702d0407406ae4e53871105a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Lamotte=20=28Klaim=29?= Date: Wed, 15 Mar 2023 18:18:01 +0100 Subject: [PATCH 7/7] Refactored sanitizer options definitions. --- CMakeLists.txt | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71793093d2..a2018d29fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,40 +36,34 @@ 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") - add_compile_options(-fno-omit-frame-pointer -fsanitize=address) - add_link_options(-fno-omit-frame-pointer -fsanitize=address) - 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} -fno-omit-frame-pointer -fsanitize=address) - endif() - + 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") - add_compile_options(-fno-omit-frame-pointer -fsanitize=thread) - add_link_options(-fno-omit-frame-pointer -fsanitize=thread) - 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} -fno-omit-frame-pointer -fsanitize=thread) - endif() + 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") - add_compile_options(-fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) - add_link_options(-fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) + 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} -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) + set(STATIC_LIBRARY_FLAGS ${STATIC_LIBRARY_FLAGS} ${SANITIZER_FLAGS}) endif() endif() - # Variants # ========