[glib/wip/symbol-visibility: 5/6] Use -fvisibility=hidden by default



commit 3cc1d4f0e69d0de25f4579eca6653f0e4ad402c4
Author: Colin Walters <walters verbum org>
Date:   Wed Nov 28 16:22:48 2012 -0500

    Use -fvisibility=hidden by default
    
    Now that we have all symbols annotated as GLIB_PUBLIC, we can switch
    the build to default to hiding symbols.  The major advantage of this
    is that it's much harder to accidentally leak symbols.
    
    This patch only adds it to CFLAGS for the sublibraries; we don't want
    to affect things like gio/fam, nor the executables.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688681

 configure.ac        |   17 +++++++++++++++++
 gio/Makefile.am     |    3 ++-
 glib/Makefile.am    |    1 +
 gmodule/Makefile.am |    1 +
 gobject/Makefile.am |    2 +-
 gthread/Makefile.am |    1 +
 6 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 548fa1c..f5ff45d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -868,6 +868,12 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#if defined(__SUNPRO_C) || (__SUNPRO_C >= 0
 AC_MSG_RESULT($g_have_sunstudio_visibility)
 AM_CONDITIONAL(HAVE_SUNSTUDIO_VISIBILITY, [test x$g_have_sunstudio_visibility = xyes])
 
+dnl See https://bugzilla.gnome.org/show_bug.cgi?id=688681
+dnl First half of symbol visibility; search for "Second half of symbol
+dnl visibility" below to find the second part.
+AS_IF([test x$g_have_gnuc_visibility = x && test x$g_have_sunstudio_visibility = x], [
+  AC_MSG_ERROR([GLib does not know how to control symbol visibility on this platform])])
+
 # check for bytesex stuff
 AC_C_BIGENDIAN
 if test x$ac_cv_c_bigendian = xuniversal ; then
@@ -3542,6 +3548,17 @@ fi
 
 AC_SUBST(GLIB_LINK_FLAGS)
 
+dnl See https://bugzilla.gnome.org/show_bug.cgi?id=688681
+dnl Second half of symbol visibility; search for "First half of symbol
+dnl visibility" above to find the first part.  They are separated for
+dnl the same reason the -Werror bits below are last - so we don't affect
+dnl any autoconf tests.
+GLIB_HIDDEN_VISIBILITY_CFLAGS=""
+AS_IF([test x$GCC = xyes], [GLIB_HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden"],
+      [test x$g_have_sunstudio_visibility != x], [GLIB_HIDDEN_VISIBILITY_CFLAGS="-xldscope=hidden"],
+      [AC_MSG_ERROR([GLib does not know how to make symbols hidden by default with this compiler])])
+AC_SUBST(GLIB_HIDDEN_VISIBILITY_CFLAGS)
+
 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], [\
diff --git a/gio/Makefile.am b/gio/Makefile.am
index a3cf1ed..fbdad50 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -518,6 +518,7 @@ install-data-local: install-ms-lib install-def-file
 
 uninstall-local: uninstall-ms-lib uninstall-def-file
 
+libgio_2_0_la_CFLAGS = $(AM_CFLAGS) $(GLIB_HIDDEN_VISIBILITY_CFLAGS)
 libgio_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	$(gio_win32_res_ldflag) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
@@ -525,7 +526,7 @@ libgio_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 
 if OS_COCOA
 # This is dumb.  The ObjC source file should be properly named .m
-libgio_2_0_la_CFLAGS = -xobjective-c
+libgio_2_0_la_CFLAGS += -xobjective-c
 libgio_2_0_la_LDFLAGS += -Wl,-framework,Foundation
 endif
 
diff --git a/glib/Makefile.am b/glib/Makefile.am
index 4249de2..26be6e3 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -378,6 +378,7 @@ pcre_lib = pcre/libpcre.la
 pcre_inc =
 endif
 
+libglib_2_0_la_CFLAGS = $(AM_CFLAGS) $(GLIB_HIDDEN_VISIBILITY_CFLAGS)
 libglib_2_0_la_LIBADD = libcharset/libcharset.la $(printf_la) @GIO@ @GSPAWN@ @PLATFORMDEP@ @ICONV_LIBS@ @G_LIBS_EXTRA@ $(pcre_lib) $(G_THREAD_LIBS_EXTRA) $(G_THREAD_LIBS_FOR_GTHREAD)
 libglib_2_0_la_DEPENDENCIES = libcharset/libcharset.la $(printf_la) @GIO@ @GSPAWN@ @PLATFORMDEP@ $(glib_win32_res) $(glib_def)
 
diff --git a/gmodule/Makefile.am b/gmodule/Makefile.am
index 6496863..85e5e76 100644
--- a/gmodule/Makefile.am
+++ b/gmodule/Makefile.am
@@ -79,6 +79,7 @@ install-def-file:
 uninstall-def-file:
 endif
 
+libgmodule_2_0_la_CFLAGS = $(AM_CFLAGS) $(GLIB_HIDDEN_VISIBILITY_CFLAGS)
 libgmodule_2_0_la_SOURCES = gmodule.c
 libgmodule_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	$(gmodule_win32_res_ldflag) \
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index 6976e8a..1497b55 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -80,7 +80,7 @@ libgobject_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
   -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
   -export-dynamic $(no_undefined) $(export_symbols)
 
-libgobject_2_0_la_CFLAGS = $(LIBFFI_CFLAGS)
+libgobject_2_0_la_CFLAGS = $(AM_CFLAGS) $(LIBFFI_CFLAGS) $(GLIB_HIDDEN_VISIBILITY_CFLAGS)
 
 libgobject_2_0_la_LIBADD = $(libglib) $(LIBFFI_LIBS)
 
diff --git a/gthread/Makefile.am b/gthread/Makefile.am
index e2916b8..119a47d 100644
--- a/gthread/Makefile.am
+++ b/gthread/Makefile.am
@@ -62,6 +62,7 @@ gthread_win32_res = gthread-win32-res.o
 gthread_win32_res_ldflag = -Wl,$(gthread_win32_res)
 endif
 
+libgthread_2_0_la_CFLAGS = $(AM_CFLAGS) $(GLIB_HIDDEN_VISIBILITY_CFLAGS)
 libgthread_2_0_la_SOURCES = gthread-impl.c
 libgthread_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	$(gthread_win32_res_ldflag) \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]