From bed51fab0a9c9547bed4004fbc001107b05eade9 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 20 Oct 2024 12:41:17 +0200 Subject: [PATCH] Allow turning on multiple sanitizers (#611) Consolidate the ASan and UBSan buildbots and turn on both sanitizers when fuzzing. --- .github/workflows/ci.yml | 15 +++++---------- CMakeLists.txt | 16 +++++++++++++--- Makefile | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6ea6b7..12727fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,8 +52,7 @@ jobs: - { os: ubuntu-latest, configType: Release, runTest262: true, runV8: true } - { os: ubuntu-latest, configType: examples } - { os: ubuntu-latest, configType: shared } - - { os: ubuntu-latest, configType: asan, runTest262: true } - - { os: ubuntu-latest, configType: ubsan, runTest262: true } + - { os: ubuntu-latest, configType: asan+ubsan, runTest262: true } - { os: ubuntu-latest, configType: msan } - { os: ubuntu-latest, configType: tcc } - { os: ubuntu-latest, arch: x86 } @@ -64,15 +63,13 @@ jobs: - { os: macos-14, configType: Release } - { os: macos-14, configType: examples } - { os: macos-14, configType: shared } - - { os: macos-14, configType: asan } - - { os: macos-14, configType: ubsan } + - { os: macos-14, configType: asan+ubsan } - { os: macos-12, configType: Debug } - { os: macos-12, configType: Release } - { os: macos-12, configType: examples } - { os: macos-12, configType: shared } - - { os: macos-12, configType: asan } - - { os: macos-12, configType: ubsan } + - { os: macos-12, configType: asan+ubsan } steps: - uses: actions/checkout@v4 with: @@ -80,7 +77,7 @@ jobs: # ASLR with big PIE slides does not work well with [AM]San - name: disable ASLR - if: ${{ matrix.config.os == 'ubuntu-latest' && (matrix.config.configType == 'asan' || matrix.config.configType == 'ubsan' || matrix.config.configType == 'msan')}} + if: ${{ matrix.config.os == 'ubuntu-latest' && (matrix.config.configType == 'asan+ubsan' || matrix.config.configType == 'msan')}} run: | sudo sysctl -w kernel.randomize_va_space=0 @@ -119,11 +116,9 @@ jobs: echo "BUILD_EXAMPLES=ON" >> $GITHUB_ENV; elif [ "${{ matrix.config.configType }}" = "shared" ]; then echo "BUILD_SHARED_LIBS=ON" >> $GITHUB_ENV; - elif [ "${{ matrix.config.configType }}" = "asan" ]; then + elif [ "${{ matrix.config.configType }}" = "asan+ubsan" ]; then echo "BUILD_TYPE=RelWithDebInfo" >> $GITHUB_ENV; echo "CONFIG_ASAN=ON" >> $GITHUB_ENV; - elif [ "${{ matrix.config.configType }}" = "ubsan" ]; then - echo "BUILD_TYPE=RelWithDebInfo" >> $GITHUB_ENV; echo "CONFIG_UBSAN=ON" >> $GITHUB_ENV; elif [ "${{ matrix.config.configType }}" = "msan" ]; then echo "BUILD_TYPE=RelWithDebInfo" >> $GITHUB_ENV; diff --git a/CMakeLists.txt b/CMakeLists.txt index 572603d..651f3f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,10 @@ if(BUILD_SHARED_LIBS) message(STATUS "Building a shared library") endif() +# note: CONFIG_TSAN is currently incompatible with the other sanitizers but we +# don't explicitly check for that because who knows what the future will bring? +# CONFIG_MSAN only works with clang at the time of writing; also not checked +# for the same reason xoption(BUILD_EXAMPLES "Build examples" OFF) xoption(BUILD_STATIC_QJS_EXE "Build a static qjs executable" OFF) xoption(BUILD_CLI_WITH_MIMALLOC "Build the qjs executable with mimalloc" OFF) @@ -132,7 +136,9 @@ add_link_options( -fno-sanitize-recover=all -fno-omit-frame-pointer ) -elseif(CONFIG_MSAN) +endif() + +if(CONFIG_MSAN) message(STATUS "Building with MSan") add_compile_options( -fsanitize=memory @@ -144,7 +150,9 @@ add_link_options( -fno-sanitize-recover=all -fno-omit-frame-pointer ) -elseif(CONFIG_TSAN) +endif() + +if(CONFIG_TSAN) message(STATUS "Building with TSan") add_compile_options( -fsanitize=thread @@ -156,7 +164,9 @@ add_link_options( -fno-sanitize-recover=all -fno-omit-frame-pointer ) -elseif(CONFIG_UBSAN) +endif() + +if(CONFIG_UBSAN) message(STATUS "Building with UBSan") add_compile_definitions( __UBSAN__=1 diff --git a/Makefile b/Makefile index 684fe17..dda3af0 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ endif all: $(QJS) fuzz: - clang -g -O1 -fsanitize=fuzzer -o fuzz fuzz.c + clang -g -O1 -fsanitize=address,undefined,fuzzer -o fuzz fuzz.c ./fuzz $(BUILD_DIR):