From 236b0c590cc1781848c76e119309acc1f942f5ec Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 22 Jun 2015 21:01:34 +0200 Subject: [PATCH] Use explicit symbol visibility control in GCC/clang --- dtool/src/dtoolbase/dtoolbase.h | 3 +++ dtool/src/dtoolbase/dtoolsymbols.h | 5 +++++ dtool/src/interrogate/interrogate_module.cxx | 4 ++++ dtool/src/prc/notifyCategoryProxy.h | 18 ++++-------------- makepanda/makepanda.py | 2 ++ 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/dtool/src/dtoolbase/dtoolbase.h b/dtool/src/dtoolbase/dtoolbase.h index 50efeab52d..4398036e3a 100644 --- a/dtool/src/dtoolbase/dtoolbase.h +++ b/dtool/src/dtoolbase/dtoolbase.h @@ -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 diff --git a/dtool/src/dtoolbase/dtoolsymbols.h b/dtool/src/dtoolbase/dtoolsymbols.h index 56320840f5..02e976b936 100644 --- a/dtool/src/dtoolbase/dtoolsymbols.h +++ b/dtool/src/dtoolbase/dtoolsymbols.h @@ -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 diff --git a/dtool/src/interrogate/interrogate_module.cxx b/dtool/src/interrogate/interrogate_module.cxx index 02ac43ca50..8aad13c5c6 100644 --- a/dtool/src/interrogate/interrogate_module.cxx +++ b/dtool/src/interrogate/interrogate_module.cxx @@ -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" diff --git a/dtool/src/prc/notifyCategoryProxy.h b/dtool/src/prc/notifyCategoryProxy.h index 5a306497cd..4349b4a04b 100644 --- a/dtool/src/prc/notifyCategoryProxy.h +++ b/dtool/src/prc/notifyCategoryProxy.h @@ -125,8 +125,9 @@ INLINE ostream &operator << (ostream &out, NotifyCategoryProxy &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 &pro }; \ exptp template class expcl NotifyCategoryProxy; \ extern expcl NotifyCategoryProxy basename ## _cat; - -#else // WIN32_VC - -#define NotifyCategoryDecl(basename, expcl, exptp) \ - class NotifyCategoryGetCategory_ ## basename { \ - public: \ - NotifyCategoryGetCategory_ ## basename(); \ - static NotifyCategory *get_category(); \ - }; \ - extern NotifyCategoryProxy 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. diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 8d081ebf5f..de7d68b6b6 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -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"