Hi all,

This patch adds visibility annotations to public functions in libICE and
also enables -fvisibility=hidden on platforms where it's available.

This results in 10% size decrease (101K -> 92K) and 50% export symbols
reduction (141 -> 67) on x86_64.

Is this ok for trunk?

Best regards,
Yury Gribov



>From af175352ddf6139a66092616ec66229553fee32d Mon Sep 17 00:00:00 2001
From: Yury Gribov <[email protected]>
Date: Tue, 12 Apr 2016 17:04:09 +0300
Subject: [PATCH] Added visibility annotations.

Signed-off-by: Yury Gribov <[email protected]>
---
 configure.ac              | 16 +++++++++
 include/X11/ICE/ICElib.h  | 82 +++++++++++++++++++++++------------------------
 include/X11/ICE/ICEmsg.h  | 18 +++++------
 include/X11/ICE/ICEutil.h | 18 +++++------
 src/Makefile.am           |  1 +
 5 files changed, 76 insertions(+), 59 deletions(-)

diff --git a/configure.ac b/configure.ac
index 458882a..6c51f62 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,6 +40,22 @@ AC_DEFINE(ICE_t, 1, [Xtrans transport type])
 AC_CHECK_LIB([bsd], [arc4random_buf])
 AC_CHECK_FUNCS([asprintf arc4random_buf])
 
+save_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -fvisibility=hidden"
+CFLAGS_VISIBILITY=
+AC_COMPILE_IFELSE(
+  [AC_LANG_SOURCE([[
+    #if defined(__CYGWIN__) || defined(__MINGW32__)
+    #error No visibility support
+    #endif
+    extern __attribute__((__visibility__("default"))) int x;
+  ]])],
+  [CFLAGS_VISIBILITY=-fvisibility=hidden],
+  []
+)
+CFLAGS="$save_CFLAGS"
+AC_SUBST([CFLAGS_VISIBILITY])
+
 # Allow checking code with lint, sparse, etc.
 XORG_WITH_LINT
 XORG_LINT_LIBRARY([ICE])
