Skip to content

Allow turning on multiple sanitizers #611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -64,23 +63,21 @@ 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:
submodules: true

# 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

Expand Down Expand Up @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading