]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Disallow semantic interposition in ELF shared libraries if supported by the compiler.
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 11 Jan 2021 17:44:09 +0000 (18:44 +0100)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Mon, 11 Jan 2021 20:37:33 +0000 (21:37 +0100)
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.

CMakeLists.txt
configure

index 9ee040487124d5b91e21e1e22048395714f2b691..372f7f691789b27f48a778a6c8e5a9af854529f6 100644 (file)
@@ -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\"")
index b5a446287a8fa5eb1e2adbe69ce6f6cc2069f8e0..945f6ba915d17026831704d679079001a1856b20 100755 (executable)
--- a/configure
+++ b/configure
@@ -856,6 +856,18 @@ else
   leave 1
 fi
 
+# Check for -fno-semantic-interposition compiler support
+echo "" > test.c
+  cat > $test.c <<EOF
+int main() { return 0; }
+EOF
+if test "$gcc" -eq 1 && ($cc $CFLAGS -fno-semantic-interposition -c $test.c) >> configure.log 2>&1; then
+  echo "Checking for -no-semantic-interposition... Yes." | tee -a configure.log
+  SFLAGS="$SFLAGS -fno-semantic-interposition"
+else
+  echo "Checking for -no-semantic-interposition... No." | tee -a configure.log
+fi
+
 # see if we can hide zlib internal symbols that are linked between separate source files using hidden
 if test "$gcc" -eq 1; then
   echo >> configure.log