]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Add support for internal attribute, the advantage of this over hidden
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Thu, 28 Apr 2016 09:04:15 +0000 (11:04 +0200)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Thu, 28 Apr 2016 11:39:13 +0000 (13:39 +0200)
is for example that the compiler can safely assume that pointers to
functions declared internal can never be passed externally.
This allows the compiler to consider optimizations otherwise impossible.

configure
zutil.h

index d437c20958fd9f85837f573fe4d7a70c3ea6faca..1c41b4a1ad27ef18c8914e8715175eabe5dde045 100755 (executable)
--- a/configure
+++ b/configure
@@ -582,7 +582,7 @@ else
   leave 1
 fi
 
-# see if we can hide zlib internal symbols that are linked between separate source files
+# 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
   cat > $test.c <<EOF
@@ -597,10 +597,32 @@ EOF
     CFLAGS="$CFLAGS -DHAVE_HIDDEN"
     SFLAGS="$SFLAGS -DHAVE_HIDDEN"
     echo >> configure.log
-    echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
+    echo "Checking for attribute(visibility(hidden)) support... Yes." | tee -a configure.log
   else
     echo >> configure.log
-    echo "Checking for attribute(visibility) support... No." | tee -a configure.log
+    echo "Checking for attribute(visibility(hidden)) support... No." | tee -a configure.log
+  fi
+fi
+
+# see if we can hide zlib internal symbols that are linked between separate source files using internal
+if test "$gcc" -eq 1; then
+  echo >> configure.log
+  cat > $test.c <<EOF
+#define ZLIB_INTERNAL __attribute__((visibility ("internal")))
+int ZLIB_INTERNAL foo;
+int main()
+{
+  return 0;
+}
+EOF
+  if tryboth $CC -c $CFLAGS $test.c; then
+    CFLAGS="$CFLAGS -DHAVE_INTERNAL"
+    SFLAGS="$SFLAGS -DHAVE_INTERNAL"
+    echo >> configure.log
+    echo "Checking for attribute(visibility(internal)) support... Yes." | tee -a configure.log
+  else
+    echo >> configure.log
+    echo "Checking for attribute(visibility(internal)) support... No." | tee -a configure.log
   fi
 fi
 
diff --git a/zutil.h b/zutil.h
index c56ca71f199afb92a4835febdae68b9423e3536b..b6e858c9cd29b70a6813060cb11e7caf5abcb615 100644 (file)
--- a/zutil.h
+++ b/zutil.h
@@ -12,7 +12,9 @@
 
 /* @(#) $Id$ */
 
-#ifdef HAVE_HIDDEN
+#if defined(HAVE_INTERNAL)
+#  define ZLIB_INTERNAL __attribute__((visibility ("internal")))
+#elif defined(HAVE_HIDDEN)
 #  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
 #else
 #  define ZLIB_INTERNAL