Skip to content

Commit

Permalink
Added default sanitizer options (vesoft-inc#108)
Browse files Browse the repository at this point in the history
* Added default sanitizer options

* add comments

* Fixed FindPCH

* GCC 7.3 doesnt support no_sanitize attributes
  • Loading branch information
dutor authored Jan 18, 2019
1 parent 03ffc15 commit 454929e
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 39 deletions.
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(CMAKE_CXX_STANDARD 14)

set(CMAKE_EXE_LINKER_FLAGS "-static-libstdc++")

# CMake macro to specify number of jobs to build third-party
if (NOT THIRD_PARTY_JOBS)
set(THIRD_PARTY_JOBS 2)
endif(NOT THIRD_PARTY_JOBS)
Expand All @@ -43,14 +44,17 @@ endif(NOT THIRD_PARTY_JOBS)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif(NOT CMAKE_BUILD_TYPE)
message("== Build type is " ${CMAKE_BUILD_TYPE} " ==")

message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}, "
"options: Debug, Release, RelWithDebInfo, MinSizeRel")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "_build")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "_build")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "_build")

# Set the project home dir
set(NEBULA_HOME ${CMAKE_CURRENT_SOURCE_DIR})
add_definitions(-DNEBULA_HOME=${NEBULA_HOME})

# To include customized FindXXX.cmake modules
set(CMAKE_MODULE_PATH "${NEBULA_HOME}/cmake" ${CMAKE_MODULE_PATH})
Expand Down Expand Up @@ -121,12 +125,22 @@ add_compile_options(-Wunused-parameter)
add_compile_options(-Wshadow)

if(asan)
add_definitions(-DBUILT_WITH_SANITIZER)
add_compile_options(-fsanitize=address)
add_compile_options(-g)
add_compile_options(-fno-omit-frame-pointer)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
endif()

macro(nebula_add_test test_name)
add_test(NAME ${test_name} COMMAND ${test_name})
# e.g. cmake -DNEBULA_ASAN_PRELOAD=/path/to/libasan.so
# or, cmake -DNEBULA_ASAN_PRELOAD=`/path/to/gcc --print-file-name=libasan.so`
if (NEBULA_ASAN_PRELOAD)
set_property(TEST ${test_name} PROPERTY ENVIRONMENT LD_PRELOAD=${NEBULA_ASAN_PRELOAD})
endif(NEBULA_ASAN_PRELOAD)
endmacro(nebula_add_test)

include_directories(SYSTEM ${NEBULA_HOME}/third-party/bzip2/_install/include)
include_directories(SYSTEM ${NEBULA_HOME}/third-party/double-conversion/_install/include)
include_directories(SYSTEM ${NEBULA_HOME}/third-party/fatal/_install/include)
Expand Down
4 changes: 3 additions & 1 deletion cmake/FindPCHSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ MACRO(ADD_PRECOMPILED_HEADER _targetName _input _dep)
ENDFOREACH(item)

GET_DIRECTORY_PROPERTY(_directory_flags COMPILE_DEFINITIONS)
LIST(APPEND _compiler_FLAGS ${_directory_flags})
FOREACH(item ${_directory_flags})
LIST(APPEND _compiler_FLAGS "-D${item}")
ENDFOREACH(item)

SEPARATE_ARGUMENTS(_compiler_FLAGS)
MESSAGE("Precompile header file " ${_source} " into " ${_output})
Expand Down
3 changes: 3 additions & 0 deletions src/common/base/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
_Pragma("GCC optimize(\"O0\")")
#define END_NO_OPTIMIZATION _Pragma("GCC pop_options")

#define NEBULA_STRINGIFY(STR) NEBULA_STRINGIFY_X(STR)
#define NEBULA_STRINGIFY_X(STR) #STR

#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif // UNUSED
Expand Down
1 change: 1 addition & 0 deletions src/common/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_library(
Cord.cpp
Configuration.cpp
Status.cpp
SanitizerOptions.cpp
)
add_dependencies(base_obj third-party)
IF(${PCHSupport_FOUND})
Expand Down
65 changes: 65 additions & 0 deletions src/common/base/SanitizerOptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved
*
* This source code is licensed under Apache 2.0 License
* (found in the LICENSE.Apache file in the root directory)
*/
#include "base/Base.h"

