diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-12-22 21:48:31 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-12-31 14:26:12 +0000 |
commit | 776b44f17b44b92b08f8cc37ec87e74ac68762ea (patch) | |
tree | a2ef598f0454073e7e903b238a817ab755ae4acb /cmake | |
parent | Merge pull request #2955 (diff) | |
download | monero-776b44f17b44b92b08f8cc37ec87e74ac68762ea.tar.xz |
Add misc hardening flags to the cmake machinery
See https://wiki.debian.org/Hardening#User_Space
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/CheckLinkerFlag.c | 14 | ||||
-rw-r--r-- | cmake/CheckLinkerFlag.cmake | 47 |
2 files changed, 61 insertions, 0 deletions
diff --git a/cmake/CheckLinkerFlag.c b/cmake/CheckLinkerFlag.c new file mode 100644 index 000000000..a0dcc168d --- /dev/null +++ b/cmake/CheckLinkerFlag.c @@ -0,0 +1,14 @@ +#ifdef __CLASSIC_C__ +int main() +{ + int ac; + char* av[]; +#else +int main(int ac, char* av[]) +{ +#endif + if (ac > 1000) { + return *av[0]; + } + return 0; +} diff --git a/cmake/CheckLinkerFlag.cmake b/cmake/CheckLinkerFlag.cmake new file mode 100644 index 000000000..a3879d0be --- /dev/null +++ b/cmake/CheckLinkerFlag.cmake @@ -0,0 +1,47 @@ +include(CheckCCompilerFlag) + +macro(CHECK_LINKER_FLAG flag VARIABLE) + if(NOT DEFINED "${VARIABLE}") + if(NOT CMAKE_REQUIRED_QUIET) + message(STATUS "Looking for ${flag} linker flag") + endif() + + set(_cle_source ${CMAKE_SOURCE_DIR}/cmake/CheckLinkerFlag.c) + + set(saved_CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) + set(CMAKE_C_FLAGS "${flag}") + try_compile(${VARIABLE} + ${CMAKE_BINARY_DIR} + ${_cle_source} + COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} ${flag} + CMAKE_FLAGS + OUTPUT_VARIABLE OUTPUT) + unset(_cle_source) + set(CMAKE_C_FLAGS ${saved_CMAKE_C_FLAGS}) + unset(saved_CMAKE_C_FLAGS) + + if ("${OUTPUT}" MATCHES "warning.*ignored") + set(${VARIABLE} 0) + endif() + + if(${VARIABLE}) + if(NOT CMAKE_REQUIRED_QUIET) + message(STATUS "Looking for ${flag} linker flag - found") + endif() + set(${VARIABLE} 1 CACHE INTERNAL "Have linker flag ${flag}") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the ${flag} linker flag is supported " + "passed with the following output:\n" + "${OUTPUT}\n\n") + else() + if(NOT CMAKE_REQUIRED_QUIET) + message(STATUS "Looking for ${flag} linker flag - not found") + endif() + set(${VARIABLE} "" CACHE INTERNAL "Have linker flag ${flag}") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the ${flag} linker flag is suppored " + "failed with the following output:\n" + "${OUTPUT}\n\n") + endif() + endif() +endmacro() |