diff --git a/include/X11/ICE/ICElib.h b/include/X11/ICE/ICElib.h
index 402cbc8..a1d2256 100644
--- a/include/X11/ICE/ICElib.h
+++ b/include/X11/ICE/ICElib.h
@@ -205,7 +205,7 @@ typedef void (*IceIOErrorHandler) (
 
 _XFUNCPROTOBEGIN
 
-extern int IceRegisterForProtocolSetup (
+_X_EXPORT int IceRegisterForProtocolSetup (
     const char *		/* protocolName */,
     const char *		/* vendor */,
     const char *		/* release */,
@@ -217,7 +217,7 @@ extern int IceRegisterForProtocolSetup (
     IceIOErrorProc		/* IOErrorProc */
 );
 
-extern int IceRegisterForProtocolReply (
+_X_EXPORT int IceRegisterForProtocolReply (
     const char *		/* protocolName */,
     const char *		/* vendor */,
     const char *		/* release */,
@@ -232,7 +232,7 @@ extern int IceRegisterForProtocolReply (
     IceIOErrorProc		/* IOErrorProc */
 );
 
-extern IceConn IceOpenConnection (
+_X_EXPORT IceConn IceOpenConnection (
     char *		/* networkIdsList */,
     IcePointer		/* context */,
     Bool		/* mustAuthenticate */,
@@ -241,18 +241,18 @@ extern IceConn IceOpenConnection (
     char *		/* errorStringRet */
 );
 
-extern IcePointer IceGetConnectionContext (
+_X_EXPORT IcePointer IceGetConnectionContext (
     IceConn		/* iceConn */
 );
 
-extern Status IceListenForConnections (
+_X_EXPORT Status IceListenForConnections (
     int *		/* countRet */,
     IceListenObj **	/* listenObjsRet */,
     int			/* errorLength */,
     char *		/* errorStringRet */
 );
 
-extern Status IceListenForWellKnownConnections (
+_X_EXPORT Status IceListenForWellKnownConnections (
     char *		/* port */,
     int *		/* countRet */,
     IceListenObj **	/* listenObjsRet */,
@@ -260,58 +260,58 @@ extern Status IceListenForWellKnownConnections (
     char *		/* errorStringRet */
 );
 
-extern int IceGetListenConnectionNumber (
+_X_EXPORT int IceGetListenConnectionNumber (
     IceListenObj	/* listenObj */
 );
 
-extern char *IceGetListenConnectionString (
+_X_EXPORT char *IceGetListenConnectionString (
     IceListenObj	/* listenObj */
 );
 
-extern char *IceComposeNetworkIdList (
+_X_EXPORT char *IceComposeNetworkIdList (
     int			/* count */,
     IceListenObj *	/* listenObjs */
 );
 
-extern void IceFreeListenObjs (
+_X_EXPORT void IceFreeListenObjs (
     int			/* count */,
     IceListenObj *	/* listenObjs */
 );
 
-extern void IceSetHostBasedAuthProc (
+_X_EXPORT void IceSetHostBasedAuthProc (
     IceListenObj		/* listenObj */,
     IceHostBasedAuthProc   	/* hostBasedAuthProc */
 );
 
-extern IceConn IceAcceptConnection (
+_X_EXPORT IceConn IceAcceptConnection (
     IceListenObj	/* listenObj */,
     IceAcceptStatus *	/* statusRet */
 );
 
-extern void IceSetShutdownNegotiation (
+_X_EXPORT void IceSetShutdownNegotiation (
     IceConn		/* iceConn */,
     Bool		/* negotiate */
 );
 
-extern Bool IceCheckShutdownNegotiation (
+_X_EXPORT Bool IceCheckShutdownNegotiation (
     IceConn		/* iceConn */
 );
 
-extern IceCloseStatus IceCloseConnection (
+_X_EXPORT IceCloseStatus IceCloseConnection (
     IceConn		/* iceConn */
 );
 
-extern Status IceAddConnectionWatch (
+_X_EXPORT Status IceAddConnectionWatch (
     IceWatchProc		/* watchProc */,
     IcePointer			/* clientData */
 );
 
-extern void IceRemoveConnectionWatch (
+_X_EXPORT void IceRemoveConnectionWatch (
     IceWatchProc		/* watchProc */,
     IcePointer			/* clientData */
 );
 
-extern IceProtocolSetupStatus IceProtocolSetup (
+_X_EXPORT IceProtocolSetupStatus IceProtocolSetup (
     IceConn		/* iceConn */,
     int 		/* myOpcode */,
     IcePointer		/* clientData */,
@@ -324,89 +324,89 @@ extern IceProtocolSetupStatus IceProtocolSetup (
     char *		/* errorStringRet */
 );
 
-extern Status IceProtocolShutdown (
+_X_EXPORT Status IceProtocolShutdown (
     IceConn		/* iceConn */,
     int			/* majorOpcode */
 );
 
-extern IceProcessMessagesStatus IceProcessMessages (
+_X_EXPORT IceProcessMessagesStatus IceProcessMessages (
     IceConn		/* iceConn */,
     IceReplyWaitInfo *	/* replyWait */,
     Bool *		/* replyReadyRet */
 );
 
-extern Status IcePing (
+_X_EXPORT Status IcePing (
    IceConn		/* iceConn */,
    IcePingReplyProc	/* pingReplyProc */,
    IcePointer		/* clientData */
 );
 
-extern char *IceAllocScratch (
+_X_EXPORT char *IceAllocScratch (
    IceConn		/* iceConn */,
    unsigned long	/* size */
 );
 
-extern int IceFlush (
+_X_EXPORT int IceFlush (
    IceConn		/* iceConn */
 );
 
-extern int IceGetOutBufSize (
+_X_EXPORT int IceGetOutBufSize (
    IceConn		/* iceConn */
 );
 
-extern int IceGetInBufSize (
+_X_EXPORT int IceGetInBufSize (
    IceConn		/* iceConn */
 );
 
-extern IceConnectStatus IceConnectionStatus (
+_X_EXPORT IceConnectStatus IceConnectionStatus (
     IceConn		/* iceConn */
 );
 
-extern char *IceVendor (
+_X_EXPORT char *IceVendor (
     IceConn		/* iceConn */
 );
 
-extern char *IceRelease (
+_X_EXPORT char *IceRelease (
     IceConn		/* iceConn */
 );
 
-extern int IceProtocolVersion (
+_X_EXPORT int IceProtocolVersion (
     IceConn		/* iceConn */
 );
 
-extern int IceProtocolRevision (
+_X_EXPORT int IceProtocolRevision (
     IceConn		/* iceConn */
 );
 
-extern int IceConnectionNumber (
+_X_EXPORT int IceConnectionNumber (
     IceConn		/* iceConn */
 );
 
-extern char *IceConnectionString (
+_X_EXPORT char *IceConnectionString (
     IceConn		/* iceConn */
 );
 
-extern unsigned long IceLastSentSequenceNumber (
+_X_EXPORT unsigned long IceLastSentSequenceNumber (
     IceConn		/* iceConn */
 );
 
-extern unsigned long IceLastReceivedSequenceNumber (
+_X_EXPORT unsigned long IceLastReceivedSequenceNumber (
     IceConn		/* iceConn */
 );
 
-extern Bool IceSwapping (
+_X_EXPORT Bool IceSwapping (
     IceConn		/* iceConn */
 );
 
-extern IceErrorHandler IceSetErrorHandler (
+_X_EXPORT IceErrorHandler IceSetErrorHandler (
     IceErrorHandler 	/* handler */
 );
 
-extern IceIOErrorHandler IceSetIOErrorHandler (
+_X_EXPORT IceIOErrorHandler IceSetIOErrorHandler (
     IceIOErrorHandler 	/* handler */
 );
 
-extern char *IceGetPeerName (
+_X_EXPORT char *IceGetPeerName (
     IceConn		/* iceConn */
 );
 
@@ -414,15 +414,15 @@ extern char *IceGetPeerName (
  * Multithread Routines
  */
 
-extern Status IceInitThreads (
+_X_EXPORT Status IceInitThreads (
     void
 );
 
-extern void IceAppLockConn (
+_X_EXPORT void IceAppLockConn (
     IceConn		/* iceConn */
 );
 
-extern void IceAppUnlockConn (
+_X_EXPORT void IceAppUnlockConn (
     IceConn		/* iceConn */
 );
 
diff --git a/include/X11/ICE/ICEmsg.h b/include/X11/ICE/ICEmsg.h
index f6e7121..d2636aa 100644
--- a/include/X11/ICE/ICEmsg.h
+++ b/include/X11/ICE/ICEmsg.h
@@ -39,46 +39,46 @@ _XFUNCPROTOBEGIN
  * Function prototypes for internal ICElib functions
  */
 
-extern Status _IceRead (
+_X_EXPORT Status _IceRead (
     IceConn		/* iceConn */,
     unsigned long	/* nbytes */,
     char *		/* ptr */
 );
 
-extern void _IceReadSkip (
+_X_EXPORT void _IceReadSkip (
     IceConn		/* iceConn */,
     unsigned long	/* nbytes */
 );
 
-extern void _IceWrite (
+_X_EXPORT void _IceWrite (
     IceConn		/* iceConn */,
     unsigned long	/* nbytes */,
     char *		/* ptr */
 );
 
 
-extern void _IceErrorBadMinor (
+_X_EXPORT void _IceErrorBadMinor (
     IceConn		/* iceConn */,
     int			/* majorOpcode */,
     int			/* offendingMinor */,
     int			/* severity */
 );
 
-extern void _IceErrorBadState (
+_X_EXPORT void _IceErrorBadState (
     IceConn		/* iceConn */,
     int			/* majorOpcode */,
     int			/* offendingMinor */,
     int			/* severity */
 );
 
-extern void _IceErrorBadLength (
+_X_EXPORT void _IceErrorBadLength (
     IceConn		/* iceConn */,
     int			/* majorOpcode */,
     int			/* offendingMinor */,
     int			/* severity */
 );
 
-extern void _IceErrorBadValue (
+_X_EXPORT void _IceErrorBadValue (
     IceConn		/* iceConn */,
     int			/* majorOpcode */,
     int			/* offendingMinor */,
@@ -87,7 +87,7 @@ extern void _IceErrorBadValue (
     IcePointer		/* value */
 );
 
-extern IcePoAuthStatus _IcePoMagicCookie1Proc (
+_X_EXPORT IcePoAuthStatus _IcePoMagicCookie1Proc (
     IceConn		/* iceConn */,
     IcePointer *	/* authStatePtr */,
     Bool 		/* cleanUp */,
@@ -99,7 +99,7 @@ extern IcePoAuthStatus _IcePoMagicCookie1Proc (
     char **		/* errorStringRet */
 );
 
-extern IcePaAuthStatus _IcePaMagicCookie1Proc (
+_X_EXPORT IcePaAuthStatus _IcePaMagicCookie1Proc (
     IceConn		/* iceConn */,
     IcePointer *	/* authStatePtr */,
     Bool		/* swap */,
diff --git a/include/X11/ICE/ICEutil.h b/include/X11/ICE/ICEutil.h
index dbf1490..592993e 100644
--- a/include/X11/ICE/ICEutil.h
+++ b/include/X11/ICE/ICEutil.h
@@ -76,45 +76,45 @@ typedef struct {
  * Function Prototypes
  */
 
-extern char *IceAuthFileName (
+_X_EXPORT char *IceAuthFileName (
     void
 );
 
-extern int IceLockAuthFile (
+_X_EXPORT int IceLockAuthFile (
     const char *	/* file_name */,
     int			/* retries */,
     int			/* timeout */,
     long		/* dead */
 );
 
-extern void IceUnlockAuthFile (
+_X_EXPORT void IceUnlockAuthFile (
     const char *	/* file_name */
 );
 
-extern IceAuthFileEntry *IceReadAuthFileEntry (
+_X_EXPORT IceAuthFileEntry *IceReadAuthFileEntry (
     FILE *		/* auth_file */
 );
 
-extern void IceFreeAuthFileEntry (
+_X_EXPORT void IceFreeAuthFileEntry (
     IceAuthFileEntry *	/* auth */
 );
 
-extern Status IceWriteAuthFileEntry (
+_X_EXPORT Status IceWriteAuthFileEntry (
     FILE *		/* auth_file */,
     IceAuthFileEntry *	/* auth */
 );
 
-extern IceAuthFileEntry *IceGetAuthFileEntry (
+_X_EXPORT IceAuthFileEntry *IceGetAuthFileEntry (
     const char *	/* protocol_name */,
     const char *	/* network_id */,
     const char *	/* auth_name */
 );
 
-extern char *IceGenerateMagicCookie (
+_X_EXPORT char *IceGenerateMagicCookie (
     int			/* len */
 );
 
-extern void IceSetPaAuthData (
+_X_EXPORT void IceSetPaAuthData (
     int			/* numEntries */,
     IceAuthDataEntry *	/* entries */
 );
diff --git a/src/Makefile.am b/src/Makefile.am
index 3cbe9c6..c359bcb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,7 @@ AM_CPPFLAGS = -I${top_srcdir}/include
 AM_CFLAGS = \
 	$(ICE_CFLAGS) \
 	$(CWARNFLAGS) \
+	$(CFLAGS_VISIBILITY) \
 	-DICE_t -DTRANS_CLIENT -DTRANS_SERVER
 
 libICE_la_LDFLAGS = -version-number 6:3:0 -no-undefined
-- 
1.9.1


_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to