>From 0d4727f431eb82524703551e59e861462f657047 Mon Sep 17 00:00:00 2001
From: Yury Usishchev
Date: Wed, 17 Feb 2016 13:38:54 +0300
Subject: [PATCH 2/2] Cleanup visibility of API functions
Import visibility_hidden.m4 macro from acl and use it in configure.ac
This will enable -fvisibility CFLAG when supported by compiler.
Mark API functions with default visibility attribute.
---
configure.ac | 1 +
include/Makemodule.am | 25 +++++++++++++++++++++----
include/attributes.h | 20 ++++++++++----------
include/libattr.h | 8 ++++----
libattr/syscalls.c | 8 ++++++++
m4/visibility_hidden.m4 | 40 ++++++++++++++++++++++++++++++++++++++++
6 files changed, 84 insertions(+), 18 deletions(-)
create mode 100644 m4/visibility_hidden.m4
diff --git a/configure.ac b/configure.ac
index a5f9de5..7260ce3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,6 +29,7 @@ AC_USE_SYSTEM_EXTENSIONS
AC_C_CONST
AC_TYPE_MODE_T
AC_FUNC_ALLOCA
+AC_FUNC_GCC_VISIBILITY
AM_PROG_AR
LT_INIT
diff --git a/include/Makemodule.am b/include/Makemodule.am
index 2ab600a..e4f56f9 100644
--- a/include/Makemodule.am
+++ b/include/Makemodule.am
@@ -1,9 +1,26 @@
-pkginclude_HEADERS += \
+noinst_HEADERS += \
include/attributes.h \
include/error_context.h \
- include/libattr.h
-
-noinst_HEADERS += \
+ include/libattr.h \
include/misc.h \
include/nls.h \
include/walk_tree.h
+
+
+SUBST_INSTALL_HEADER = \
+ subst_install_header() { \
+ file=`echo "$$1" | sed -e 's,^.*/,,'`; \
+ $(SED) -e "s/\/extern/" < "$$1" > "include/$$file.t" || exit 1; \
+ $(MKDIR_P) "$$2" || exit 1; \
+ $(INSTALL_HEADER) "include/$$file.t" "$$2/$$file" || exit 1; \
+ $(RM) "include/$$file.t"; \
+ }; \
+ subst_install_header
+
+install-attributes_h: include/attributes.h
+ $(SUBST_INSTALL_HEADER) "$<" "$(DESTDIR)$(pkgincludedir)"
+install-error_context_h: include/error_context.h
+ $(SUBST_INSTALL_HEADER) "$<" "$(DESTDIR)$(pkgincludedir)"
+install-libattr_h: include/libattr.h
+ $(SUBST_INSTALL_HEADER) "$<" "$(DESTDIR)$(pkgincludedir)"
+install-data-local: install-attributes_h install-error_context_h install-libattr_h
diff --git a/include/attributes.h b/include/attributes.h
index 8b73c5c..14beb8f 100644
--- a/include/attributes.h
+++ b/include/attributes.h
@@ -125,10 +125,10 @@ typedef struct attr_multiop {
* be set to the actual number of bytes used in the value buffer upon return.
* The return value is -1 on error (w/errno set appropriately), 0 on success.
*/
-extern int attr_get (const char *__path, const char *__attrname,
+EXPORT int attr_get (const char *__path, const char *__attrname,
char *__attrvalue, int *__valuelength, int __flags)
__attribute__ ((deprecated ("Use getxattr or lgetxattr instead")));
-extern int attr_getf (int __fd, const char *__attrname, char *__attrvalue,
+EXPORT int attr_getf (int __fd, const char *__attrname, char *__attrvalue,
int *__valuelength, int __flags)
__attribute__ ((deprecated ("Use fgetxattr instead")));
@@ -136,11 +136,11 @@ extern int attr_getf (int __fd, const char *__attrname, char *__attrvalue,
* Set the value of an attribute, creating the attribute if necessary.
* The return value is -1 on error (w/errno set appropriately), 0 on success.
*/
-extern int attr_set (const char *__path, const char *__attrname,
+EXPORT int attr_set (const char *__path, const char *__attrname,
const char *__attrvalue, const int __valuelength,
int __flags)
__attribute__ ((deprecated ("Use setxattr or lsetxattr instead")));
-extern int attr_setf (int __fd, const char *__attrname,
+EXPORT int attr_setf (int __fd, const char *__attrname,
const char *__attrvalue, const int __valuelength,
int __flags)
__attribute__ ((deprecated ("Use fsetxattr instead")));
@@ -149,10 +149,10 @@ extern int attr_setf (int __fd, const char *__attrname,
* Remove an attribute.
* The return value is -1 on error (w/errno set appropriately), 0 on success.
*/
-extern int attr_remove (const char *__path, const char *__attrname,
+EXPORT int attr_remove (const char *__path, const char *__attrname,
int __flags)
__attribute__ ((deprecated ("Use removexattr or lremovexattr instead")));
-extern int attr_removef (int __fd, const char *__attrname, int __flags)
+EXPORT int attr_removef (int __fd, const char *__attrname, int __flags)
__attribute__ ((deprecated ("Use fremovexattr instead")));
/*
@@ -162,10 +162,10 @@ extern int attr_removef (int __fd, const char *__attrname, int __flags)
* fit into the buffer on the first system call.
* The return value is -1 on error (w/errno set appropriately), 0 on success.
*/
-int attr_list(const char *__path, char *__buffer, const int __buffersize,
+EXPORT int attr_list(const char *__path, char *__buffer, const int __buffersize,
int __flags, attrlist_cursor_t *__cursor)
__attribute__ ((deprecated ("Use listxattr or llistxattr instead")));
-int attr_listf(int __fd, char *__buffer, const int __buffersize,
+EXPORT int attr_listf(int __fd, char *__buffer, const int __buffersize,
int __flags, attrlist_cursor_t *__cursor)
__attribute__ ((deprecated ("Use flistxattr instead")));
@@ -186,10 +186,10 @@ int attr_listf(int __fd, char *__buffer, const int __buffersize,
* the corresponding "simple" attribute interface. For example: the args
* to a ATTR_OP_GET are the same as the args to an attr_get() call.
*/
-extern int attr_multi (const char *__path, attr_multiop_t *__oplist,
+EXPORT int attr_multi (const char *__path, attr_multiop_t *__oplist,
int __count, int __flags)
__attribute__ ((deprecated ("Use getxattr, setxattr, listxattr, removexattr instead")));
-extern int attr_multif (int __fd, attr_multiop_t *__oplist,
+EXPORT int attr_multif (int __fd, attr_multiop_t *__oplist,
int __count, int __flags)
__attribute__ ((deprecated ("Use getxattr, setxattr, listxattr, removexattr instead")));
diff --git a/include/libattr.h b/include/libattr.h
index 81ebc1b..472dca4 100644
--- a/include/libattr.h
+++ b/include/libattr.h
@@ -24,20 +24,20 @@ extern "C" {
struct error_context;
-extern int attr_copy_file (const char *, const char *,
+EXPORT int attr_copy_file (const char *, const char *,
int (*) (const char *, struct error_context *),
struct error_context *);
-extern int attr_copy_fd (const char *, int, const char *, int,
+EXPORT int attr_copy_fd (const char *, int, const char *, int,
int (*) (const char *, struct error_context *),
struct error_context *);
/* Keep this function for backwards compatibility. */
-extern int attr_copy_check_permissions(const char *, struct error_context *);
+EXPORT int attr_copy_check_permissions(const char *, struct error_context *);
#define ATTR_ACTION_SKIP 1
#define ATTR_ACTION_PERMISSIONS 2
-extern int attr_copy_action(const char *, struct error_context *);
+EXPORT int attr_copy_action(const char *, struct error_context *);
#ifdef __cplusplus
}
diff --git a/libattr/syscalls.c b/libattr/syscalls.c
index 352841b..3013aa0 100644
--- a/libattr/syscalls.c
+++ b/libattr/syscalls.c
@@ -24,6 +24,10 @@
#include
+#ifdef HAVE_VISIBILITY_ATTRIBUTE
+# pragma GCC visibility push(default)
+#endif
+
int libattr_setxattr(const char *path, const char *name,
void *value, size_t size, int flags)
{
@@ -89,3 +93,7 @@ int libattr_fremovexattr(int filedes, const char *name)
{
return fremovexattr(filedes, name);
}
+
+#ifdef HAVE_VISIBILITY_ATTRIBUTE
+# pragma GCC visibility pop
+#endif
diff --git a/m4/visibility_hidden.m4 b/m4/visibility_hidden.m4
new file mode 100644
index 0000000..dbd57d4
--- /dev/null
+++ b/m4/visibility_hidden.m4
@@ -0,0 +1,40 @@
+dnl Copyright (C) 2003, 2008 Silicon Graphics, Inc.
+dnl
+dnl This program is free software: you can redistribute it and/or modify it
+dnl under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation, either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program. If not, see .
+AC_DEFUN([AC_FUNC_GCC_VISIBILITY],
+ [AC_CACHE_CHECK(whether __attribute__((visibility())) is supported,
+ libc_cv_visibility_attribute,
+ [cat > conftest.c </dev/null 2>&1; then
+ if grep '\.hidden.*foo' conftest.s >/dev/null; then
+ if grep '\.protected.*bar' conftest.s >/dev/null; then
+ libc_cv_visibility_attribute=yes
+ fi
+ fi
+ fi
+ rm -f conftest.[cs]
+ ])
+ if test $libc_cv_visibility_attribute = yes; then
+ AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE, [], [GCC supports visibility attributes])
+ AC_DEFINE(EXPORT, [__attribute__ ((visibility ("default"))) extern], [Visibility attribute for API symbols])
+ CFLAGS="${CFLAGS} -fvisibility=hidden"
+ else
+ AC_DEFINE(EXPORT, [extern], [Visibility attribute for API symbols])
+ fi
+ ])
--
2.7.2