diff options
author | Hans Kristian Rosbach <hk-git@circlestorm.org> | 2021-01-11 18:44:09 +0100 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2021-01-11 21:37:33 +0100 |
commit | 1f5890d760ffeb6a37d94e027e5eb0e1b865d607 (patch) | |
tree | 5e303b5cb584756af16b4d4e94aff94554e55f13 /CMakeLists.txt | |
parent | 446c6974fec0d3b8a55eef7ce36a249a9eb601ea (diff) |
Disallow semantic interposition in ELF shared libraries if supported by the compiler.
This disallows calls to our own exported functions being replaced by LD_PRELOAD, thus
avoiding the potential bugs and allowing the compiler to optimize better.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ee0404..372f7f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -364,6 +364,17 @@ elseif(WITH_SANITIZER STREQUAL "Memory") elseif(WITH_SANITIZER STREQUAL "Undefined") add_undefined_sanitizer() endif() + +# +# Check whether compiler supports -fno-semantic-interposition parameter +# +set(CMAKE_REQUIRED_FLAGS "-fno-semantic-interposition") +check_c_source_compiles( + "int main() { return 0; }" + HAVE_NO_INTERPOSITION +) +set(CMAKE_REQUIRED_FLAGS) + # # Check if we can hide zlib internal symbols that are linked between separate source files using hidden # @@ -936,6 +947,9 @@ if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS) endif() if(UNIX) + if(HAVE_NO_INTERPOSITION) + set_target_properties(zlib PROPERTIES COMPILE_FLAGS "-fno-semantic-interposition") + endif() if(NOT APPLE) set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib${SUFFIX}.map\"") |