From: veega2022 zhuweijia@huawei.com
add compiler option -pie -fPIE, -Wl,-z,relro,-z,now and disable rpath
Signed-off-by: veega2022 zhuweijia@huawei.com --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d79a31..c697edf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,9 @@
project(hikptool C)
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -pie -fPIE -Wall") +set(CMAKE_SKIP_RPATH TRUE) + macro(get_header_dir_recurse HEADER_DIR_LIST) file(GLOB_RECURSE HEADER_LIST *.h) set(DIR_LIST "") @@ -40,5 +43,7 @@ get_header_dir_recurse(HIKPTOOL_HEADER_DIR) target_include_directories(hikptool PRIVATE ${HIKPTOOL_HEADER_DIR}) target_link_directories(hikptool PRIVATE ${CMAKE_INSTALL_PREFIX}/lib) target_link_libraries(hikptool PRIVATE KPTDEV_SO) -target_link_options(hikptool PRIVATE -g -lpthread -ldl -lm -lrt -T ${CMAKE_CURRENT_SOURCE_DIR}/hikp_register.ld) +target_link_options(hikptool PRIVATE + -Wl,-z,relro,-z,now -Wl,-z,noexecstack + -g -lpthread -ldl -lm -lrt -T ${CMAKE_CURRENT_SOURCE_DIR}/hikp_register.ld) install(TARGETS hikptool RUNTIME DESTINATION bin OPTIONAL)