#ifdef BUILT_WITH_SANITIZER

// Following hook functions are required by the sanitizer runtime library.
// So make them exported.
// Besides, keep these hooks outside the consideration of sanitizer
#define SANITIZER_HOOK_ATTRIBUTES \
__attribute__((visibility("default"))) \
// __attribute__((no_sanitize("address", "thread", "undefined")))

extern "C" {

SANITIZER_HOOK_ATTRIBUTES
const char* __asan_default_options() {
// You could add new or update existing options via ASAN_OPTIONS at runtime.
return ""
"fast_unwind_on_malloc=0 \n"
"detect_stack_use_after_return=1 \n"
"alloc_dealloc_mismatch=1 \n"
"new_delete_type_mismatch=1 \n"
"strict_init_order=1 \n"
"intercept_tls_get_addr=1 \n"
"symbolize_inline_frames=1 \n"
"strict_string_checks=1 \n"
"detect_container_overflow=1 \n"
"strip_path_prefix=" NEBULA_STRINGIFY(NEBULA_HOME) "/ \n"
"";
}


SANITIZER_HOOK_ATTRIBUTES
const char* __asan_default_suppressions() {
return ""
""
"";
}


SANITIZER_HOOK_ATTRIBUTES
const char* __lsan_default_options() {
return ""
""
"";
}


SANITIZER_HOOK_ATTRIBUTES
const char* __lsan_default_suppressions() {
// NOTE Don't add extra spaces around the suppression patterns, unless you intend to.
return ""
"leak:folly::SingletonVault::destroyInstances\n"
"";
}

} // extern "C"

#undef SANITIZER_HOOK_ATTRIBUTES

#endif
10 changes: 5 additions & 5 deletions src/common/base/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME cord_test COMMAND cord_test)
nebula_add_test(cord_test)


add_executable(cord_bm CordBenchmark.cpp $<TARGET_OBJECTS:base_obj>)
Expand Down Expand Up @@ -37,7 +37,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME murmurhash2_test COMMAND murmurhash2_test)
nebula_add_test(murmurhash2_test)

add_executable(
configuration_test
Expand All @@ -56,7 +56,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME configuration_test COMMAND configuration_test)
nebula_add_test(configuration_test)

add_executable(
status_test
Expand All @@ -75,7 +75,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME status_test COMMAND status_test)
nebula_add_test(status_test)

add_executable(
status_or_test
Expand All @@ -94,7 +94,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME status_or_test COMMAND status_or_test)
nebula_add_test(status_or_test)

add_executable(hash_bm HashBenchmark.cpp $<TARGET_OBJECTS:base_obj>)
target_link_libraries(
Expand Down
2 changes: 1 addition & 1 deletion src/common/concurrent/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ target_link_libraries(
pthread
dl
)
add_test(NAME concurrent_test COMMAND concurrent_test)
nebula_add_test(concurrent_test)
6 changes: 3 additions & 3 deletions src/common/fs/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME file_utils_test COMMAND file_utils_test)
nebula_add_test(file_utils_test)

add_executable(
temp_dir_test
Expand All @@ -32,7 +32,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME temp_dir_test COMMAND temp_dir_test)
nebula_add_test(temp_dir_test)

add_executable(
temp_file_test
Expand All @@ -51,5 +51,5 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME temp_file_test COMMAND temp_file_test)
nebula_add_test(temp_file_test)

2 changes: 1 addition & 1 deletion src/common/network/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME network_utils_test COMMAND network_utils_test)
nebula_add_test(network_utils_test)

add_executable(
network_utils_bm
Expand Down
2 changes: 1 addition & 1 deletion src/common/process/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME process_test COMMAND process_test)
nebula_add_test(process_test)
2 changes: 1 addition & 1 deletion src/common/thread/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ target_link_libraries(
pthread
dl
)
add_test(NAME thread_test COMMAND thread_test)
nebula_add_test(thread_test)
2 changes: 1 addition & 1 deletion src/common/time/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ target_link_libraries(
-pthread
)

