Skip to content

Commit

Permalink
This commit makes the default symbol visibility hidden for unixen builds
Browse files Browse the repository at this point in the history
This only applies when building shared libraries, but switches to a
symbol management strategy which is more in line with Windows, where
symbols must be explicitly exported (marked as default visibilty). This
allows us to be much more explicit and careful about what symbols are
being exposed, making our .so files tidier

Signed-off-by: Kimball Thurston <[email protected]>
  • Loading branch information
kdt3rd committed Nov 22, 2020
1 parent 467be80 commit 60e8e0e
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 149 deletions.
2 changes: 2 additions & 0 deletions cmake/LibraryDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ function(OPENEXR_DEFINE_LIBRARY libname)
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
)
if (_ilmbase_extra_flags)
target_compile_options(${objlib} PUBLIC ${_ilmbase_extra_flags})
Expand Down
80 changes: 40 additions & 40 deletions src/lib/Iex/IexBaseExc.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,59 +57,59 @@ IEX_INTERNAL_NAMESPACE_HEADER_ENTER
// Our most basic exception class
//-------------------------------

class BaseExc: public std::exception
class IEX_EXPORT BaseExc: public std::exception
{
public:

//----------------------------
// Constructors and destructor
//----------------------------

IEX_EXPORT BaseExc (const char *s = nullptr) throw(); // std::string (s)
IEX_EXPORT BaseExc (const std::string &s) throw(); // std::string (s)
IEX_EXPORT BaseExc (std::stringstream &s) throw(); // std::string (s.str())
BaseExc (const char *s = nullptr) throw(); // std::string (s)
BaseExc (const std::string &s) throw(); // std::string (s)
BaseExc (std::stringstream &s) throw(); // std::string (s.str())

IEX_EXPORT BaseExc (const BaseExc &be) throw();
IEX_EXPORT BaseExc (BaseExc &&be) throw();
IEX_EXPORT virtual ~BaseExc () throw ();
BaseExc (const BaseExc &be) throw();
BaseExc (BaseExc &&be) throw();
virtual ~BaseExc () throw ();

IEX_EXPORT BaseExc & operator = (const BaseExc& be) throw ();
IEX_EXPORT BaseExc & operator = (BaseExc&& be) throw ();
BaseExc & operator = (const BaseExc& be) throw ();
BaseExc & operator = (BaseExc&& be) throw ();

//---------------------------------------------------
// what() method -- e.what() returns _message.c_str()
//---------------------------------------------------

IEX_EXPORT virtual const char * what () const throw ();
virtual const char * what () const throw ();


//--------------------------------------------------
// Convenient methods to change the exception's text
//--------------------------------------------------

IEX_EXPORT BaseExc & assign (std::stringstream &s); // assign (s.str())
IEX_EXPORT BaseExc & operator = (std::stringstream &s);
BaseExc & assign (std::stringstream &s); // assign (s.str())
BaseExc & operator = (std::stringstream &s);

IEX_EXPORT BaseExc & append (std::stringstream &s); // append (s.str())
IEX_EXPORT BaseExc & operator += (std::stringstream &s);
BaseExc & append (std::stringstream &s); // append (s.str())
BaseExc & operator += (std::stringstream &s);


//--------------------------------------------------
// These methods from the base class get obscured by
// the definitions above.
//--------------------------------------------------

IEX_EXPORT BaseExc & assign (const char *s);
IEX_EXPORT BaseExc & operator = (const char *s);
BaseExc & assign (const char *s);
BaseExc & operator = (const char *s);

IEX_EXPORT BaseExc & append (const char *s);
IEX_EXPORT BaseExc & operator += (const char *s);
BaseExc & append (const char *s);
BaseExc & operator += (const char *s);

//---------------------------------------------------
// Access to the string representation of the message
//---------------------------------------------------

IEX_EXPORT const std::string & message () const;
const std::string & message () const;

//--------------------------------------------------
// Stack trace for the point at which the exception
Expand All @@ -118,7 +118,7 @@ class BaseExc: public std::exception
// has been installed (see below, setStackTracer()).
//--------------------------------------------------

IEX_EXPORT const std::string & stackTrace () const;
const std::string & stackTrace () const;

private:

Expand All @@ -133,30 +133,30 @@ class BaseExc: public std::exception
//-----------------------------------------------------

#define DEFINE_EXC_EXP(exp, name, base) \
class name: public base \
class exp name: public base \
{ \
public: \
exp name() throw(); \
exp name (const char* text) throw(); \
exp name (const std::string &text) throw(); \
exp name (std::stringstream &text) throw(); \
exp name (const name &other) throw(); \
exp name (name &&other) throw(); \
exp name& operator = (name &other) throw(); \
exp name& operator = (name &&other) throw(); \
exp ~name() throw(); \
name() throw(); \
name (const char* text) throw(); \
name (const std::string &text) throw(); \
name (std::stringstream &text) throw(); \
name (const name &other) throw(); \
name (name &&other) throw(); \
name& operator = (name &other) throw(); \
name& operator = (name &&other) throw(); \
~name() throw(); \
};

#define DEFINE_EXC_EXP_IMPL(exp, name, base) \
exp name::name () throw () : base () {} \
exp name::name (const char* text) throw () : base (text) {} \
exp name::name (const std::string& text) throw () : base (text) {} \
exp name::name (std::stringstream& text) throw () : base (text) {} \
exp name::name (const name &other) throw() : base (other) {} \
exp name::name (name &&other) throw() : base (other) {} \
exp name& name::operator = (name &other) throw() { base::operator=(other); return *this; } \
exp name& name::operator = (name &&other) throw() { base::operator=(other); return *this; } \
exp name::~name () throw () {}
#define DEFINE_EXC_EXP_IMPL(exp, name, base) \
name::name () throw () : base () {} \
name::name (const char* text) throw () : base (text) {} \
name::name (const std::string& text) throw () : base (text) {} \
name::name (std::stringstream& text) throw () : base (text) {} \
name::name (const name &other) throw() : base (other) {} \
name::name (name &&other) throw() : base (other) {} \
name& name::operator = (name &other) throw() { base::operator=(other); return *this; } \
name& name::operator = (name &&other) throw() { base::operator=(other); return *this; } \
name::~name () throw () {}

// For backward compatibility.
#define DEFINE_EXC(name, base) DEFINE_EXC_EXP(, name, base)
Expand Down
14 changes: 6 additions & 8 deletions src/lib/Iex/IexExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@
///////////////////////////////////////////////////////////////////////////

#if defined(OPENEXR_DLL)
#if defined(IEX_EXPORTS)
#define IEX_EXPORT __declspec(dllexport)
#else
#define IEX_EXPORT __declspec(dllimport)
#endif
#define IEX_EXPORT_CONST
# if defined(IEX_EXPORTS)
# define IEX_EXPORT __declspec(dllexport)
# else
# define IEX_EXPORT __declspec(dllimport)
# endif
#else
#define IEX_EXPORT
#define IEX_EXPORT_CONST const
# define IEX_EXPORT __attribute__ ((visibility ("default")))
#endif

#endif // #ifndef IEXEXPORT_H
Expand Down
2 changes: 1 addition & 1 deletion src/lib/IlmThread/IlmThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER
ILMTHREAD_EXPORT bool supportsThreads ();


class Thread
class ILMTHREAD_EXPORT Thread
{
public:

Expand Down
18 changes: 9 additions & 9 deletions src/lib/IlmThread/IlmThreadExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
///////////////////////////////////////////////////////////////////////////

#if defined(OPENEXR_DLL)
#if defined(ILMTHREAD_EXPORTS)
#define ILMTHREAD_EXPORT __declspec(dllexport)
#define ILMTHREAD_EXPORT_CONST extern __declspec(dllexport)
#else
#define ILMTHREAD_EXPORT __declspec(dllimport)
#define ILMTHREAD_EXPORT_CONST extern __declspec(dllimport)
#endif
# if defined(ILMTHREAD_EXPORTS)
# define ILMTHREAD_EXPORT __declspec(dllexport)
# define ILMTHREAD_EXPORT_CONST extern __declspec(dllexport)
# else
# define ILMTHREAD_EXPORT __declspec(dllimport)
# define ILMTHREAD_EXPORT_CONST extern __declspec(dllimport)
# endif
#else
#define ILMTHREAD_EXPORT
#define ILMTHREAD_EXPORT_CONST extern const
# define ILMTHREAD_EXPORT __attribute__ ((visibility ("default")))
# define ILMTHREAD_EXPORT_CONST extern const __attribute__ ((visibility ("default")))
#endif
2 changes: 1 addition & 1 deletion src/lib/OpenEXR/ImfAttribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER


class Attribute
class IMF_EXPORT Attribute
{
public:

Expand Down
18 changes: 9 additions & 9 deletions src/lib/OpenEXR/ImfExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
///////////////////////////////////////////////////////////////////////////

#if defined(OPENEXR_DLL)
#if defined(OPENEXR_EXPORTS)
#define IMF_EXPORT __declspec(dllexport)
#define IMF_EXPORT_CONST extern __declspec(dllexport)
#else
#define IMF_EXPORT __declspec(dllimport)
#define IMF_EXPORT_CONST extern __declspec(dllimport)
#endif
# if defined(OPENEXR_EXPORTS)
# define IMF_EXPORT __declspec(dllexport)
# define IMF_EXPORT_CONST extern __declspec(dllexport)
# else
# define IMF_EXPORT __declspec(dllimport)
# define IMF_EXPORT_CONST extern __declspec(dllimport)
# endif
#else
#define IMF_EXPORT
#define IMF_EXPORT_CONST extern const
# define IMF_EXPORT __attribute__ ((visibility ("default")))
# define IMF_EXPORT_CONST extern const __attribute__ ((visibility ("default")))
#endif
12 changes: 6 additions & 6 deletions src/lib/OpenEXR/ImfIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
// class IStream -- an abstract base class for input streams.
//-----------------------------------------------------------

class IStream
class IMF_EXPORT IStream
{
public:

Expand Down Expand Up @@ -160,7 +160,7 @@ class IStream
// class OStream -- an abstract base class for output streams
//-----------------------------------------------------------

class OStream
class IMF_EXPORT OStream
{
public:

Expand Down Expand Up @@ -230,13 +230,13 @@ class OStream

struct StreamIO
{
static void
static inline void
writeChars (OStream &os, const char c[/*n*/], int n)
{
os.write (c, n);
}

static bool
static inline bool
readChars (IStream &is, char c[/*n*/], int n)
{
return is.read (c, n);
Expand All @@ -246,14 +246,14 @@ struct StreamIO

struct CharPtrIO
{
static void
static inline void
writeChars (char *&op, const char c[/*n*/], int n)
{
while (n--)
*op++ = *c++;
}

static bool
static inline bool
readChars (const char *&ip, char c[/*n*/], int n)
{
while (n--)
Expand Down
10 changes: 1 addition & 9 deletions src/lib/OpenEXR/ImfOpaqueAttribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,52 +56,44 @@
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER


class OpaqueAttribute: public Attribute
class IMF_EXPORT OpaqueAttribute: public Attribute
{
public:

//----------------------------
// Constructors and destructor
//----------------------------

IMF_EXPORT
OpaqueAttribute (const char typeName[]);
IMF_EXPORT
OpaqueAttribute (const OpaqueAttribute &other);
IMF_EXPORT
virtual ~OpaqueAttribute ();


//-------------------------------
// Get this attribute's type name
//-------------------------------

IMF_EXPORT
virtual const char * typeName () const;


//------------------------------
// Make a copy of this attribute
//------------------------------

IMF_EXPORT
virtual Attribute * copy () const;


//----------------
// I/O and copying
//----------------

IMF_EXPORT
virtual void writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os,
int version) const;

IMF_EXPORT
virtual void readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is,
int size,
int version);

IMF_EXPORT
virtual void copyValueFrom (const Attribute &other);


Expand Down
8 changes: 4 additions & 4 deletions src/lib/OpenEXR/ImfStdIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
// class OPENEXR_IMF_INTERNAL_NAMESPACE::IStream based on class std::ifstream
//-------------------------------------------

class StdIFStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::IStream
class IMF_EXPORT StdIFStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::IStream
{
public:

Expand Down Expand Up @@ -105,7 +105,7 @@ class StdIFStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::IStream
// OPENEXR_IMF_INTERNAL_NAMESPACE::IStream, based on class std::istringstream
//------------------------------------------------

class StdISStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::IStream
class IMF_EXPORT StdISStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::IStream
{
public:

Expand Down Expand Up @@ -139,7 +139,7 @@ class StdISStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::IStream
// class OPENEXR_IMF_INTERNAL_NAMESPACE::OStream based on class std::ofstream
//-------------------------------------------

class StdOFStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::OStream
class IMF_EXPORT StdOFStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::OStream
{
public:

Expand Down Expand Up @@ -184,7 +184,7 @@ class StdOFStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::OStream
// OPENEXR_IMF_INTERNAL_NAMESPACE::OStream, based on class std::ostringstream
//------------------------------------------------

class StdOSStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::OStream
class IMF_EXPORT StdOSStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::OStream
{
public:

Expand Down
Loading

0 comments on commit 60e8e0e

Please sign in to comment.