Skip to content

Commit d798e2a

Browse files
committed
compile opt: safer
1 parent 95e9df5 commit d798e2a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if(ci STREQUAL "cov")
1111
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") # gcov req
1212
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0") # gcov req
1313
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-abs-path") # gcc 8
14+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") # valgrind req
1415

1516
add_compile_definitions(SMART_LOG)
1617
add_compile_definitions(WITH_HID_LOG) # more info to debug ci
@@ -20,13 +21,19 @@ elseif(ci STREQUAL "asan")
2021
set(CMAKE_CXX_STANDARD 17) # low c++ version for wide usage; 17 since "if constexpr()"
2122
message("!!! asan+lsan+ubsan for: use-after-free, double-free, out-of-bound, leak, undef behavior")
2223
add_compile_options(-g -fno-omit-frame-pointer)
24+
add_compile_options(-fstack-protector-strong) # stack overflow protection
25+
add_compile_options(-O2) # required for FORTIFY_SOURCE
26+
add_compile_definitions(_FORTIFY_SOURCE=2) # buffer overflow checks
2327
add_compile_options(-fsanitize=address,undefined)
2428
add_link_options (-fsanitize=address,undefined)
2529

2630
elseif(ci STREQUAL "tsan") # asan/lsan/msan cover by valgrind(memcheck)
2731
set(CMAKE_CXX_STANDARD 17)
2832
message("!!! SANITIZE for: thread")
2933
add_compile_options(-g -fno-omit-frame-pointer)
34+
add_compile_options(-fstack-protector-strong) # stack overflow protection
35+
add_compile_options(-O2) # required for FORTIFY_SOURCE
36+
add_compile_definitions(_FORTIFY_SOURCE=2) # buffer overflow checks
3037
add_compile_options(-fsanitize=thread)
3138
add_link_options (-fsanitize=thread)
3239

0 commit comments

Comments
 (0)