From ed83f204854700465637ee329bde26dc4a31f713 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 15:23:12 +0100 Subject: [PATCH 01/17] [eclipse-iceoryx#957] Refactor cmake to support sanitizers as a string Signed-off-by: Ziad Mostafa --- .../modules/Iceoryx2CommonOptionsAndParams.cmake | 7 ++++--- .../modules/Iceoryx2Sanitizer.cmake | 16 ++++++++++++++-- .../modules/Iceoryx2PlatformSettings.cmake | 2 +- .../mac/modules/Iceoryx2PlatformSettings.cmake | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/iceoryx2-cmake-modules/modules/Iceoryx2CommonOptionsAndParams.cmake b/iceoryx2-cmake-modules/modules/Iceoryx2CommonOptionsAndParams.cmake index b52d3a954b..c6ba63ea41 100644 --- a/iceoryx2-cmake-modules/modules/Iceoryx2CommonOptionsAndParams.cmake +++ b/iceoryx2-cmake-modules/modules/Iceoryx2CommonOptionsAndParams.cmake @@ -29,10 +29,11 @@ if(NOT ICEORYX2_COMMON_OPTIONS_AND_PARAMS_LISTED) DEFAULT_VALUE OFF ) - add_option( + add_param( NAME SANITIZERS - DESCRIPTION "Build with undefined-behavior- and address-sanitizer" - DEFAULT_VALUE OFF + TYPE STRING + DESCRIPTION "Sanitizer configuration: 'address', 'ub', 'address;ub', or 'thread'" + DEFAULT_VALUE "" ) add_option( diff --git a/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake b/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake index 07ea7d2e34..d9aa3e47e9 100644 --- a/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake +++ b/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake @@ -10,5 +10,17 @@ # # SPDX-License-Identifier: Apache-2.0 OR MIT -# TODO #957: differentiate between address and thread sanitizer -set(ICEORYX2_SANITZER_FLAGS -fsanitize=address -fsanitize=undefined CACHE INTERNAL "") +# Parse SANITIZERS string and set appropriate flags +set(ICEORYX2_SANITZER_FLAGS "" CACHE INTERNAL "") + +if(SANITIZERS STREQUAL "address") + set(ICEORYX2_SANITZER_FLAGS -fsanitize=address CACHE INTERNAL "") +elseif(SANITIZERS STREQUAL "ub") + set(ICEORYX2_SANITZER_FLAGS -fsanitize=undefined CACHE INTERNAL "") +elseif(SANITIZERS STREQUAL "address;ub") + set(ICEORYX2_SANITZER_FLAGS -fsanitize=address -fsanitize=undefined CACHE INTERNAL "") +elseif(SANITIZERS STREQUAL "thread") + set(ICEORYX2_SANITZER_FLAGS -fsanitize=thread CACHE INTERNAL "") +elseif(NOT SANITIZERS STREQUAL "") + message(FATAL_ERROR "Invalid SANITIZERS value: '${SANITIZERS}'. Valid options are: 'address', 'ub', 'address;ub', or 'thread'") +endif() diff --git a/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake b/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake index 8a1c05b3d5..9513142547 100644 --- a/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake +++ b/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake @@ -36,7 +36,7 @@ if(WARNING_AS_ERROR) endif() set(ICEORYX2_SANITZER_FLAGS CACHE INTERNAL "") -if(SANITIZERS) +if(NOT SANITIZERS STREQUAL "") include(Iceoryx2Sanitizer) endif() diff --git a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake index aa65265cb5..0f2b9578c2 100644 --- a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake +++ b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake @@ -35,7 +35,7 @@ if(WARNING_AS_ERROR) set(ICEORYX2_CXX_WARNINGS ${ICEORYX2_CXX_WARNINGS} -Werror CACHE INTERNAL "") endif() -if(SANITIZERS) +if(NOT SANITIZERS STREQUAL "") include(Iceoryx2Sanitizer) set(ICEORYX2_CXX_FLAGS "${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS}" CACHE INTERNAL "") From 4baae3e4875c58f309e23ee70a13cd92b8bac476 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 15:32:29 +0100 Subject: [PATCH 02/17] [eclipse-iceoryx#957] Add new CI job for running sanitizers Signed-off-by: Ziad Mostafa --- .github/workflows/build-test.yml | 100 +++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 6353bc55fa..fdb5ae5277 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -677,6 +677,105 @@ jobs: USE_BAZEL_VERSION: "7.4.1" run: bazel test //... + sanitizers: + needs: [preflight-check, static-code-analysis, cargo-nextest] + if: ${{ needs.changes.outputs.source-code == 'true' }} + strategy: + matrix: + os: [ubuntu-latest] + toolchain: [stable] + sanitizer: ["address", "ub", "address;ub", "thread"] + timeout-minutes: 60 + runs-on: ${{ matrix.os }} + steps: + - name: Checkout sources + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 + + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v2 + with: + cmake-version: "3.31.x" + + - name: Use cmake + run: cmake --version + + - name: Setup Rust + uses: dtolnay/rust-toolchain@888c2e1ea69ab0d4330cbf0af1ecc7b68f368cc1 # ratchet:dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ matrix.toolchain }} + components: rustfmt, clippy + + - name: Download artifact cargo-nextest + uses: ./.github/actions/download-cached-rust-tool + with: + artifact-bin-name: cargo-nextest + artifact-upload-name: ${{ runner.os }}-cargo-nextest + + - name: Prepare Linux + run: | + internal/scripts/ci_prepare_ubuntu.sh + uname -a + + - name: Run cargo build + run: cargo build --workspace --all-targets + + - name: Run cargo nextest + run: cargo nextest run --workspace --all-targets --no-fail-fast + + - name: Build iceoryx_hoofs + run: internal/scripts/ci_build_and_install_iceoryx_hoofs.sh + + - name: Build language bindings with sanitizers + run: | + cmake -S . -B target/ff/cc/build \ + -DBUILD_EXAMPLES=ON \ + -DBUILD_TESTING=ON \ + -DCMAKE_BUILD_TYPE=Debug \ + -DSANITIZERS="${{ matrix.sanitizer }}" \ + -DCMAKE_INSTALL_PREFIX=target/ff/cc/install \ + -DCMAKE_PREFIX_PATH="${{ github.workspace }}/target/ff/iceoryx/install" \ + -DRUST_BUILD_ARTIFACT_PATH="${{ github.workspace }}/target/debug" + cmake --build target/ff/cc/build + cmake --install target/ff/cc/build + + - name: Run C language binding tests with sanitizers + env: + ASAN_OPTIONS: "detect_leaks=1:check_initialization_order=1:strict_init_order=1" + UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" + TSAN_OPTIONS: "halt_on_error=1:history_size=7" + run: target/ff/cc/build/tests/iceoryx2-c-tests + + - name: Run C++ language binding tests with sanitizers + env: + ASAN_OPTIONS: "detect_leaks=1:check_initialization_order=1:strict_init_order=1" + UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" + TSAN_OPTIONS: "halt_on_error=1:history_size=7" + run: target/ff/cc/build/tests/iceoryx2-cxx-tests + + - name: Run C examples with sanitizers + env: + ASAN_OPTIONS: "detect_leaks=1:check_initialization_order=1:strict_init_order=1" + UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" + TSAN_OPTIONS: "halt_on_error=1:history_size=7" + run: | + cd target/ff/cc/build/examples/c + find . -maxdepth 1 -type f -executable | while read example; do + echo "Running C example: $example" + timeout 10s $example || true + done + + - name: Run C++ examples with sanitizers + env: + ASAN_OPTIONS: "detect_leaks=1:check_initialization_order=1:strict_init_order=1" + UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" + TSAN_OPTIONS: "halt_on_error=1:history_size=7" + run: | + cd target/ff/cc/build/examples/cxx + find . -maxdepth 1 -type f -executable | while read example; do + echo "Running C++ example: $example" + timeout 10s $example || true + done + cargo-publish-dry-run: needs: [preflight-check, static-code-analysis] if: ${{ needs.changes.outputs.source-code == 'true' }} @@ -792,6 +891,7 @@ jobs: x86_32, python-bindings, end-to-end-tests, + sanitizers, ] runs-on: ubuntu-latest steps: From 518263a9d6768b8681855441561467f88ba2ea05 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 16:05:40 +0100 Subject: [PATCH 03/17] [eclipse-iceoryx#957] Handle empty SANITIZER string Signed-off-by: Ziad Mostafa --- .../modules/Iceoryx2CommonOptionsAndParams.cmake | 3 +-- .../modules/Iceoryx2OptionAndParamMacros.cmake | 2 +- iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake | 8 +++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/iceoryx2-cmake-modules/modules/Iceoryx2CommonOptionsAndParams.cmake b/iceoryx2-cmake-modules/modules/Iceoryx2CommonOptionsAndParams.cmake index c6ba63ea41..9b95f7a148 100644 --- a/iceoryx2-cmake-modules/modules/Iceoryx2CommonOptionsAndParams.cmake +++ b/iceoryx2-cmake-modules/modules/Iceoryx2CommonOptionsAndParams.cmake @@ -31,8 +31,7 @@ if(NOT ICEORYX2_COMMON_OPTIONS_AND_PARAMS_LISTED) add_param( NAME SANITIZERS - TYPE STRING - DESCRIPTION "Sanitizer configuration: 'address', 'ub', 'address;ub', or 'thread'" + DESCRIPTION "Sanitizer configuration: 'address', 'ub', 'address;ub', 'thread', or empty string (disabled)" DEFAULT_VALUE "" ) diff --git a/iceoryx2-cmake-modules/modules/Iceoryx2OptionAndParamMacros.cmake b/iceoryx2-cmake-modules/modules/Iceoryx2OptionAndParamMacros.cmake index b63cb5a637..dce585b7cc 100644 --- a/iceoryx2-cmake-modules/modules/Iceoryx2OptionAndParamMacros.cmake +++ b/iceoryx2-cmake-modules/modules/Iceoryx2OptionAndParamMacros.cmake @@ -20,7 +20,7 @@ endmacro() macro(add_param) set(ONE_VALUE_ARGS NAME DESCRIPTION DEFAULT_VALUE) cmake_parse_arguments(ADD_PARAM "" "${ONE_VALUE_ARGS}" "" ${ARGN}) - if(NOT ${ADD_PARAM_NAME}) + if(NOT DEFINED ${ADD_PARAM_NAME}) set(${ADD_PARAM_NAME} ${ADD_PARAM_DEFAULT_VALUE}) endif() message(STATUS " ${ADD_PARAM_NAME}: ${${ADD_PARAM_NAME}} (Description: ${ADD_PARAM_DESCRIPTION})") diff --git a/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake b/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake index d9aa3e47e9..0c8622d0bf 100644 --- a/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake +++ b/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake @@ -13,7 +13,9 @@ # Parse SANITIZERS string and set appropriate flags set(ICEORYX2_SANITZER_FLAGS "" CACHE INTERNAL "") -if(SANITIZERS STREQUAL "address") +if(SANITIZERS STREQUAL "") + # No sanitizers enabled - empty string is the default +elseif(SANITIZERS STREQUAL "address") set(ICEORYX2_SANITZER_FLAGS -fsanitize=address CACHE INTERNAL "") elseif(SANITIZERS STREQUAL "ub") set(ICEORYX2_SANITZER_FLAGS -fsanitize=undefined CACHE INTERNAL "") @@ -21,6 +23,6 @@ elseif(SANITIZERS STREQUAL "address;ub") set(ICEORYX2_SANITZER_FLAGS -fsanitize=address -fsanitize=undefined CACHE INTERNAL "") elseif(SANITIZERS STREQUAL "thread") set(ICEORYX2_SANITZER_FLAGS -fsanitize=thread CACHE INTERNAL "") -elseif(NOT SANITIZERS STREQUAL "") - message(FATAL_ERROR "Invalid SANITIZERS value: '${SANITIZERS}'. Valid options are: 'address', 'ub', 'address;ub', or 'thread'") +else() + message(FATAL_ERROR "Invalid SANITIZERS value: '${SANITIZERS}'. Valid options are: 'address', 'ub', 'address;ub', 'thread', or empty string (disabled)") endif() From f404393c93b91763a8b77437f1a50ed062dd4da2 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 16:08:16 +0100 Subject: [PATCH 04/17] [eclipse-iceoryx#957] Update release notes Signed-off-by: Ziad Mostafa --- doc/release-notes/iceoryx2-unreleased.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/release-notes/iceoryx2-unreleased.md b/doc/release-notes/iceoryx2-unreleased.md index deb40f235b..27a81918f1 100644 --- a/doc/release-notes/iceoryx2-unreleased.md +++ b/doc/release-notes/iceoryx2-unreleased.md @@ -71,6 +71,8 @@ [#1133](https://github.com/eclipse-iceoryx/iceoryx2/issues/1133) * Enable -Wconversion warning for the C and C++ code [#956](https://github.com/eclipse-iceoryx/iceoryx2/issues/956) +* Add thread sanitizer + [#957](https://github.com/eclipse-iceoryx/iceoryx2/issues/957) ### Workflow From ebb2c845a947858637127228516035e94b060e87 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 16:38:45 +0100 Subject: [PATCH 05/17] [eclipse-iceoryx#957] Handle not defined SANITIZER string case Signed-off-by: Ziad Mostafa --- iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake | 2 +- .../platform/generic/modules/Iceoryx2PlatformSettings.cmake | 2 +- .../platform/mac/modules/Iceoryx2PlatformSettings.cmake | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake b/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake index 0c8622d0bf..5424ada465 100644 --- a/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake +++ b/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake @@ -13,7 +13,7 @@ # Parse SANITIZERS string and set appropriate flags set(ICEORYX2_SANITZER_FLAGS "" CACHE INTERNAL "") -if(SANITIZERS STREQUAL "") +if(NOT DEFINED SANITIZERS OR SANITIZERS STREQUAL "") # No sanitizers enabled - empty string is the default elseif(SANITIZERS STREQUAL "address") set(ICEORYX2_SANITZER_FLAGS -fsanitize=address CACHE INTERNAL "") diff --git a/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake b/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake index 9513142547..df5da9c325 100644 --- a/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake +++ b/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake @@ -36,7 +36,7 @@ if(WARNING_AS_ERROR) endif() set(ICEORYX2_SANITZER_FLAGS CACHE INTERNAL "") -if(NOT SANITIZERS STREQUAL "") +if(DEFINED SANITIZERS AND NOT SANITIZERS STREQUAL "") include(Iceoryx2Sanitizer) endif() diff --git a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake index 0f2b9578c2..af62c8b97b 100644 --- a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake +++ b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake @@ -35,7 +35,7 @@ if(WARNING_AS_ERROR) set(ICEORYX2_CXX_WARNINGS ${ICEORYX2_CXX_WARNINGS} -Werror CACHE INTERNAL "") endif() -if(NOT SANITIZERS STREQUAL "") +if(DEFINED SANITIZERS AND NOT SANITIZERS STREQUAL "") include(Iceoryx2Sanitizer) set(ICEORYX2_CXX_FLAGS "${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS}" CACHE INTERNAL "") From 6aba344745a6ef497a1d28870cd89c8bfc74c375 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 17:12:00 +0100 Subject: [PATCH 06/17] [eclipse-iceoryx#957] Enable sanitizers on mac-os Signed-off-by: Ziad Mostafa --- .github/workflows/build-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index fdb5ae5277..f2666a7c5e 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -682,7 +682,7 @@ jobs: if: ${{ needs.changes.outputs.source-code == 'true' }} strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest] toolchain: [stable] sanitizer: ["address", "ub", "address;ub", "thread"] timeout-minutes: 60 @@ -712,6 +712,7 @@ jobs: artifact-upload-name: ${{ runner.os }}-cargo-nextest - name: Prepare Linux + if: ${{ matrix.os == 'ubuntu-latest' }} run: | internal/scripts/ci_prepare_ubuntu.sh uname -a From 53db3e2d7414a96088fc1381aecb68cfb866d2a1 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 19:00:18 +0100 Subject: [PATCH 07/17] [eclipse-iceoryx#957] Use same sanitizers env variables from iceoryx Signed-off-by: Ziad Mostafa --- .github/workflows/build-test.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index f2666a7c5e..4b03d3a973 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -741,21 +741,24 @@ jobs: - name: Run C language binding tests with sanitizers env: - ASAN_OPTIONS: "detect_leaks=1:check_initialization_order=1:strict_init_order=1" + ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:intercept_tls_get_addr=0" + LSAN_OPTIONS: "verbosity=1:log_threads=1" UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" TSAN_OPTIONS: "halt_on_error=1:history_size=7" run: target/ff/cc/build/tests/iceoryx2-c-tests - name: Run C++ language binding tests with sanitizers env: - ASAN_OPTIONS: "detect_leaks=1:check_initialization_order=1:strict_init_order=1" + ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:intercept_tls_get_addr=0" + LSAN_OPTIONS: "verbosity=1:log_threads=1" UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" TSAN_OPTIONS: "halt_on_error=1:history_size=7" run: target/ff/cc/build/tests/iceoryx2-cxx-tests - name: Run C examples with sanitizers env: - ASAN_OPTIONS: "detect_leaks=1:check_initialization_order=1:strict_init_order=1" + ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:intercept_tls_get_addr=0" + LSAN_OPTIONS: "verbosity=1:log_threads=1" UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" TSAN_OPTIONS: "halt_on_error=1:history_size=7" run: | @@ -767,7 +770,8 @@ jobs: - name: Run C++ examples with sanitizers env: - ASAN_OPTIONS: "detect_leaks=1:check_initialization_order=1:strict_init_order=1" + ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:intercept_tls_get_addr=0" + LSAN_OPTIONS: "verbosity=1:log_threads=1" UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" TSAN_OPTIONS: "halt_on_error=1:history_size=7" run: | From 6a7ec2aaf74c7f54c7cfaa823e407aa6754a38ae Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 19:12:10 +0100 Subject: [PATCH 08/17] [eclipse-iceoryx#957] Fix cmake flag concatination Signed-off-by: Ziad Mostafa --- .../platform/generic/modules/Iceoryx2PlatformSettings.cmake | 4 ++++ .../platform/mac/modules/Iceoryx2PlatformSettings.cmake | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake b/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake index df5da9c325..992ef87a37 100644 --- a/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake +++ b/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake @@ -38,6 +38,10 @@ endif() set(ICEORYX2_SANITZER_FLAGS CACHE INTERNAL "") if(DEFINED SANITIZERS AND NOT SANITIZERS STREQUAL "") include(Iceoryx2Sanitizer) + + set(ICEORYX2_C_FLAGS ${ICEORYX2_C_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") + set(ICEORYX2_CXX_FLAGS ${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") + set(ICEORYX2_TEST_CXX_FLAGS ${ICEORYX2_TEST_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") endif() set(ICEORYX2_COVERAGE_FLAGS CACHE INTERNAL "") diff --git a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake index af62c8b97b..08b71f38de 100644 --- a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake +++ b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake @@ -38,6 +38,7 @@ endif() if(DEFINED SANITIZERS AND NOT SANITIZERS STREQUAL "") include(Iceoryx2Sanitizer) - set(ICEORYX2_CXX_FLAGS "${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS}" CACHE INTERNAL "") - set(ICEORYX2_TEST_CXX_FLAGS "${ICEORYX2_TEST_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS}" CACHE INTERNAL "") + set(ICEORYX2_C_FLAGS ${ICEORYX2_C_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") + set(ICEORYX2_CXX_FLAGS ${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") + set(ICEORYX2_TEST_CXX_FLAGS ${ICEORYX2_TEST_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") endif() From dd208122232103e7bf518098711e3cdf74a8d559 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 19:26:31 +0100 Subject: [PATCH 09/17] [eclipse-iceoryx#957] Enable sanitizers for rust Signed-off-by: Ziad Mostafa --- .github/workflows/build-test.yml | 92 +++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 4b03d3a973..294003f345 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -678,15 +678,23 @@ jobs: run: bazel test //... sanitizers: - needs: [preflight-check, static-code-analysis, cargo-nextest] + needs: [preflight-check] + # needs: [preflight-check, static-code-analysis, cargo-nextest] + # needs: [preflight-check, static-code-analysis, cargo-nextest] if: ${{ needs.changes.outputs.source-code == 'true' }} strategy: matrix: os: [ubuntu-latest, macos-latest] - toolchain: [stable] + toolchain: [nightly] # Rust sanitizers require nightly sanitizer: ["address", "ub", "address;ub", "thread"] + exclude: + # Thread sanitizer is not well supported on macOS + - os: macos-latest + sanitizer: "thread" timeout-minutes: 60 runs-on: ${{ matrix.os }} + env: + RUST_BACKTRACE: 1 steps: - name: Checkout sources uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 @@ -704,6 +712,7 @@ jobs: with: toolchain: ${{ matrix.toolchain }} components: rustfmt, clippy + targets: x86_64-unknown-linux-gnu, x86_64-apple-darwin - name: Download artifact cargo-nextest uses: ./.github/actions/download-cached-rust-tool @@ -717,11 +726,34 @@ jobs: internal/scripts/ci_prepare_ubuntu.sh uname -a + - name: Set Rust sanitizer flags + run: | + # Set default target based on OS + if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then + RUST_TARGET="x86_64-unknown-linux-gnu" + elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then + RUST_TARGET="x86_64-apple-darwin" + fi + + # Set sanitizer-specific flags + if [[ "${{ matrix.sanitizer }}" == "address" ]]; then + echo "RUSTFLAGS=-Zsanitizer=address -Copt-level=1" >> $GITHUB_ENV + elif [[ "${{ matrix.sanitizer }}" == "ub" ]]; then + # Rust doesn't have a specific undefined behavior sanitizer, but we can enable debug assertions + echo "RUSTFLAGS=-Cdebug-assertions=on -Coverflow-checks=on -Copt-level=1" >> $GITHUB_ENV + elif [[ "${{ matrix.sanitizer }}" == "address;ub" ]]; then + echo "RUSTFLAGS=-Zsanitizer=address -Cdebug-assertions=on -Coverflow-checks=on -Copt-level=1" >> $GITHUB_ENV + elif [[ "${{ matrix.sanitizer }}" == "thread" ]]; then + echo "RUSTFLAGS=-Zsanitizer=thread -Copt-level=1" >> $GITHUB_ENV + fi + + echo "RUST_TARGET=$RUST_TARGET" >> $GITHUB_ENV + - name: Run cargo build - run: cargo build --workspace --all-targets + run: cargo build -Zbuild-std --workspace --all-targets --target ${{ env.RUST_TARGET }} - name: Run cargo nextest - run: cargo nextest run --workspace --all-targets --no-fail-fast + run: cargo nextest run --workspace --all-targets --no-fail-fast --target ${{ env.RUST_TARGET }} - name: Build iceoryx_hoofs run: internal/scripts/ci_build_and_install_iceoryx_hoofs.sh @@ -735,7 +767,7 @@ jobs: -DSANITIZERS="${{ matrix.sanitizer }}" \ -DCMAKE_INSTALL_PREFIX=target/ff/cc/install \ -DCMAKE_PREFIX_PATH="${{ github.workspace }}/target/ff/iceoryx/install" \ - -DRUST_BUILD_ARTIFACT_PATH="${{ github.workspace }}/target/debug" + -DRUST_BUILD_ARTIFACT_PATH="${{ github.workspace }}/target/${{ env.RUST_TARGET }}/debug" cmake --build target/ff/cc/build cmake --install target/ff/cc/build @@ -755,31 +787,43 @@ jobs: TSAN_OPTIONS: "halt_on_error=1:history_size=7" run: target/ff/cc/build/tests/iceoryx2-cxx-tests - - name: Run C examples with sanitizers - env: - ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:intercept_tls_get_addr=0" - LSAN_OPTIONS: "verbosity=1:log_threads=1" - UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" - TSAN_OPTIONS: "halt_on_error=1:history_size=7" - run: | - cd target/ff/cc/build/examples/c - find . -maxdepth 1 -type f -executable | while read example; do - echo "Running C example: $example" - timeout 10s $example || true - done - - - name: Run C++ examples with sanitizers + # - name: Run C examples with sanitizers + # env: + # ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:intercept_tls_get_addr=0" + # LSAN_OPTIONS: "verbosity=1:log_threads=1" + # UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" + # TSAN_OPTIONS: "halt_on_error=1:history_size=7" + # run: | + # cd target/ff/cc/build/examples/c + # find . -maxdepth 1 -type f -executable | while read example; do + # echo "Running C example: $example" + # timeout 10s $example || true + # done + + # - name: Run C++ examples with sanitizers + # env: + # ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:intercept_tls_get_addr=0" + # LSAN_OPTIONS: "verbosity=1:log_threads=1" + # UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" + # TSAN_OPTIONS: "halt_on_error=1:history_size=7" + # run: | + # cd target/ff/cc/build/examples/cxx + # find . -maxdepth 1 -type f -executable | while read example; do + # echo "Running C++ example: $example" + # timeout 10s $example || true + # done + + - name: Run end-to-end tests with sanitizers + # Skip end-to-end tests with thread sanitizer due to potential issues with dynamic linking + if: ${{ matrix.sanitizer != 'thread' }} env: ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:intercept_tls_get_addr=0" LSAN_OPTIONS: "verbosity=1:log_threads=1" UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" TSAN_OPTIONS: "halt_on_error=1:history_size=7" run: | - cd target/ff/cc/build/examples/cxx - find . -maxdepth 1 -type f -executable | while read example; do - echo "Running C++ example: $example" - timeout 10s $example || true - done + cd "${GITHUB_WORKSPACE}" + internal/scripts/ci_build_and_run_end_to_end_tests.sh no-build cargo-publish-dry-run: needs: [preflight-check, static-code-analysis] From 4ac6d58cda099ed611d9131756a9ae23a8f12722 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 20:54:36 +0100 Subject: [PATCH 10/17] [eclipse-iceoryx#957] Disable macos build for sanitizers Signed-off-by: Ziad Mostafa --- .github/workflows/build-test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 294003f345..554fe386e5 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -679,7 +679,6 @@ jobs: sanitizers: needs: [preflight-check] - # needs: [preflight-check, static-code-analysis, cargo-nextest] # needs: [preflight-check, static-code-analysis, cargo-nextest] if: ${{ needs.changes.outputs.source-code == 'true' }} strategy: @@ -750,7 +749,9 @@ jobs: echo "RUST_TARGET=$RUST_TARGET" >> $GITHUB_ENV - name: Run cargo build - run: cargo build -Zbuild-std --workspace --all-targets --target ${{ env.RUST_TARGET }} + run: | + rustup component add rust-src --toolchain ${{ matrix.toolchain }} + cargo build -Zbuild-std --workspace --all-targets --target ${{ env.RUST_TARGET }} - name: Run cargo nextest run: cargo nextest run --workspace --all-targets --no-fail-fast --target ${{ env.RUST_TARGET }} From c65e7c94dde4f63f324596e5d6a800b820fee0a1 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 21:20:04 +0100 Subject: [PATCH 11/17] [eclipse-iceoryx#957] Disable rust sanitizers Signed-off-by: Ziad Mostafa --- .github/workflows/build-test.yml | 50 +++++++++++++++----------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 554fe386e5..8e7059f3a0 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -684,7 +684,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - toolchain: [nightly] # Rust sanitizers require nightly + toolchain: [stable] # Rust sanitizers require nightly sanitizer: ["address", "ub", "address;ub", "thread"] exclude: # Thread sanitizer is not well supported on macOS @@ -725,36 +725,34 @@ jobs: internal/scripts/ci_prepare_ubuntu.sh uname -a - - name: Set Rust sanitizer flags - run: | - # Set default target based on OS - if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then - RUST_TARGET="x86_64-unknown-linux-gnu" - elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then - RUST_TARGET="x86_64-apple-darwin" - fi + # - name: Set Rust sanitizer flags + # run: | + # # Set default target based on OS + # if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then + # RUST_TARGET="x86_64-unknown-linux-gnu" + # elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then + # RUST_TARGET="x86_64-apple-darwin" + # fi - # Set sanitizer-specific flags - if [[ "${{ matrix.sanitizer }}" == "address" ]]; then - echo "RUSTFLAGS=-Zsanitizer=address -Copt-level=1" >> $GITHUB_ENV - elif [[ "${{ matrix.sanitizer }}" == "ub" ]]; then - # Rust doesn't have a specific undefined behavior sanitizer, but we can enable debug assertions - echo "RUSTFLAGS=-Cdebug-assertions=on -Coverflow-checks=on -Copt-level=1" >> $GITHUB_ENV - elif [[ "${{ matrix.sanitizer }}" == "address;ub" ]]; then - echo "RUSTFLAGS=-Zsanitizer=address -Cdebug-assertions=on -Coverflow-checks=on -Copt-level=1" >> $GITHUB_ENV - elif [[ "${{ matrix.sanitizer }}" == "thread" ]]; then - echo "RUSTFLAGS=-Zsanitizer=thread -Copt-level=1" >> $GITHUB_ENV - fi + # # Set sanitizer-specific flags + # if [[ "${{ matrix.sanitizer }}" == "address" ]]; then + # echo "RUSTFLAGS=-Zsanitizer=address -Copt-level=1" >> $GITHUB_ENV + # elif [[ "${{ matrix.sanitizer }}" == "ub" ]]; then + # # Rust doesn't have a specific undefined behavior sanitizer, but we can enable debug assertions + # echo "RUSTFLAGS=-Cdebug-assertions=on -Coverflow-checks=on -Copt-level=1" >> $GITHUB_ENV + # elif [[ "${{ matrix.sanitizer }}" == "address;ub" ]]; then + # echo "RUSTFLAGS=-Zsanitizer=address -Cdebug-assertions=on -Coverflow-checks=on -Copt-level=1" >> $GITHUB_ENV + # elif [[ "${{ matrix.sanitizer }}" == "thread" ]]; then + # echo "RUSTFLAGS=-Zsanitizer=thread -Copt-level=1" >> $GITHUB_ENV + # fi - echo "RUST_TARGET=$RUST_TARGET" >> $GITHUB_ENV + # echo "RUST_TARGET=$RUST_TARGET" >> $GITHUB_ENV - name: Run cargo build - run: | - rustup component add rust-src --toolchain ${{ matrix.toolchain }} - cargo build -Zbuild-std --workspace --all-targets --target ${{ env.RUST_TARGET }} + run: cargo build --workspace --all-targets - name: Run cargo nextest - run: cargo nextest run --workspace --all-targets --no-fail-fast --target ${{ env.RUST_TARGET }} + run: cargo nextest run --workspace --all-targets --no-fail-fast - name: Build iceoryx_hoofs run: internal/scripts/ci_build_and_install_iceoryx_hoofs.sh @@ -768,7 +766,7 @@ jobs: -DSANITIZERS="${{ matrix.sanitizer }}" \ -DCMAKE_INSTALL_PREFIX=target/ff/cc/install \ -DCMAKE_PREFIX_PATH="${{ github.workspace }}/target/ff/iceoryx/install" \ - -DRUST_BUILD_ARTIFACT_PATH="${{ github.workspace }}/target/${{ env.RUST_TARGET }}/debug" + -DRUST_BUILD_ARTIFACT_PATH="${{ github.workspace }}/target/debug" cmake --build target/ff/cc/build cmake --install target/ff/cc/build From db59b163ed201c1656384e6382e99a27f760bc0b Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 21:42:22 +0100 Subject: [PATCH 12/17] [eclipse-iceoryx#957] Fix linker issue, and small name typo Signed-off-by: Ziad Mostafa --- .../modules/Iceoryx2Sanitizer.cmake | 10 +++++----- .../generic/modules/Iceoryx2PlatformSettings.cmake | 13 +++++++++---- .../mac/modules/Iceoryx2PlatformSettings.cmake | 11 ++++++++--- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake b/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake index 5424ada465..5e75d3c177 100644 --- a/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake +++ b/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake @@ -11,18 +11,18 @@ # SPDX-License-Identifier: Apache-2.0 OR MIT # Parse SANITIZERS string and set appropriate flags -set(ICEORYX2_SANITZER_FLAGS "" CACHE INTERNAL "") +set(ICEORYX2_SANITIZER_FLAGS "" CACHE INTERNAL "") if(NOT DEFINED SANITIZERS OR SANITIZERS STREQUAL "") # No sanitizers enabled - empty string is the default elseif(SANITIZERS STREQUAL "address") - set(ICEORYX2_SANITZER_FLAGS -fsanitize=address CACHE INTERNAL "") + set(ICEORYX2_SANITIZER_FLAGS -fsanitize=address CACHE INTERNAL "") elseif(SANITIZERS STREQUAL "ub") - set(ICEORYX2_SANITZER_FLAGS -fsanitize=undefined CACHE INTERNAL "") + set(ICEORYX2_SANITIZER_FLAGS -fsanitize=undefined CACHE INTERNAL "") elseif(SANITIZERS STREQUAL "address;ub") - set(ICEORYX2_SANITZER_FLAGS -fsanitize=address -fsanitize=undefined CACHE INTERNAL "") + set(ICEORYX2_SANITIZER_FLAGS -fsanitize=address -fsanitize=undefined CACHE INTERNAL "") elseif(SANITIZERS STREQUAL "thread") - set(ICEORYX2_SANITZER_FLAGS -fsanitize=thread CACHE INTERNAL "") + set(ICEORYX2_SANITIZER_FLAGS -fsanitize=thread CACHE INTERNAL "") else() message(FATAL_ERROR "Invalid SANITIZERS value: '${SANITIZERS}'. Valid options are: 'address', 'ub', 'address;ub', 'thread', or empty string (disabled)") endif() diff --git a/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake b/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake index 992ef87a37..5318c206f0 100644 --- a/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake +++ b/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake @@ -35,13 +35,18 @@ if(WARNING_AS_ERROR) set(ICEORYX2_CXX_WARNINGS ${ICEORYX2_CXX_WARNINGS} -Werror CACHE INTERNAL "") endif() -set(ICEORYX2_SANITZER_FLAGS CACHE INTERNAL "") +set(ICEORYX2_SANITIZER_FLAGS CACHE INTERNAL "") +set(ICEORYX2_LINK_FLAGS CACHE INTERNAL "") + if(DEFINED SANITIZERS AND NOT SANITIZERS STREQUAL "") include(Iceoryx2Sanitizer) - set(ICEORYX2_C_FLAGS ${ICEORYX2_C_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") - set(ICEORYX2_CXX_FLAGS ${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") - set(ICEORYX2_TEST_CXX_FLAGS ${ICEORYX2_TEST_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") + set(ICEORYX2_C_FLAGS ${ICEORYX2_C_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") + set(ICEORYX2_CXX_FLAGS ${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") + set(ICEORYX2_TEST_CXX_FLAGS ${ICEORYX2_TEST_CXX_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") + + # Sanitizer flags must also be added to linker flags + set(ICEORYX2_LINK_FLAGS ${ICEORYX2_LINK_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") endif() set(ICEORYX2_COVERAGE_FLAGS CACHE INTERNAL "") diff --git a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake index 08b71f38de..7284a33f76 100644 --- a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake +++ b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake @@ -35,10 +35,15 @@ if(WARNING_AS_ERROR) set(ICEORYX2_CXX_WARNINGS ${ICEORYX2_CXX_WARNINGS} -Werror CACHE INTERNAL "") endif() +set(ICEORYX2_LINK_FLAGS CACHE INTERNAL "") + if(DEFINED SANITIZERS AND NOT SANITIZERS STREQUAL "") include(Iceoryx2Sanitizer) - set(ICEORYX2_C_FLAGS ${ICEORYX2_C_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") - set(ICEORYX2_CXX_FLAGS ${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") - set(ICEORYX2_TEST_CXX_FLAGS ${ICEORYX2_TEST_CXX_FLAGS} ${ICEORYX2_SANITZER_FLAGS} CACHE INTERNAL "") + set(ICEORYX2_C_FLAGS ${ICEORYX2_C_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") + set(ICEORYX2_CXX_FLAGS ${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") + set(ICEORYX2_TEST_CXX_FLAGS ${ICEORYX2_TEST_CXX_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") + + # Sanitizer flags must also be added to linker flags + set(ICEORYX2_LINK_FLAGS ${ICEORYX2_LINK_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") endif() From 922f3abe2cb1134dbe4b1d236f5005cbfd8c5727 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 21:42:56 +0100 Subject: [PATCH 13/17] [eclipse-iceoryx#957] Enable address sanitizer only on macos Signed-off-by: Ziad Mostafa --- .github/workflows/build-test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 8e7059f3a0..38c58f577e 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -687,9 +687,13 @@ jobs: toolchain: [stable] # Rust sanitizers require nightly sanitizer: ["address", "ub", "address;ub", "thread"] exclude: - # Thread sanitizer is not well supported on macOS + # Only run address sanitizer on macOS - os: macos-latest sanitizer: "thread" + - os: macos-latest + sanitizer: "ub" + - os: macos-latest + sanitizer: "address;ub" timeout-minutes: 60 runs-on: ${{ matrix.os }} env: From 3980312baf7cf3853c21ef24b2a111148fb50f20 Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 27 Oct 2025 22:01:45 +0100 Subject: [PATCH 14/17] [eclipse-iceoryx#957] Fix rust setup step Signed-off-by: Ziad Mostafa --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 38c58f577e..a1534ac9a5 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -715,7 +715,7 @@ jobs: with: toolchain: ${{ matrix.toolchain }} components: rustfmt, clippy - targets: x86_64-unknown-linux-gnu, x86_64-apple-darwin + # targets: x86_64-unknown-linux-gnu, x86_64-apple-darwin - name: Download artifact cargo-nextest uses: ./.github/actions/download-cached-rust-tool From dc883eb8fee8f426a0a28e3af4ed055ba79e0a3c Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Tue, 28 Oct 2025 00:48:55 +0100 Subject: [PATCH 15/17] tmp commit Signed-off-by: Ziad Mostafa --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index a1534ac9a5..f5f058b0a5 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -683,7 +683,7 @@ jobs: if: ${{ needs.changes.outputs.source-code == 'true' }} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest] toolchain: [stable] # Rust sanitizers require nightly sanitizer: ["address", "ub", "address;ub", "thread"] exclude: From 5925ecfcc0cf1073e7252306f5cd22de44da654f Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Tue, 28 Oct 2025 15:13:43 +0100 Subject: [PATCH 16/17] Remove unwanted cmake definition Signed-off-by: Ziad Mostafa --- .../platform/generic/modules/Iceoryx2PlatformSettings.cmake | 2 -- .../platform/mac/modules/Iceoryx2PlatformSettings.cmake | 2 -- 2 files changed, 4 deletions(-) diff --git a/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake b/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake index 5318c206f0..5996101854 100644 --- a/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake +++ b/iceoryx2-cmake-modules/platform/generic/modules/Iceoryx2PlatformSettings.cmake @@ -45,8 +45,6 @@ if(DEFINED SANITIZERS AND NOT SANITIZERS STREQUAL "") set(ICEORYX2_CXX_FLAGS ${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") set(ICEORYX2_TEST_CXX_FLAGS ${ICEORYX2_TEST_CXX_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") - # Sanitizer flags must also be added to linker flags - set(ICEORYX2_LINK_FLAGS ${ICEORYX2_LINK_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") endif() set(ICEORYX2_COVERAGE_FLAGS CACHE INTERNAL "") diff --git a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake index 7284a33f76..44d55458db 100644 --- a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake +++ b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake @@ -44,6 +44,4 @@ if(DEFINED SANITIZERS AND NOT SANITIZERS STREQUAL "") set(ICEORYX2_CXX_FLAGS ${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") set(ICEORYX2_TEST_CXX_FLAGS ${ICEORYX2_TEST_CXX_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") - # Sanitizer flags must also be added to linker flags - set(ICEORYX2_LINK_FLAGS ${ICEORYX2_LINK_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") endif() From 5fa2f0bdf023c7f15bcce6a393b7243aee338cab Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Tue, 28 Oct 2025 15:50:25 +0100 Subject: [PATCH 17/17] Copy sanitizers cmake functions from iceoryx Signed-off-by: Ziad Mostafa --- .github/workflows/build-test.yml | 18 +-- .../modules/Iceoryx2Sanitizer.cmake | 132 ++++++++++++++++-- .../modules/Iceoryx2PlatformSettings.cmake | 3 + 3 files changed, 134 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index f5f058b0a5..aa9c72e8c7 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -776,18 +776,18 @@ jobs: - name: Run C language binding tests with sanitizers env: - ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:intercept_tls_get_addr=0" - LSAN_OPTIONS: "verbosity=1:log_threads=1" + ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:suppressions=${{ github.workspace }}/target/ff/cc/build/sanitizer_blacklist/asan_runtime.txt:intercept_tls_get_addr=0" + LSAN_OPTIONS: "verbosity=1:log_threads=1:suppressions=${{ github.workspace }}/target/ff/cc/build/sanitizer_blacklist/lsan_runtime.txt" UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" - TSAN_OPTIONS: "halt_on_error=1:history_size=7" + TSAN_OPTIONS: "halt_on_error=1:history_size=7:suppressions=${{ github.workspace }}/target/ff/cc/build/sanitizer_blacklist/tsan_runtime.txt" run: target/ff/cc/build/tests/iceoryx2-c-tests - name: Run C++ language binding tests with sanitizers env: - ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:intercept_tls_get_addr=0" - LSAN_OPTIONS: "verbosity=1:log_threads=1" + ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:suppressions=${{ github.workspace }}/target/ff/cc/build/sanitizer_blacklist/asan_runtime.txt:intercept_tls_get_addr=0" + LSAN_OPTIONS: "verbosity=1:log_threads=1:suppressions=${{ github.workspace }}/target/ff/cc/build/sanitizer_blacklist/lsan_runtime.txt" UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" - TSAN_OPTIONS: "halt_on_error=1:history_size=7" + TSAN_OPTIONS: "halt_on_error=1:history_size=7:suppressions=${{ github.workspace }}/target/ff/cc/build/sanitizer_blacklist/tsan_runtime.txt" run: target/ff/cc/build/tests/iceoryx2-cxx-tests # - name: Run C examples with sanitizers @@ -820,10 +820,10 @@ jobs: # Skip end-to-end tests with thread sanitizer due to potential issues with dynamic linking if: ${{ matrix.sanitizer != 'thread' }} env: - ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:intercept_tls_get_addr=0" - LSAN_OPTIONS: "verbosity=1:log_threads=1" + ASAN_OPTIONS: "detect_leaks=1:detect_stack_use_after_return=1:detect_stack_use_after_scope=1:check_initialization_order=true:strict_init_order=true:new_delete_type_mismatch=0:suppressions=${{ github.workspace }}/target/ff/cc/build/sanitizer_blacklist/asan_runtime.txt:intercept_tls_get_addr=0" + LSAN_OPTIONS: "verbosity=1:log_threads=1:suppressions=${{ github.workspace }}/target/ff/cc/build/sanitizer_blacklist/lsan_runtime.txt" UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" - TSAN_OPTIONS: "halt_on_error=1:history_size=7" + TSAN_OPTIONS: "halt_on_error=1:history_size=7:suppressions=${{ github.workspace }}/target/ff/cc/build/sanitizer_blacklist/tsan_runtime.txt" run: | cd "${GITHUB_WORKSPACE}" internal/scripts/ci_build_and_run_end_to_end_tests.sh no-build diff --git a/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake b/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake index 5e75d3c177..054efbb459 100644 --- a/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake +++ b/iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake @@ -10,19 +10,131 @@ # # SPDX-License-Identifier: Apache-2.0 OR MIT +# Sanitizer blacklist creation functions +function(iox2_create_asan_compile_time_blacklist BLACKLIST_FILE_PATH) + # Suppressing Errors in Recompiled Code (Blacklist) + # (https://clang.llvm.org/docs/AddressSanitizer.html#suppressing-errors-in-recompiled-code-blacklist) + # More details about the syntax can be found here (https://clang.llvm.org/docs/SanitizerSpecialCaseList.html) + if(NOT EXISTS ${BLACKLIST_FILE_PATH}) + file(WRITE ${BLACKLIST_FILE_PATH} "# This file is auto-generated from iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake\n") + file(APPEND ${BLACKLIST_FILE_PATH} "# src:*file_name.cpp*\n") + file(APPEND ${BLACKLIST_FILE_PATH} "# fun:*Test_Name*\n") + file(APPEND ${BLACKLIST_FILE_PATH} "# End of file\n") + endif() +endfunction() + +function(iox2_create_asan_runtime_blacklist BLACKLIST_FILE_PATH) + # Suppress errors in external libraries (https://clang.llvm.org/docs/AddressSanitizer.html#suppressing-reports-in-external-libraries) + # List of errors generated in .inl files. These cannot be suppressed with -fsanitize-blacklist! + # We enable sanitizer flags for core components, not in tests (mainly to avoid catching errors in test cases, at least for now) + # NOTE : AddressSanitizer won't generate any report for the suppressed errors. + # Only way to see detailed errors is to disable the entries here & run + if(NOT EXISTS ${BLACKLIST_FILE_PATH}) + file(WRITE ${BLACKLIST_FILE_PATH} "# This file is auto-generated from iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake\n") + file(APPEND ${BLACKLIST_FILE_PATH} "#interceptor_via_fun:-[ClassName objCMethodToSuppress:]\n") + file(APPEND ${BLACKLIST_FILE_PATH} "#interceptor_via_lib:NameOfTheLibraryToSuppress\n") + file(APPEND ${BLACKLIST_FILE_PATH} "# End of file\n") + endif() +endfunction() + +function(iox2_create_tsan_runtime_blacklist BLACKLIST_FILE_PATH) + # (https://github.com/google/sanitizers/wiki/ThreadSanitizerSuppressions) + # The suppression types are: + # race suppresses data races and use-after-free reports + # race_top same as race, but matched only against the top stack frame + # thread suppresses reports related to threads (leaks) + # mutex suppresses reports related to mutexes (destruction of a locked mutex) + # signal suppresses reports related to signal handlers (handler calls malloc()) + # deadlock suppresses lock inversion reports + # called_from_lib suppresses all interceptors in a particular library + if(NOT EXISTS ${BLACKLIST_FILE_PATH}) + file(WRITE ${BLACKLIST_FILE_PATH} "# This file is auto-generated from iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake\n") + file(APPEND ${BLACKLIST_FILE_PATH} "mutex:*MutexWithDeadlockDetectionsFailsWhenSameThreadTriesToUnlockItTwice*\n") + file(APPEND ${BLACKLIST_FILE_PATH} "mutex:*MutexWithDeadlockDetectionsFailsWhenAnotherThreadTriesToUnlock*\n") + file(APPEND ${BLACKLIST_FILE_PATH} "mutex:*MutexWithStallWhenLockedBehaviorDoesntUnlockMutexWhenThreadTerminates*\n") + file(APPEND ${BLACKLIST_FILE_PATH} "race:*\n") + file(APPEND ${BLACKLIST_FILE_PATH} "deadlock:*TimingTest_AttachingInCallbackWorks*\n") + file(APPEND ${BLACKLIST_FILE_PATH} "# End of file\n") + endif() +endfunction() + +function(iox2_create_lsan_runtime_blacklist BLACKLIST_FILE_PATH) + # Suppress known memory leaks (https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer) + # Below function/files contains memory leaks! + # LeakSanitizer wont report the problem for the entries here , however you can find the suppression report in the log + # + # e.g. + # Suppressions used: + # count bytes template + # 8 642 libacl.so.1 + # 1 24 iox::UnixDomainSocket::timedReceive + # 1 24 iox::MessageQueue::receive + if(NOT EXISTS ${BLACKLIST_FILE_PATH}) + file(WRITE ${BLACKLIST_FILE_PATH} "# This file is auto-generated from iceoryx2-cmake-modules/modules/Iceoryx2Sanitizer.cmake\n") + file(APPEND ${BLACKLIST_FILE_PATH} "#leak:libacl.so.1\n") + file(APPEND ${BLACKLIST_FILE_PATH} "#leak:iox::UnixDomainSocket::timedReceive\n") + file(APPEND ${BLACKLIST_FILE_PATH} "# End of file\n") + endif() +endfunction() + # Parse SANITIZERS string and set appropriate flags set(ICEORYX2_SANITIZER_FLAGS "" CACHE INTERNAL "") +set(ICEORYX2_SANITIZER_BLACKLIST "" CACHE INTERNAL "") + +# Strip any whitespace from SANITIZERS +if(DEFINED SANITIZERS) + string(STRIP "${SANITIZERS}" SANITIZERS_STRIPPED) +else() + set(SANITIZERS_STRIPPED "") +endif() + +# Check for invalid combinations +if(SANITIZERS_STRIPPED MATCHES "address" AND SANITIZERS_STRIPPED MATCHES "thread") + message(FATAL_ERROR "You cannot run address sanitizer and thread sanitizer together. Choose one or the other!") +endif() + +# Create blacklist directories and files if sanitizers are enabled +if(DEFINED SANITIZERS AND NOT SANITIZERS_STRIPPED STREQUAL "" AND NOT SANITIZERS_STRIPPED STREQUAL "OFF" AND NOT SANITIZERS_STRIPPED STREQUAL "FALSE") + # Create sanitizer blacklist directory + set(ICEORYX2_SANITIZER_BLACKLIST_DIR ${CMAKE_BINARY_DIR}/sanitizer_blacklist) + file(MAKE_DIRECTORY ${ICEORYX2_SANITIZER_BLACKLIST_DIR}) + + # Create runtime blacklists (always created when any sanitizer is enabled) + iox2_create_asan_runtime_blacklist(${ICEORYX2_SANITIZER_BLACKLIST_DIR}/asan_runtime.txt) + iox2_create_lsan_runtime_blacklist(${ICEORYX2_SANITIZER_BLACKLIST_DIR}/lsan_runtime.txt) + iox2_create_tsan_runtime_blacklist(${ICEORYX2_SANITIZER_BLACKLIST_DIR}/tsan_runtime.txt) + + # Create compile-time blacklist for Clang + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + set(ICEORYX2_SANITIZER_BLACKLIST_FILE ${ICEORYX2_SANITIZER_BLACKLIST_DIR}/sanitizer_compile_time.txt) + iox2_create_asan_compile_time_blacklist(${ICEORYX2_SANITIZER_BLACKLIST_FILE}) + set(ICEORYX2_SANITIZER_BLACKLIST -fsanitize-blacklist=${ICEORYX2_SANITIZER_BLACKLIST_FILE} CACHE INTERNAL "") + endif() +endif() + +# Common sanitizer flags +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + set(ICEORYX2_SANITIZER_COMMON_FLAGS -fno-omit-frame-pointer -fno-optimize-sibling-calls) +else() + set(ICEORYX2_SANITIZER_COMMON_FLAGS "") +endif() -if(NOT DEFINED SANITIZERS OR SANITIZERS STREQUAL "") +# Set sanitizer flags based on SANITIZERS value +if(NOT DEFINED SANITIZERS OR SANITIZERS_STRIPPED STREQUAL "" OR SANITIZERS_STRIPPED STREQUAL "OFF" OR SANITIZERS_STRIPPED STREQUAL "FALSE") # No sanitizers enabled - empty string is the default -elseif(SANITIZERS STREQUAL "address") - set(ICEORYX2_SANITIZER_FLAGS -fsanitize=address CACHE INTERNAL "") -elseif(SANITIZERS STREQUAL "ub") - set(ICEORYX2_SANITIZER_FLAGS -fsanitize=undefined CACHE INTERNAL "") -elseif(SANITIZERS STREQUAL "address;ub") - set(ICEORYX2_SANITIZER_FLAGS -fsanitize=address -fsanitize=undefined CACHE INTERNAL "") -elseif(SANITIZERS STREQUAL "thread") - set(ICEORYX2_SANITIZER_FLAGS -fsanitize=thread CACHE INTERNAL "") +elseif(SANITIZERS_STRIPPED STREQUAL "address") + set(ICEORYX2_SANITIZER_FLAGS ${ICEORYX2_SANITIZER_COMMON_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope ${ICEORYX2_SANITIZER_BLACKLIST} CACHE INTERNAL "") +elseif(SANITIZERS_STRIPPED STREQUAL "ub") + set(ICEORYX2_SANITIZER_FLAGS ${ICEORYX2_SANITIZER_COMMON_FLAGS} -fsanitize=undefined -fno-sanitize-recover=undefined CACHE INTERNAL "") +elseif(SANITIZERS_STRIPPED STREQUAL "address;ub") + set(ICEORYX2_SANITIZER_FLAGS ${ICEORYX2_SANITIZER_COMMON_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined -fno-sanitize-recover=undefined ${ICEORYX2_SANITIZER_BLACKLIST} CACHE INTERNAL "") +elseif(SANITIZERS_STRIPPED STREQUAL "thread") + set(ICEORYX2_SANITIZER_FLAGS ${ICEORYX2_SANITIZER_COMMON_FLAGS} -fsanitize=thread CACHE INTERNAL "") else() - message(FATAL_ERROR "Invalid SANITIZERS value: '${SANITIZERS}'. Valid options are: 'address', 'ub', 'address;ub', 'thread', or empty string (disabled)") + message(FATAL_ERROR "Invalid SANITIZERS value: '${SANITIZERS_STRIPPED}' (original: '${SANITIZERS}'). Valid options are: 'address', 'ub', 'address;ub', 'thread', or empty string (disabled)") +endif() + +# Export the blacklist directory path for use in CI +if(DEFINED ICEORYX2_SANITIZER_BLACKLIST_DIR) + set(ICEORYX2_SANITIZER_BLACKLIST_DIR ${ICEORYX2_SANITIZER_BLACKLIST_DIR} CACHE PATH "Path to sanitizer blacklist directory" FORCE) endif() diff --git a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake index 44d55458db..62554e2e66 100644 --- a/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake +++ b/iceoryx2-cmake-modules/platform/mac/modules/Iceoryx2PlatformSettings.cmake @@ -44,4 +44,7 @@ if(DEFINED SANITIZERS AND NOT SANITIZERS STREQUAL "") set(ICEORYX2_CXX_FLAGS ${ICEORYX2_CXX_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") set(ICEORYX2_TEST_CXX_FLAGS ${ICEORYX2_TEST_CXX_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") + # Sanitizer flags must also be added to linker flags + set(ICEORYX2_LINK_FLAGS ${ICEORYX2_LINK_FLAGS} ${ICEORYX2_SANITIZER_FLAGS} CACHE INTERNAL "") + endif()