Use explicit symbol visibility control in GCC/clang

This commit is contained in:
rdb 2015-06-22 21:01:34 +02:00
parent 419eadb859
commit 236b0c590c
5 changed files with 18 additions and 14 deletions

View File

@ -431,6 +431,9 @@
#if defined(WIN32_VC) && !defined(CPPPARSER) && !defined(LINK_ALL_STATIC)
#define EXPORT_CLASS __declspec(dllexport)
#define IMPORT_CLASS __declspec(dllimport)
#elif __GNUC__ >= 4 && !defined(CPPPARSER) && !defined(LINK_ALL_STATIC)
#define EXPORT_CLASS __attribute__((visibility("default")))
#define IMPORT_CLASS
#else
#define EXPORT_CLASS
#define IMPORT_CLASS

View File

@ -97,7 +97,12 @@
/* These two are always defined empty, because pystub is statically
built. But we leave the symbol around in case we change our minds
to make pystub once again be a dynamic library. */
#if __GNUC__ >= 4
/* In GCC, though, we still need to mark the symbols as visible. */
#define EXPCL_PYSTUB __attribute__((visibility("default")))
#else
#define EXPCL_PYSTUB
#endif
#define EXPTP_PYSTUB
#endif

View File

@ -135,6 +135,8 @@ int write_python_table_native(ostream &out) {
<< "\n"
<< "#ifdef _WIN32\n"
<< "extern \"C\" __declspec(dllexport) PyObject *PyInit_" << library_name << "();\n"
<< "#elif __GNUC__ >= 4\n"
<< "extern \"C\" __attribute__((visibility(\"default\"))) PyObject *PyInit_" << library_name << "();\n"
<< "#else\n"
<< "extern \"C\" PyObject *PyInit_" << library_name << "();\n"
<< "#endif\n"
@ -180,6 +182,8 @@ int write_python_table_native(ostream &out) {
<< "\n"
<< "#ifdef _WIN32\n"
<< "extern \"C\" __declspec(dllexport) void init" << library_name << "();\n"
<< "#elif __GNUC__ >= 4\n"
<< "extern \"C\" __attribute__((visibility(\"default\"))) void init" << library_name << "();\n"
<< "#else\n"
<< "extern \"C\" void init" << library_name << "();\n"
<< "#endif\n"

View File

@ -125,8 +125,9 @@ INLINE ostream &operator << (ostream &out, NotifyCategoryProxy<GetCategory> &pro
// appear in the config_*.h file. The proxy object will be named
// basename_cat.
#if defined(WIN32_VC) && !defined(CPPPARSER)
#ifdef CPPPARSER
#define NotifyCategoryDecl(basename, expcl, exptp)
#else
#define NotifyCategoryDecl(basename, expcl, exptp) \
class expcl NotifyCategoryGetCategory_ ## basename { \
public: \
@ -135,18 +136,7 @@ INLINE ostream &operator << (ostream &out, NotifyCategoryProxy<GetCategory> &pro
}; \
exptp template class expcl NotifyCategoryProxy<NotifyCategoryGetCategory_ ## basename>; \
extern expcl NotifyCategoryProxy<NotifyCategoryGetCategory_ ## basename> basename ## _cat;
#else // WIN32_VC
#define NotifyCategoryDecl(basename, expcl, exptp) \
class NotifyCategoryGetCategory_ ## basename { \
public: \
NotifyCategoryGetCategory_ ## basename(); \
static NotifyCategory *get_category(); \
}; \
extern NotifyCategoryProxy<NotifyCategoryGetCategory_ ## basename> basename ## _cat;
#endif // WIN32_VC
#endif
// This macro is the same as the above, except that it declares a category
// that is not intended to be exported from any DLL.

View File

@ -1160,6 +1160,8 @@ def CompileCxx(obj,src,opts):
if (opt=="ALWAYS") or (opt in opts): cmd += ' -D' + var + '=' + val
for x in ipath: cmd += ' -I' + x
cmd += ' -fvisibility=hidden'
# Mac-specific flags.
if GetTarget() == "darwin":
cmd += " -Wno-deprecated-declarations"