From b0c0f123a91c295fcb641d44206a55f1ea8953e9 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sun, 26 Nov 2023 18:26:03 +0100 Subject: [PATCH 1/2] CI: Start using AddressSanitizer (ASan) and UndefinedBehaviorSanitizer (UBSan) --- .github/workflows/linux_and_macos.yml | 11 +++++++++-- recordings/record.sh | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux_and_macos.yml b/.github/workflows/linux_and_macos.yml index 19c6b85..4fe2abc 100644 --- a/.github/workflows/linux_and_macos.yml +++ b/.github/workflows/linux_and_macos.yml @@ -79,7 +79,8 @@ jobs: if: "${{ runner.os == 'Linux' && contains(matrix.cxx, 'clang') }}" run: |- sudo apt-get install --yes --no-install-recommends -V \ - clang-${{ matrix.clang_major_version }} + clang-${{ matrix.clang_major_version }} \ + libclang-rt-${{ matrix.clang_major_version }}-dev - name: Add versioned aliases for Clang ${{ matrix.clang_major_version }} if: "${{ runner.os == 'macOS' && contains(matrix.cxx, 'clang') }}" @@ -96,7 +97,13 @@ jobs: CC: ${{ matrix.cc }} CXX: ${{ matrix.cxx }} run: |- - CFLAGS='-std=gnu99 -pedantic -Werror' make + set -x + + # ASan: https://clang.llvm.org/docs/AddressSanitizer.html + # UBSan: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html + sanitizer='-fsanitize=address,undefined -fno-sanitize-recover=all' + + CFLAGS="-std=gnu99 -pedantic -Werror ${sanitizer}" LDFLAGS="${sanitizer}" make - name: 'Install' run: |- diff --git a/recordings/record.sh b/recordings/record.sh index b207b43..c337c14 100755 --- a/recordings/record.sh +++ b/recordings/record.sh @@ -27,7 +27,8 @@ rm -f actual*.* asciinema_args=( --cols 90 --rows 20 - -c 'timeout -s INT 3s sh -c "{ sleep 0.5; echo \"1 2 3 4\"; sleep 0.5; } | ttyplot -2 -c X"' + # MallocNanoZone=0 is for AddressSanitizer on macOS, see https://stackoverflow.com/a/70209891/11626624 . + -c 'timeout -s INT 3s sh -c "{ sleep 0.5; echo \"1 2 3 4\"; sleep 0.5; } | MallocNanoZone=0 ttyplot -2 -c X"' -t 'ttyplot waiting, drawing, and shutting down' ) From 64f5fd08851202272d023eb2b3058efb65347c28 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 27 Nov 2023 03:11:41 +0100 Subject: [PATCH 2/2] recordings: Give ttyplot more time in record.sh .. because sanitizers are slowing down runtime execution. --- recordings/record.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recordings/record.sh b/recordings/record.sh index c337c14..7b0dfe9 100755 --- a/recordings/record.sh +++ b/recordings/record.sh @@ -28,7 +28,7 @@ asciinema_args=( --cols 90 --rows 20 # MallocNanoZone=0 is for AddressSanitizer on macOS, see https://stackoverflow.com/a/70209891/11626624 . - -c 'timeout -s INT 3s sh -c "{ sleep 0.5; echo \"1 2 3 4\"; sleep 0.5; } | MallocNanoZone=0 ttyplot -2 -c X"' + -c 'timeout -s INT 5s sh -c "{ sleep 1.5; echo \"1 2 3 4\"; sleep 1.5; } | MallocNanoZone=0 ttyplot -2 -c X"' -t 'ttyplot waiting, drawing, and shutting down' )