From 7f04d825cea33617f85ba367f8873ac1f63bbcdc Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 17 Jul 2012 23:41:06 -0500 Subject: [PATCH] Add some missing epicsShareClass decorations. Also set the gcc-4 visibility attribute in shareLib.h --- src/ca/legacy/pcas/generic/casdef.h | 16 ++++++------- src/libCom/fdmgr/fdManager.h | 2 +- src/libCom/misc/shareLib.h | 35 +++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/ca/legacy/pcas/generic/casdef.h b/src/ca/legacy/pcas/generic/casdef.h index 5d1e60981..001f7bb11 100644 --- a/src/ca/legacy/pcas/generic/casdef.h +++ b/src/ca/legacy/pcas/generic/casdef.h @@ -150,7 +150,7 @@ private: // // caServer - Channel Access Server API Class // -class caServer { +class epicsShareClass caServer { friend class casPVI; public: epicsShareFunc caServer (); @@ -312,7 +312,7 @@ private: // then it may decide to provide a "destroy()" implementation in the // derived class which is a noop. // -class casPV { +class epicsShareClass casPV { public: epicsShareFunc casPV (); @@ -566,7 +566,7 @@ public: // occurring when both the server library and the server tool attempt // to destroy the same casChannel derived object at the same instant. // -class casChannel { +class epicsShareClass casChannel { public: epicsShareFunc casChannel ( const casCtx & ctx ); epicsShareFunc virtual ~casChannel (); @@ -724,7 +724,7 @@ private: // in the destructor, for the class deriving from // casAsyncReadIO. // ** -class casAsyncReadIO { +class epicsShareClass casAsyncReadIO { public: // @@ -784,7 +784,7 @@ private: // casAsyncWriteIO. // ** // -class casAsyncWriteIO { +class epicsShareClass casAsyncWriteIO { public: // // casAsyncWriteIO() @@ -830,7 +830,7 @@ private: // casAsyncPVExistIO // - for use with caServer::pvExistTest() // -class casAsyncPVExistIO { +class epicsShareClass casAsyncPVExistIO { public: // @@ -879,7 +879,7 @@ private: // casAsyncPVAttachIO // - for use with caServer::pvAttach() // -class casAsyncPVAttachIO { +class epicsShareClass casAsyncPVAttachIO { public: // // casAsyncPVAttachIO() @@ -926,7 +926,7 @@ private: // casAsyncPVCreateIO (deprecated) // (this class will be deleted in a future release) // -class casAsyncPVCreateIO : private casAsyncPVAttachIO { +class epicsShareClass casAsyncPVCreateIO : private casAsyncPVAttachIO { public: epicsShareFunc casAsyncPVCreateIO ( const casCtx & ctx ); epicsShareFunc virtual ~casAsyncPVCreateIO (); diff --git a/src/libCom/fdmgr/fdManager.h b/src/libCom/fdmgr/fdManager.h index 23ca84587..6bcd2e557 100644 --- a/src/libCom/fdmgr/fdManager.h +++ b/src/libCom/fdmgr/fdManager.h @@ -122,7 +122,7 @@ epicsShareExtern fdManager fileDescriptorManager; // // file descriptor registration // -class fdReg : public fdRegId, public tsDLNode, public tsSLNode { +class epicsShareClass fdReg : public fdRegId, public tsDLNode, public tsSLNode { friend class fdManager; public: diff --git a/src/libCom/misc/shareLib.h b/src/libCom/misc/shareLib.h index ba23b282f..789ce6b08 100644 --- a/src/libCom/misc/shareLib.h +++ b/src/libCom/misc/shareLib.h @@ -29,12 +29,9 @@ * int epicsShareAPI myExtFunc ( int arg ); * int epicsShareAPI myExtFunc ( int arg ) {} * - * ** NOTE ** epicsShareAPI is deprecated for new routines, don't use it! - * In a future major release (R3.15) we will remove this keyword - * from most EPICS APIs, although CA may continue to use it. - * This is a major release though, since it affects the order - * that arguments are pushed onto the stack on Windows and we - * don't want a replacement DLL to silent cause mayhem... + * ** NOTE ** epicsShareAPI is deprecated for new routines and has been removed + * from all IOC-specific APIs, although most libCom APIs are still + * declared to use it. * * 2) epicsShare{Func,Class,Extern,Def} - specifies shareable library (DLL) * export/import related information in the source code. On windows these keywords @@ -44,7 +41,11 @@ * names. These keywords are only necessary if the address of a function or data * internal to a shareable library (DLL) needs to be visible outside of this shareable * library (DLL). All compilers targeting windows accept the __declspec(dllexport) - * and __declspec(dllimport) keywords. + * and __declspec(dllimport) keywords. For GCC version 4 and above the first three + * keywords specify a visibility attribute of "default", which marks the symbol as + * exported even when gcc is given the option -fvisibility=hidden. Doing this can + * significantly reduce the number of symbols exported to a shared library. See the + * URL below for more information. * * In header files declare references to externally visible variables, classes and * functions like this: @@ -139,6 +140,26 @@ # define epicsShareDef # define epicsShareAPI __stdcall /* function removes arguments */ # define READONLY const + +#elif __GNUC__ >= 4 +/* + * See http://gcc.gnu.org/wiki/Visibility + * For these to have any effect, the compiler and linker must be given the flag + * -fvisibility=hidden + */ + +# define epicsShareExtern __attribute__ ((visibility("default"))) extern +# define epicsShareClass __attribute__ ((visibility("default"))) +# define epicsShareFunc __attribute__ ((visibility("default"))) + +# define epicsShareDef +# define epicsShareAPI +# if defined(__STDC__) || defined (__cplusplus) +# define READONLY const +# else +# define READONLY +# endif + /* * if its the old VAX C Compiler (not DEC C) */