Skip to content

Commit

Permalink
Merge pull request #124 from Sean-Der/main
Browse files Browse the repository at this point in the history
Enable clang sanitizers
  • Loading branch information
sepfy authored Sep 8, 2024
2 parents 6a9bbdb + e1132ea commit a97fbb0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ jobs:
build:

runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
submodules: recursive
- name: install
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: sanitizers

on: [push]

jobs:
build:
runs-on: ubuntu-20.04
env:
CC: clang
CXX: clang++
strategy:
matrix:
sanitizer:
- ADDRESS_SANITIZER
- MEMORY_SANITIZER
- THREAD_SANITIZER
- UNDEFINED_BEHAVIOR_SANITIZER
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: install
run: sudo apt-get update && sudo apt-get --no-install-recommends -y install cmake clang

- name: build
run: >
mkdir cmake ;
cd cmake ;
cmake .. -DENABLE_TESTS=true -D${{matrix.sanitizer}}=true;
make -j$(nproc);
run-parts ./tests/ || true;
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ project(peer)

option(ENABLE_TESTS "Enable tests" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(ADDRESS_SANITIZER "Build with AddressSanitizer." OFF)
option(MEMORY_SANITIZER "Build with MemorySanitizer." OFF)
option(THREAD_SANITIZER "Build with ThreadSanitizer." OFF)
option(UNDEFINED_BEHAVIOR_SANITIZER "Build with UndefinedBehaviorSanitizer." OFF)

include(ExternalProject)

Expand All @@ -30,6 +34,29 @@ set(DEP_LIBS "srtp2" "usrsctp" "mbedtls" "mbedcrypto" "mbedx509" "cjson")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")

function(enableSanitizer SANITIZER)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fsanitize=${SANITIZER} -fno-omit-frame-pointer -fno-optimize-sibling-calls" PARENT_SCOPE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${SANITIZER}" PARENT_SCOPE)
endfunction()

if(ADDRESS_SANITIZER)
enableSanitizer("address")
endif()

if(MEMORY_SANITIZER)
enableSanitizer("memory")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-memory-track-origins")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-memory-track-origins")
endif()

if(THREAD_SANITIZER)
enableSanitizer("thread")
endif()

if(UNDEFINED_BEHAVIOR_SANITIZER)
enableSanitizer("undefined")
endif()

add_definitions("-Wunused-variable -Werror=sequence-point -Werror=pointer-sign -Werror=return-type -Werror=sizeof-pointer-memaccess -Wincompatible-pointer-types -DHTTP_DO_NOT_USE_CUSTOM_CONFIG -DMQTT_DO_NOT_USE_CUSTOM_CONFIG")

add_subdirectory(src)
Expand Down

0 comments on commit a97fbb0

Please sign in to comment.