add -fstack-protector-strong and -D_FORTIFY_SOURCE=2 compiler options for SP and FS. add -s link options for Strip.
Signed-off-by: veega zhuweijia@huawei.com --- CMakeLists.txt | 6 +++--- libhikptdev/src/rciep/CMakeLists.txt | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt index 174dd8f..cbd063c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,8 @@
project(hikptool C)
-set(CMAKE_C_FLAGS - "${CMAKE_C_FLAGS} -O2 -fPIC -fPIE -Wall -Wextra -fno-common -std=gnu11 -Wfloat-equal") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -fPIC -fPIE -Wall -Wextra -fno-common -std=gnu11") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wfloat-equal -fstack-protector-strong -D_FORTIFY_SOURCE=2") set(CMAKE_SKIP_RPATH TRUE)
macro(get_header_dir_recurse HEADER_DIR_LIST) @@ -46,5 +46,5 @@ target_link_directories(hikptool PRIVATE ${CMAKE_INSTALL_PREFIX}/lib) target_link_libraries(hikptool PRIVATE KPTDEV_SO) target_link_options(hikptool PRIVATE -Wl,-z,relro,-z,now -Wl,-z,noexecstack -fPIE -pie - -g -lpthread -ldl -lm -lrt -T ${CMAKE_CURRENT_SOURCE_DIR}/hikp_register.ld) + -s -lpthread -ldl -lm -lrt -T ${CMAKE_CURRENT_SOURCE_DIR}/hikp_register.ld) install(TARGETS hikptool RUNTIME DESTINATION bin OPTIONAL) diff --git a/libhikptdev/src/rciep/CMakeLists.txt b/libhikptdev/src/rciep/CMakeLists.txt index b96d621..5017f5b 100644 --- a/libhikptdev/src/rciep/CMakeLists.txt +++ b/libhikptdev/src/rciep/CMakeLists.txt @@ -17,5 +17,7 @@ add_library(KPTDEV_SO SHARED hikpt_rciep.c)
target_include_directories(KPTDEV_SO PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+target_link_options(KPTDEV_SO PRIVATE -Wl,-z,relro,-z,now -Wl,-z,noexecstack -fPIE -pie -s) + set_target_properties(KPTDEV_SO PROPERTIES OUTPUT_NAME ${KPTDEV_SO_NAME} SOVERSION 1 VERSION 1.0.0) -install(TARGETS KPTDEV_SO LIBRARY DESTINATION lib OPTIONAL) \ No newline at end of file +install(TARGETS KPTDEV_SO LIBRARY DESTINATION lib OPTIONAL)