From db6aec0850199750ba8a711d139d2b1c9c886f6c Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 18 Oct 2017 10:08:11 -0700 Subject: [PATCH] Add compiler switches replace dangerous function with safer ones. (#5089) * Add compiler switches replace the dangerous function with safer ones. * Add -02 and make linker flags per platform * add -O2 for arm and add -z,now * remove windows linker flags --- src/libpsl-native/CMakeLists.txt | 9 ++++++++- src/libpsl-native/arm.toolchain.cmake | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libpsl-native/CMakeLists.txt b/src/libpsl-native/CMakeLists.txt index 60d42a35294..e4f33cce07b 100644 --- a/src/libpsl-native/CMakeLists.txt +++ b/src/libpsl-native/CMakeLists.txt @@ -3,7 +3,14 @@ project(PSL-NATIVE) # Can't use add_compile_options with 2.8.11 set(CMAKE_BUILD_TYPE "Release") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -fstack-protector-strong -fpie") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -fstack-protector-strong -fpie -DFORTIFY_SOURCE=2 -O2") + +if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro,-z,now") +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl") +endif() + set(LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/../powershell-unix") if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm*") diff --git a/src/libpsl-native/arm.toolchain.cmake b/src/libpsl-native/arm.toolchain.cmake index c8f20e0e7dd..c2c68104d81 100644 --- a/src/libpsl-native/arm.toolchain.cmake +++ b/src/libpsl-native/arm.toolchain.cmake @@ -1,7 +1,8 @@ set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_VERSION 1) set(CMAKE_SYSTEM_PROCESSOR armv7l) -set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++ -fstack-protector-strong -fpie) +set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++ -fstack-protector-strong -fpie -DFORTIFY_SOURCE=2 -O2) +set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,relro,-z,now") set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) # add_compile_options(-target armv7-linux-gnueabihf)