summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Kientzle <kientzle@acm.org>2022-07-31 09:06:34 -0700
committerGitHub <noreply@github.com>2022-07-31 09:06:34 -0700
commitbd9f5577abf5dc76a3d1d859619404451bc203d2 (patch)
tree26735b8a56cee35164f2d0a248596e8916d2cc0f
parenta45905b0166713760a2fb4f2e908d7ce47488371 (diff)
parent120bef7014399259c8efefcde85e3bca67318c25 (diff)
downloadlibarchive-bd9f5577abf5dc76a3d1d859619404451bc203d2.tar.gz
Merge pull request #1751 from yugr/hide-symbols
Hide internal symbols on platforms that support visibility annotations
-rw-r--r--CMakeLists.txt11
-rw-r--r--configure.ac12
-rw-r--r--libarchive/CMakeLists.txt1
-rw-r--r--libarchive/archive.h2
-rw-r--r--libarchive/archive_entry.h2
5 files changed, 28 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/CMakeLists.txt b/libarchive/CMakeLists.txt
index 44895ce3..ff7ade00 100644
--- a/libarchive/CMakeLists.txt
+++ b/libarchive/CMakeLists.txt
@@ -82,6 +82,7 @@ SET(libarchive_SOURCES
archive_read_set_format.c
archive_read_set_options.c
archive_read_support_filter_all.c
+ archive_read_support_filter_by_code.c
archive_read_support_filter_bzip2.c
archive_read_support_filter_compress.c
archive_read_support_filter_gzip.c
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