add compiler option -g -pie -FPIE -Wall and link option -Wl,-z,relro,-z,now -Wl,-z,noexecstack Signed-off-by: veega2022 <zhuweijia@huawei.com>
40 lines
1.3 KiB
Diff
40 lines
1.3 KiB
Diff
From 0a4e7eb4cb35e126e9ca6e8e1f8f4282a008d0d2 Mon Sep 17 00:00:00 2001
|
|
From: veega2022 <zhuweijia@huawei.com>
|
|
Date: Tue, 13 Dec 2022 21:32:52 +0800
|
|
Subject: [PATCH] fix compiler security option problem
|
|
|
|
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)
|
|
--
|
|
2.33.0
|
|
|