From 2e7669f5cc46927602108c328fbbeb846bd09218 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Thu, 6 Dec 2012 13:42:06 -0500 Subject: [PATCH] configure.ac: change our visibility policy Check for -fvisibility=hidden as a supported CFLAG. If it is supported, use it and emit an AC_DEFINE to change the meaning of _GLIB_EXTERN to include the GNU attribute for marking symbols as public: __attribute((visibility("default"))). This will override the public definition of _GLIB_EXTERN for any file which does #include "config.h" (forcing all our .c files to do so, as a side effect). If we're on mingw, assume that -fvisibility will work and also throw in a __declspec(dllexport) for good measure. This will allow us to move away from using a .def file to create the the various DLLs. It's possible that there may be compilers that accept -fvisibility=hidden but don't accept the GNU attribute for making symbols public again -- we will hopefully receive bugs if any of those exist. https://bugzilla.gnome.org/show_bug.cgi?id=688681 --- configure.ac | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/configure.ac b/configure.ac index 5cb21df..9e48f90 100644 --- a/configure.ac +++ b/configure.ac @@ -3566,6 +3566,37 @@ fi AC_SUBST(GLIB_LINK_FLAGS) +dnl +dnl Check for -fvisibility=hidden to determine if we can do GNU-style +dnl visibility attributes for symbol export control +dnl +case "$host" in + *-*-mingw*) + dnl on mingw32 we do -fvisibility=hidden and __declspec(dllexport) + AC_DEFINE([_GLIB_EXTERN], [__attribute__((visibility("default"))) __declspec(dllexport) extern], + [defines how to decorate public symbols while building]) + CFLAGS="${CFLAGS} -fvisibility=hidden" + ;; + *) + dnl on other compilers, check if we can do -fvisibility=hidden + SAVED_CFLAGS="${CFLAGS}" + CFLAGS="-fvisibility=hidden" + AC_MSG_CHECKING([for -fvisibility=hidden compiler flag]) + AC_TRY_COMPILE([], [int main (void) { return 0; }], + AC_MSG_RESULT(yes) + enable_fvisibility_hidden=yes, + AC_MSG_RESULT(no) + enable_fvisibility_hidden=no) + CFLAGS="${SAVED_CFLAGS}" + + AS_IF([test "${enable_fvisibility_hidden}" = "yes"], [ + AC_DEFINE([_GLIB_EXTERN], [__attribute__((visibility("default"))) extern], + [defines how to decorate public symbols while building]) + CFLAGS="${CFLAGS} -fvisibility=hidden" + ]) + ;; +esac + dnl Compiler flags; macro originates from systemd dnl See https://bugzilla.gnome.org/show_bug.cgi?id=608953 CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\ -- 2.7.4