Skip to content
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

Propagate sanitizer flags to all cmake deps #759

Merged
merged 14 commits into from
Jul 31, 2022
23 changes: 12 additions & 11 deletions .github/workflows/kvrocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,26 @@ jobs:
compiler: clang
- name: Ubuntu GCC ASan
os: ubuntu-18.04
without_jemalloc: -DDISABLE_JEMALLOC=ON
with_sanitizer: -DENABLE_ASAN=ON
compiler: gcc
# - name: Ubuntu GCC TSan
# os: ubuntu-18.04
# with_sanitizer: -DENABLE_TSAN=ON
# compiler: gcc
- name: Ubuntu GCC without Jemalloc
- name: Ubuntu GCC TSan
os: ubuntu-18.04
without_jemalloc: -DDISABLE_JEMALLOC=ON
with_sanitizer: -DENABLE_TSAN=ON
compiler: gcc
runtime_env_vars: TSAN_OPTIONS="suppressions=$(realpath ./tests/tsan-suppressions)"
- name: Ubuntu Clang ASan
os: ubuntu-18.04
with_sanitizer: -DENABLE_ASAN=ON
without_jemalloc: -DDISABLE_JEMALLOC=ON
compiler: clang
# - name: Ubuntu Clang TSan
# os: ubuntu-18.04
# with_sanitizer: -DENABLE_TSAN=ON
# compiler: clang
- name: Ubuntu Clang without Jemalloc
- name: Ubuntu Clang TSan
os: ubuntu-18.04
with_sanitizer: -DENABLE_TSAN=ON
without_jemalloc: -DDISABLE_JEMALLOC=ON
compiler: clang
runtime_env_vars: TSAN_OPTIONS="suppressions=$(realpath ./tests/tsan-suppressions)"
- name: Ubuntu GCC Ninja
os: ubuntu-18.04
with_ninja: --ninja
Expand Down Expand Up @@ -158,10 +156,13 @@ jobs:
run: ./x.py build -j$NPROC --unittest --compiler ${{ matrix.compiler }} ${{ matrix.with_ninja }} ${{ matrix.with_sanitizer }} ${{ matrix.without_jemalloc }} ${{ matrix.without_luajit }}

- name: Run Unit Test
run: ./build/unittest
run: |
export ${{ matrix.runtime_env_vars }}
./build/unittest

- name: Run Redis Tcl Test
run: |
export ${{ matrix.runtime_env_vars }}
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
cp $HOME/local/bin/redis-cli tests/tcl/redis-cli
cd tests/tcl
./runtest --dont-clean
Expand Down
38 changes: 23 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ if(ENABLE_ASAN AND ENABLE_TSAN)
message(FATAL_ERROR "ASan and TSan cannot be used at the same time")
endif()

if((ENABLE_ASAN OR ENABLE_TSAN) AND (NOT DISABLE_JEMALLOC))
message(FATAL_ERROR "ASan/TSan does not work well with JeMalloc")
endif()

if(ENABLE_ASAN)
if(ASAN_WITH_LSAN)
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5"))
message(FATAL_ERROR "leak sanitizer is not supported until gcc 5")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=leak")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=leak")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
endif()
if(ENABLE_TSAN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# GLIBC < 2.17 should explict specify the real time library when use clock_*
Expand Down Expand Up @@ -121,21 +144,6 @@ target_include_directories(kvrocks_objs PUBLIC src ${PROJECT_BINARY_DIR})
target_compile_features(kvrocks_objs PUBLIC cxx_std_11)
target_compile_options(kvrocks_objs PUBLIC ${WARNING_FLAGS} -fno-omit-frame-pointer)
target_link_libraries(kvrocks_objs PUBLIC -fno-omit-frame-pointer)
if(ENABLE_ASAN)
if(ASAN_WITH_LSAN)
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5"))
message(FATAL_ERROR "leak sanitizer is not supported until gcc 5")
endif()
target_compile_options(kvrocks_objs PUBLIC -fsanitize=leak)
target_link_libraries(kvrocks_objs PUBLIC -fsanitize=leak)
endif()
target_compile_options(kvrocks_objs PUBLIC -fsanitize=address)
target_link_libraries(kvrocks_objs PUBLIC -fsanitize=address)
endif()
if(ENABLE_TSAN)
target_compile_options(kvrocks_objs PUBLIC -fsanitize=thread)
target_link_libraries(kvrocks_objs PUBLIC -fsanitize=thread)
endif()
target_link_libraries(kvrocks_objs PUBLIC ${EXTERNAL_LIBS})
if(FOUND_UNWIND_LIB)
target_link_libraries(kvrocks_objs PUBLIC ${FOUND_UNWIND_LIB})
Expand Down
2 changes: 1 addition & 1 deletion cmake/lua.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if(NOT lua_POPULATED)
FetchContent_Populate(lua)

set(LUA_CXX ${CMAKE_CXX_COMPILER})
set(LUA_CFLAGS "${CMAKE_CXX_FLAGS} -fpermissive -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC= -DLUA_USE_MKSTEMP")
set(LUA_CFLAGS "-DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC= -DLUA_USE_MKSTEMP")
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(LUA_CFLAGS "${LUA_CFLAGS} -isysroot ${CMAKE_OSX_SYSROOT}")
endif()
Expand Down
6 changes: 2 additions & 4 deletions cmake/luajit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ if(NOT lua_POPULATED)
set(LUA_CFLAGS "${LUA_CFLAGS} -isysroot ${CMAKE_OSX_SYSROOT}")
endif()

set(MACOSX_TARGET "")
if (CMAKE_HOST_APPLE)
set(MACOSX_TARGET "MACOSX_DEPLOYMENT_TARGET=11.0")
set(MACOSX_TARGET "MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()

add_custom_target(make_luajit COMMAND make libluajit.a
"CFLAGS=${LUA_CFLAGS}"
${MACOSX_TARGET}
"CFLAGS=${LUA_CFLAGS}" ${MACOSX_TARGET}
WORKING_DIRECTORY ${luajit_SOURCE_DIR}/src
BYPRODUCTS ${luajit_SOURCE_DIR}/src/libluajit.a
)
Expand Down
22 changes: 22 additions & 0 deletions tests/tsan-suppressions
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# ThreadSanitizer suppressions file for Kvrocks
# refer to https://github.com/google/sanitizers/wiki/ThreadSanitizerSuppressions

# suppress data race in google::LogMessageTime::CalcGmtOffset()
race:google::LogMessageTime::CalcGmtOffset