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



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

    Use -fvisibility=hidden by default on Unix
    
    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.
    
    However, this patch only changes Unix - on Windows, we keep the
    .symbols file because we still ultimately need a .def file in order to
    generate a .dll.
    
    To unify both Unix and Windows again, we need to do what cairo does
    and parse the headers at build time.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688681

 configure.ac        |   17 +++++++++++++++++
 gio/Makefile.am     |    9 ++++++---
 glib/Makefile.am    |    7 +++++--
 gmodule/Makefile.am |    5 ++++-
 gobject/Makefile.am |    8 +++++---
 gthread/Makefile.am |    7 +++++--
 6 files changed, 42 insertions(+), 11 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4831fff..8e907a1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -858,6 +858,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
@@ -3532,6 +3538,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 9c1557e..a780eb1 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -10,6 +10,8 @@ SUBDIRS += xdgmime
 endif
 
 if OS_WIN32_AND_DLL_COMPILATION
+gio_def = gio.def
+export_symbols = -export-symbols $(gio_def)
 if MS_LIB_AVAILABLE
 noinst_DATA = gio-2.0.lib
 
@@ -507,18 +509,19 @@ 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) \
-	-export-dynamic $(no_undefined) -export-symbols gio.def
+	-export-dynamic $(no_undefined) $(export_symbols)
 
 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
 
-libgio_2_0_la_DEPENDENCIES = $(gio_win32_res) gio.def $(platform_deps)
+libgio_2_0_la_DEPENDENCIES = $(gio_win32_res) $(gio_def) $(platform_deps)
 
 gio-win32-res.o: gio.rc
 	$(WINDRES) gio.rc $@
diff --git a/glib/Makefile.am b/glib/Makefile.am
index 8b339c2..6534526 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -90,6 +90,8 @@ BUILT_EXTRA_DIST = 		\
 lib_LTLIBRARIES = libglib-2.0.la
 
 if OS_WIN32_AND_DLL_COMPILATION
+glib_def = glib.def
+export_symbols = -export-symbols $(glib_def)
 if MS_LIB_AVAILABLE
 noinst_DATA = glib-2.0.lib
 
@@ -365,13 +367,14 @@ 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
+libglib_2_0_la_DEPENDENCIES = libcharset/libcharset.la $(printf_la) @GIO@ @GSPAWN@ @PLATFORMDEP@ $(glib_win32_res) $(glib_def)
 
 libglib_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	 $(glib_win32_res_ldflag) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-	-export-dynamic $(no_undefined) -export-symbols glib.def
+	-export-dynamic $(no_undefined) $(export_symbols)
 
 INSTALL_PROGS=
 
diff --git a/gmodule/Makefile.am b/gmodule/Makefile.am
index 20ab31e..0681b03 100644
--- a/gmodule/Makefile.am
+++ b/gmodule/Makefile.am
@@ -65,6 +65,8 @@ no_undefined = -no-undefined
 endif
 
 if OS_WIN32_AND_DLL_COMPILATION
+gmodule_def = gmodule.def
+export_symbols = -export-symbols $(gmodule_def)
 gmodule_win32_res = gmodule-win32-res.o
 gmodule_win32_res_ldflag = -Wl,$(gmodule_win32_res)
 
@@ -78,12 +80,13 @@ 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) \
 	$(G_MODULE_LDFLAGS) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-	-export-dynamic $(no_undefined) -export-symbols gmodule.def
+	-export-dynamic $(no_undefined) $(export_symbols)
 
 libgmodule_2_0_la_LIBADD = $(G_MODULE_LIBS_EXTRA) $(G_MODULE_LIBS) $(libglib)
 
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index f5d5fca..23d1f5d 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -30,6 +30,8 @@ libglib = $(top_builddir)/glib/libglib-2.0.la
 lib_LTLIBRARIES = libgobject-2.0.la
 
 if OS_WIN32_AND_DLL_COMPILATION
+gobject_def = gobject.def
+export_symbols = -export-symbols $(gobject_def)
 if MS_LIB_AVAILABLE
 noinst_DATA = gobject-2.0.lib
 
@@ -67,13 +69,13 @@ libgobjectincludedir = $(includedir)/glib-2.0/gobject
 libgobject_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
   $(gobject_win32_res_ldflag) \
   -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-  -export-dynamic $(no_undefined) -export-symbols gobject.def
+  -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)
 
-libgobject_2_0_la_DEPENDENCIES = $(gobject_win32_res) gobject.def
+libgobject_2_0_la_DEPENDENCIES = $(gobject_win32_res) $(gobject_def)
 
 #
 # setup source file variables
diff --git a/gthread/Makefile.am b/gthread/Makefile.am
index 4b6a752..a294543 100644
--- a/gthread/Makefile.am
+++ b/gthread/Makefile.am
@@ -28,6 +28,8 @@ top_builddir_full=`cd \$(top_builddir); pwd`
 lib_LTLIBRARIES = libgthread-2.0.la
 
 if OS_WIN32_AND_DLL_COMPILATION
+gthread_def = gthread.def
+export_symbols = -export-symbols $(gthread_def)
 if MS_LIB_AVAILABLE
 noinst_DATA = gthread-2.0.lib
 
@@ -62,15 +64,16 @@ 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) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-	-export-dynamic $(no_undefined) -export-symbols gthread.def
+	-export-dynamic $(no_undefined) $(export_symbols)
 
 libgthread_2_0_la_LIBADD = $(G_THREAD_LIBS_EXTRA) $(G_THREAD_LIBS_FOR_GTHREAD) $(libglib)
 
-libgthread_2_0_la_DEPENDENCIES = $(gthread_win32_res) gthread.def
+libgthread_2_0_la_DEPENDENCIES = $(gthread_win32_res) $(gthread_def)
 
 gthread-win32-res.o: gthread.rc
 	$(AM_V_GEN) $(WINDRES) gthread.rc $@



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