configure.ac: change our visibility policy
authorRyan Lortie <desrt@desrt.ca>
Thu, 6 Dec 2012 18:42:06 +0000 (13:42 -0500)
committerRyan Lortie <desrt@desrt.ca>
Mon, 14 Jan 2013 03:59:40 +0000 (22:59 -0500)
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

index 5cb21df..9e48f90 100644 (file)
@@ -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], [\