summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Gribov <tetra2005@gmail.com>2022-07-03 10:54:39 +0300
committerYuri Gribov <tetra2005@gmail.com>2022-07-27 21:46:34 +0300
commit5235554eb4071c798fef9b29f46e9c96970055ea (patch)
treed9f57aa29bef3f36990a6150bfee9963f2c5ed33
parenta45905b0166713760a2fb4f2e908d7ce47488371 (diff)
downloadlibarchive-5235554eb4071c798fef9b29f46e9c96970055ea.tar.gz
Hide internal symbols on platforms that support visibility annotations (see discussion in gh-1017).
-rw-r--r--CMakeLists.txt11
-rw-r--r--configure.ac12
-rw-r--r--libarchive/archive.h2
-rw-r--r--libarchive/archive_entry.h2
4 files changed, 27 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1e1ff575..df83ed18 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2024,6 +2024,17 @@ CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA512" LIBMD)
CHECK_CRYPTO_WIN("MD5;SHA1;SHA256;SHA384;SHA512")
+# Check visibility annotations
+SET(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
+SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fvisibility=hidden -Werror")
+CHECK_C_SOURCE_COMPILES("void __attribute__((visibility(\"default\"))) foo(void);
+int main() { return 0; }" HAVE_VISIBILITY_ATTR)
+IF (HAVE_VISIBILITY_ATTR)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
+ ADD_DEFINITIONS(-D__LIBARCHIVE_ENABLE_VISIBILITY)
+ENDIF(HAVE_VISIBILITY_ATTR)
+SET(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}")
+
# Generate "config.h" from "build/cmake/config.h.in"
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
diff --git a/configure.ac b/configure.ac
index b30430d2..cc51badc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1247,6 +1247,18 @@ case "$host_os" in
;;
esac
+dnl Visibility annotations...
+saved_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -fvisibility=hidden -Werror"
+AC_MSG_CHECKING(whether compiler supports visibility annotations)
+AC_LINK_IFELSE([AC_LANG_PROGRAM([
+ int foo( void ) __attribute__((visibility("default")));
+ ])],
+ [CFLAGS="$saved_CFLAGS -fvisibility=hidden -D__LIBARCHIVE_ENABLE_VISIBILITY";
+ AC_MSG_RESULT(yes)],
+ [CFLAGS="$saved_CFLAGS"
+ AC_MSG_RESULT(no)])
+
# Ensure test directories are present if building out-of-tree
AC_CONFIG_COMMANDS([mkdirs],
[mkdir -p libarchive/test tar/test cat/test cpio/test])
diff --git a/libarchive/archive.h b/libarchive/archive.h
index 7f58a1f2..dcb8b0df 100644
--- a/libarchive/archive.h
+++ b/libarchive/archive.h
@@ -120,6 +120,8 @@ typedef ssize_t la_ssize_t;
# define __LA_DECL __declspec(dllimport)
# endif
# endif
+#elif defined __LIBARCHIVE_ENABLE_VISIBILITY
+# define __LA_DECL __attribute__((visibility("default")))
#else
/* Static libraries or non-Windows needs no special declaration. */
# define __LA_DECL
diff --git a/libarchive/archive_entry.h b/libarchive/archive_entry.h
index 450b3cf9..e579e9f3 100644
--- a/libarchive/archive_entry.h
+++ b/libarchive/archive_entry.h
@@ -122,6 +122,8 @@ typedef ssize_t la_ssize_t;
# define __LA_DECL __declspec(dllimport)
# endif
# endif
+#elif defined __LIBARCHIVE_ENABLE_VISIBILITY
+# define __LA_DECL __attribute__((visibility("default")))
#else
/* Static libraries on all platforms and shared libraries on non-Windows. */
# define __LA_DECL