add_test(NAME duration_test COMMAND duration_test)
nebula_add_test(duration_test)

add_executable(
duration_bm
Expand Down
8 changes: 4 additions & 4 deletions src/dataman/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME row_reader_test COMMAND row_reader_test)
nebula_add_test(row_reader_test)


add_executable(
Expand All @@ -49,7 +49,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME row_writer_test COMMAND row_writer_test)
nebula_add_test(row_writer_test)


add_executable(
Expand All @@ -76,7 +76,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME row_updater_test COMMAND row_updater_test)
nebula_add_test(row_updater_test)


add_executable(
Expand All @@ -103,7 +103,7 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME rowset_reader_writer_test COMMAND rowset_reader_writer_test)
nebula_add_test(rowset_reader_writer_test)


add_executable(
Expand Down
4 changes: 2 additions & 2 deletions src/graph/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ target_link_libraries(
-pthread
)

add_test(NAME session_manager_test COMMAND session_manager_test)
nebula_add_test(session_manager_test)


add_executable(
Expand Down Expand Up @@ -70,4 +70,4 @@ target_link_libraries(
dl
-pthread
)
add_test(NAME query_engine_test COMMAND query_engine_test)
nebula_add_test(query_engine_test)
8 changes: 4 additions & 4 deletions src/kvstore/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ target_link_libraries(
z
-pthread
)
add_test(NAME part_test COMMAND part_test)
nebula_add_test(part_test)

add_executable(
rocksdb_engine_test
Expand Down Expand Up @@ -52,7 +52,7 @@ target_link_libraries(
z
-pthread
)
add_test(NAME rocksdb_engine_test COMMAND rocksdb_engine_test)
nebula_add_test(rocksdb_engine_test)

add_executable(
kvstore_test
Expand Down Expand Up @@ -80,7 +80,7 @@ target_link_libraries(
z
-pthread
)
add_test(NAME kvstore_test COMMAND kvstore_test)
nebula_add_test(kvstore_test)

add_executable(
load_test
Expand All @@ -107,4 +107,4 @@ target_link_libraries(
z
-pthread
)
add_test(NAME load_test COMMAND load_test)
nebula_add_test(load_test)
6 changes: 3 additions & 3 deletions src/parser/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ target_link_libraries(
-pthread
)
target_include_directories(parser_test SYSTEM BEFORE PUBLIC ${FLEX_INCLUDE_DIRS})
add_test(NAME parser_test COMMAND parser_test)
nebula_add_test(parser_test)

add_executable(
scanner_test
Expand All @@ -50,7 +50,7 @@ target_link_libraries(
-pthread
)
target_include_directories(scanner_test SYSTEM BEFORE PUBLIC ${FLEX_INCLUDE_DIRS})
add_test(NAME scanner_test COMMAND scanner_test)
nebula_add_test(scanner_test)

add_compile_options(-Wno-parentheses)

Expand Down Expand Up @@ -79,7 +79,7 @@ target_link_libraries(
-pthread
)
target_include_directories(expression_test SYSTEM BEFORE PUBLIC ${FLEX_INCLUDE_DIRS})
add_test(NAME expression_test COMMAND expression_test)
nebula_add_test(expression_test)

add_executable(
expression_encode_decode_bm
Expand Down
6 changes: 3 additions & 3 deletions src/raftex/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ target_link_libraries(
event
-pthread
)
add_test(NAME leader_election_test COMMAND leader_election_test)
nebula_add_test(leader_election_test)


add_executable(
Expand Down Expand Up @@ -71,7 +71,7 @@ target_link_libraries(
event
-pthread
)
add_test(NAME log_append_test COMMAND log_append_test)
nebula_add_test(log_append_test)


add_executable(
Expand Down Expand Up @@ -109,5 +109,5 @@ target_link_libraries(
event
-pthread
)
add_test(NAME log_cas_test COMMAND log_cas_test)
nebula_add_test(log_cas_test)

Loading

0 comments on commit 454929e

Please sign in to comment.