diff options
author | Christian Hergert <chergert@redhat.com> | 2019-08-05 19:19:08 -0700 |
---|---|---|
committer | Christian Hergert <chergert@redhat.com> | 2019-08-05 19:19:08 -0700 |
commit | eed297fb82c3ae661b427ac5fe5ea6d299baa86a (patch) | |
tree | c05519606a62418d8783daece14b473d006b4eab | |
parent | 7ad862c039ad5861ab270ac14ee59f664d7e1c32 (diff) | |
download | libpeas-eed297fb82c3ae661b427ac5fe5ea6d299baa86a.tar.gz |
build: hide private symbols with -fvisibility=hidden
This continues with the previous commit to hide non-public symbols by
default. It is slightly complicated by the fact that we need some symbol
access from the unit tests. Normally that would mean we just add a static
library and link against that, but we need shared access to globals so
that is not an option. We could possibly switch to creating a shared
library without -fvisibility=hidden.
-rw-r--r-- | libpeas-gtk/meson.build | 20 | ||||
-rw-r--r-- | libpeas/meson.build | 2 | ||||
-rw-r--r-- | libpeas/peas-engine-priv.h | 5 | ||||
-rw-r--r-- | libpeas/peas-engine.c | 4 | ||||
-rw-r--r-- | meson.build | 17 | ||||
-rw-r--r-- | tests/libpeas-gtk/testing/meson.build | 2 | ||||
-rw-r--r-- | tests/libpeas/engine.c | 4 | ||||
-rw-r--r-- | tests/libpeas/extension-py.c | 2 | ||||
-rw-r--r-- | tests/testing-util/testing-util.c | 6 |
9 files changed, 50 insertions, 12 deletions
diff --git a/libpeas-gtk/meson.build b/libpeas-gtk/meson.build index 3becc7e..2f099f7 100644 --- a/libpeas-gtk/meson.build +++ b/libpeas-gtk/meson.build @@ -29,6 +29,8 @@ libpeas_gtk_c_args = [ '-DG_LOG_DOMAIN="libpeas-gtk"', ] +libpeas_gtk_c_args += hidden_visibility_args + libpeas_gtk_link_args = [ ] @@ -40,6 +42,17 @@ install_headers( ) ) +# Static library used for testing symbol access +libpeas_gtk_test = static_library( + package_gtk_string.strip('lib'), + libpeas_gtk_c, + version: lib_version, + include_directories: rootdir, + dependencies: libpeas_gtk_deps, + c_args: libpeas_gtk_c_args, + link_args: libpeas_gtk_link_args, +) + libpeas_gtk_sha = library( package_gtk_string.strip('lib'), libpeas_gtk_c, @@ -92,6 +105,13 @@ libpeas_gtk_dep = declare_dependency( sources: libpeas_gtk_dep_sources, ) +libpeas_gtk_test_dep = declare_dependency( + link_with: libpeas_gtk_test, + dependencies: libpeas_gtk_deps, + include_directories: rootdir, + sources: libpeas_gtk_dep_sources, +) + libpeas_gtk_pc = pkg.generate( libpeas_gtk_sha, name: package_gtk_string, diff --git a/libpeas/meson.build b/libpeas/meson.build index d48d535..75bd369 100644 --- a/libpeas/meson.build +++ b/libpeas/meson.build @@ -91,7 +91,7 @@ libpeas_sha = library( version: lib_version, include_directories: [rootdir, libpeas_srcdir], dependencies: libpeas_deps, - c_args: libpeas_c_args, + c_args: libpeas_c_args + hidden_visibility_args, link_args: libpeas_link_args, install: true, install_dir: libdir, diff --git a/libpeas/peas-engine-priv.h b/libpeas/peas-engine-priv.h index c8fa9fd..c763a9c 100644 --- a/libpeas/peas-engine-priv.h +++ b/libpeas/peas-engine-priv.h @@ -22,9 +22,12 @@ #ifndef __PEAS_ENGINE_PRIV_H__ #define __PEAS_ENGINE_PRIV_H__ +#include "peas-version-macros.h" + G_BEGIN_DECLS -void peas_engine_shutdown (void); +PEAS_AVAILABLE_IN_ALL +void _peas_engine_shutdown (void); G_END_DECLS diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c index 86706a0..de0b3c4 100644 --- a/libpeas/peas-engine.c +++ b/libpeas/peas-engine.c @@ -1635,7 +1635,7 @@ peas_engine_get_default (void) } /* < private > - * peas_engine_shutdown: + * _peas_engine_shutdown: * * Frees memory shared by PeasEngines. * No libpeas API should be called after calling this. @@ -1643,7 +1643,7 @@ peas_engine_get_default (void) * Note: this is private API and as such is not thread-safe. */ void -peas_engine_shutdown (void) +_peas_engine_shutdown (void) { gint i; diff --git a/meson.build b/meson.build index f73d986..683b037 100644 --- a/meson.build +++ b/meson.build @@ -123,6 +123,23 @@ if build_machine.system() == 'darwin' config_h.set_quoted('OS_OSX', 1) endif +# Detect and set symbol visibility +hidden_visibility_args = [] +if get_option('default_library') != 'static' + if host_machine.system() == 'windows' + config_h.set('DLL_EXPORT', true) + if cc.get_id() == 'msvc' + config_h.set('_PEAS_EXTERN', '__declspec(dllexport) extern') + elif cc.has_argument('-fvisibility=hidden') + config_h.set('_PEAS_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern') + hidden_visibility_args = ['-fvisibility=hidden'] + endif + elif cc.has_argument('-fvisibility=hidden') + config_h.set('_PEAS_EXTERN', '__attribute__((visibility("default"))) extern') + hidden_visibility_args = ['-fvisibility=hidden'] + endif +endif + configure_file( output: 'config.h', configuration: config_h diff --git a/tests/libpeas-gtk/testing/meson.build b/tests/libpeas-gtk/testing/meson.build index 62fd54d..ea9dbc5 100644 --- a/tests/libpeas-gtk/testing/meson.build +++ b/tests/libpeas-gtk/testing/meson.build @@ -13,7 +13,7 @@ libpeas_gtk_testing_deps = [ glib_dep, introspection_dep, libpeas_dep, - libpeas_gtk_dep, + libpeas_gtk_test_dep, libtesting_util_dep, ] diff --git a/tests/libpeas/engine.c b/tests/libpeas/engine.c index 0c975f4..e6ba2cc 100644 --- a/tests/libpeas/engine.c +++ b/tests/libpeas/engine.c @@ -449,8 +449,8 @@ test_engine_shutdown_subprocess (PeasEngine *engine) testing_engine_free (engine); /* Should be able to shutdown multiple times */ - peas_engine_shutdown (); - peas_engine_shutdown (); + _peas_engine_shutdown (); + _peas_engine_shutdown (); /* Cannot create an engine because libpeas has been shutdown */ engine = peas_engine_new (); diff --git a/tests/libpeas/extension-py.c b/tests/libpeas/extension-py.c index 0d9f913..8ec155d 100644 --- a/tests/libpeas/extension-py.c +++ b/tests/libpeas/extension-py.c @@ -169,7 +169,7 @@ test_extension_py_already_initialized_subprocess (void) PyDict_Clear (dict); testing_engine_free (engine); - peas_engine_shutdown (); + _peas_engine_shutdown (); /* Should still be initialized */ g_assert (Py_IsInitialized ()); diff --git a/tests/testing-util/testing-util.c b/tests/testing-util/testing-util.c index 1f167a9..f35c806 100644 --- a/tests/testing-util/testing-util.c +++ b/tests/testing-util/testing-util.c @@ -19,9 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif +#include "config.h" #include <stdlib.h> @@ -300,7 +298,7 @@ testing_util_run_tests (void) g_private_replace (&engine_key, NULL); g_private_replace (&unhandled_key, NULL); g_private_replace (&log_hooks_key, NULL); - peas_engine_shutdown (); + _peas_engine_shutdown (); return retval; } |