Skip to content

Commit

Permalink
Add ASAN/MSAN/UBSAN support to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Nov 12, 2023
1 parent 843f216 commit f36215a
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 26 deletions.
83 changes: 59 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,96 @@ on:
jobs:
linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
buildType: [Debug, Release]
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: build
run: |
make -j$(getconf _NPROCESSORS_ONLN) CONFIG_WERROR=y all run-test262
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=${{matrix.buildType}} ..
cd ..
cmake --build build -j$(getconf _NPROCESSORS_ONLN)
- name: stats
run: |
./build/qjs -qd
- name: test
run: |
make test test2
./build/qjs tests/test_bigint.js
./build/qjs tests/test_closure.js
./build/qjs tests/test_language.js
./build/qjs tests/test_builtin.js
./build/qjs tests/test_loop.js
./build/qjs tests/test_std.js
./build/qjs tests/test_worker.js
- name: test 262
run: |
time ./build/run-test262 -m -c test262.conf -a
linux-asan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: build
run: |
mkdir build
cd build
cmake -DCONFIG_ASAN=ON ..
cd ..
cmake --build build -j$(getconf _NPROCESSORS_ONLN)
- name: test
env:
ASAN_OPTIONS: halt_on_error=1
run: |
make -j$(getconf _NPROCESSORS_ONLN) CONFIG_WERROR=y CONFIG_ASAN=y ASAN_OPTIONS="halt_on_error=1" test
./build/qjs tests/test_bigint.js
./build/qjs tests/test_closure.js
./build/qjs tests/test_language.js
./build/qjs tests/test_builtin.js
./build/qjs tests/test_loop.js
./build/qjs tests/test_std.js
./build/qjs tests/test_worker.js
linux-msan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: test
- name: build
env:
CC: clang
run: |
make -j$(getconf _NPROCESSORS_ONLN) CONFIG_WERROR=y CONFIG_MSAN=y CONFIG_CLANG=y MSAN_OPTIONS="halt_on_error=1" test
linux-ubsan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
mkdir build
cd build
cmake -DCONFIG_MSAN=ON ..
cd ..
cmake --build build -j$(getconf _NPROCESSORS_ONLN)
- name: test
env:
MSAN_OPTIONS: halt_on_error=1
run: |
make -j$(getconf _NPROCESSORS_ONLN) CONFIG_WERROR=y CONFIG_UBSAN=y UBSAN_OPTIONS="halt_on_error=1" test
linux-cmake:
./build/qjs tests/test_bigint.js
./build/qjs tests/test_closure.js
./build/qjs tests/test_language.js
./build/qjs tests/test_builtin.js
./build/qjs tests/test_loop.js
./build/qjs tests/test_std.js
./build/qjs tests/test_worker.js
linux-ubsan:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
buildType: [Debug, Release]
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: build
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=${{matrix.buildType}} ..
cmake -DCONFIG_UBSAN=ON ..
cd ..
cmake --build build -j$(getconf _NPROCESSORS_ONLN)
- name: stats
run: |
./build/qjs -qd
- name: test
env:
UBSAN_OPTIONS: halt_on_error=1
run: |
./build/qjs tests/test_bigint.js
./build/qjs tests/test_closure.js
Expand All @@ -77,9 +115,6 @@ jobs:
./build/qjs tests/test_loop.js
./build/qjs tests/test_std.js
./build/qjs tests/test_worker.js
- name: test 262
run: |
time ./build/run-test262 -m -c test262.conf -a
macos:
runs-on: macos-latest
Expand Down
45 changes: 43 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ project(quickjs LANGUAGES C)
# TODO:
# - LTO
# - Support cross-compilation
# - ASAN / MSAN / UBSAN
# - Install targets
# - Shared library target

Expand Down Expand Up @@ -51,7 +50,49 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
)
endif()

set(CMAKE_VERBOSE_MAKEFILE TRUE)
option(CONFIG_ASAN "Enable AddressSanitizer (ASan)" OFF)
option(CONFIG_MSAN "Enable MemorySanitizer (MSan)" OFF)
option(CONFIG_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF)

if(CONFIG_ASAN)
message(STATUS "Building with ASan")
add_compile_options(
-fsanitize=address
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
add_link_options(
-fsanitize=address
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
elseif(CONFIG_MSAN)
message(STATUS "Building with MSan")
add_compile_options(
-fsanitize=memory
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
add_link_options(
-fsanitize=memory
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
elseif(CONFIG_UBSAN)
message(STATUS "Building with UBSan")
add_compile_options(
-fsanitize=undefined
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
add_link_options(
-fsanitize=undefined
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
endif()

set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON")


# QuickJS library
Expand Down

0 comments on commit f36215a

Please sign in to comment.