From 6551d0a49bab7ea824582a71a791b6ac36e5ff46 Mon Sep 17 00:00:00 2001 From: Bertrand SIMONNET Date: Wed, 20 Aug 2014 15:43:23 -0700 Subject: [PATCH] Link dbus-daemon and dbus-daemon-lauch-helper against libdbus The shared can be used by dbus-daemon and dbus-daemon-launch-helper by exporting the private symbols needed, reducing the size of dbus by about 500k. The private symbols are exposed under the version LIBDBUS_PRIVATE_@VERSION_NUMBER@. --- bus/Makefile.am | 12 +++-- configure.ac | 8 ++++ dbus/Makefile.am | 23 ++++------ dbus/Version.in | 10 ++++ m4/ld-version-script.m4 | 43 +++++++++++++++++ test/Makefile.am | 112 +++++++++++++++++---------------------------- test/name-test/Makefile.am | 18 ++++---- 7 files changed, 126 insertions(+), 100 deletions(-) create mode 100644 dbus/Version.in create mode 100644 m4/ld-version-script.m4 diff --git a/bus/Makefile.am b/bus/Makefile.am index f335e30..1b40698 100644 --- a/bus/Makefile.am +++ b/bus/Makefile.am @@ -97,6 +97,7 @@ dbus_daemon_SOURCES= \ main.c dbus_daemon_LDADD= \ + $(top_builddir)/dbus/libdbus-1.la \ $(top_builddir)/dbus/libdbus-internal.la \ $(EFENCE) \ $(DBUS_BUS_LIBS) @@ -121,7 +122,8 @@ dbus_daemon_launch_helper_SOURCES= \ $(LAUNCH_HELPER_SOURCES) dbus_daemon_launch_helper_LDADD= \ - $(top_builddir)/dbus/libdbus-internal.la \ + $(top_builddir)/dbus/libdbus-1.la \ + $(top_builddir)/dbus/libdbus-internal.la \ $(DBUS_LAUNCHER_LIBS) ## we build another binary so we can do the launch testing without root privs. @@ -131,7 +133,7 @@ dbus_daemon_launch_helper_test_SOURCES= \ $(LAUNCH_HELPER_SOURCES) dbus_daemon_launch_helper_test_LDADD= \ - $(top_builddir)/dbus/libdbus-internal.la \ + $(top_builddir)/dbus/libdbus-1.la \ $(DBUS_LAUNCHER_LIBS) dbus_daemon_launch_helper_test_CPPFLAGS = \ @@ -145,7 +147,7 @@ test_bus_launch_helper_SOURCES= \ $(LAUNCH_HELPER_SOURCES) test_bus_launch_helper_LDADD= \ - $(top_builddir)/dbus/libdbus-internal.la \ + $(top_builddir)/dbus/libdbus-1.la \ $(DBUS_LAUNCHER_LIBS) test_bus_launch_helper_CPPFLAGS = \ @@ -190,13 +192,13 @@ test_bus_system_SOURCES= \ utils.h \ test-system.c -test_bus_system_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_BUS_LIBS) +test_bus_system_LDADD=$(top_builddir)/dbus/libdbus-1.la $(DBUS_BUS_LIBS) test_bus_SOURCES= \ $(BUS_SOURCES) \ test-main.c -test_bus_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_BUS_LIBS) +test_bus_LDADD=$(top_builddir)/dbus/libdbus-1.la $(DBUS_BUS_LIBS) ## mop up the gcov files clean-local: diff --git a/configure.ac b/configure.ac index cbaf874..eb57b9c 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,8 @@ LT_AGE=8 AC_SUBST(LT_CURRENT) AC_SUBST(LT_REVISION) AC_SUBST(LT_AGE) +SOVERSION=`expr ${LT_CURRENT} - ${LT_AGE}` +AC_SUBST([SOVERSION]) DBUS_MAJOR_VERSION=dbus_major_version DBUS_MINOR_VERSION=dbus_minor_version @@ -1385,6 +1387,11 @@ case $host_os in ;; esac +### Detect if ld supports --version-script + +gl_LD_VERSION_SCRIPT +AM_CONDITIONAL([HAVE_LD_VERSION_SCRIPT], + [test "x$have_ld_version_script" = xyes]) ### Doxygen Documentation AC_PATH_PROG(DOXYGEN, doxygen, no) @@ -1750,6 +1757,7 @@ fi AC_CONFIG_FILES([ Doxyfile +dbus/Version dbus/versioninfo.rc dbus/dbus-arch-deps.h bus/system.conf diff --git a/dbus/Makefile.am b/dbus/Makefile.am index 442fd27..1c8a6db 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -42,9 +42,6 @@ else dbus_res = dbus_res_ldflag = no_undefined = -## don't export symbols that start with "_" (we use this -## convention for internal symbols) -export_symbols = -export-symbols-regex "^[^_].*" intllibs = @LTLIBINTL@ @@ -263,34 +260,33 @@ libdbus_1_la_SOURCES= \ $(DBUS_SHARED_SOURCES) libdbus_internal_la_SOURCES= \ - $(DBUS_LIB_SOURCES) \ - $(DBUS_SHARED_SOURCES) \ $(DBUS_UTIL_SOURCES) BUILT_SOURCES=$(nodist_dbusarchinclude_HEADERS) EXTRA_DIST=dbus-arch-deps.h.in -## this library is the same as libdbus, but exports all the symbols -## and is only used for static linking within the dbus package. noinst_LTLIBRARIES=libdbus-internal.la libdbus_1_la_CPPFLAGS = \ $(AM_CPPFLAGS) \ -Ddbus_1_EXPORTS \ $(NULL) + +if HAVE_LD_VERSION_SCRIPT +SYMBOL_EXPORT_LDFLAGS=-Wl,--version-script=Version +else +SYMBOL_EXPORT_LDFLAGS= +endif + libdbus_1_la_LIBADD= $(LIBDBUS_LIBS) libdbus_1_la_LDFLAGS = \ $(AM_LDFLAGS) \ - $(export_symbols) \ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ + $(SYMBOL_EXPORT_LDFLAGS) \ -no-undefined \ $(NULL) -libdbus_internal_la_CPPFLAGS = \ - $(AM_CPPFLAGS) \ - -DDBUS_STATIC_BUILD \ - $(NULL) -libdbus_internal_la_LIBADD=$(LIBDBUS_LIBS) +libdbus_internal_la_LIBADD=$(LIBDBUS_LIBS) libdbus-1.la if DBUS_WIN # This must be a separate convenience library, otherwise libtool notices @@ -300,7 +296,6 @@ if DBUS_WIN noinst_LTLIBRARIES += libdbus-init-win.la libdbus_init_win_la_SOURCES = dbus-init-win.cpp libdbus_1_la_LIBADD += libdbus-init-win.la -libdbus_internal_la_LIBADD += libdbus-init-win.la endif noinst_PROGRAMS = diff --git a/dbus/Version.in b/dbus/Version.in new file mode 100644 index 0000000..f6cc367 --- /dev/null +++ b/dbus/Version.in @@ -0,0 +1,10 @@ +LIBDBUS_1_@SOVERSION@ { + global: + dbus_*; + local: + *; +}; +LIBDBUS_PRIVATE_@DBUS_VERSION@ { + global: + _dbus_*; +}; diff --git a/m4/ld-version-script.m4 b/m4/ld-version-script.m4 new file mode 100644 index 0000000..228f52f --- /dev/null +++ b/m4/ld-version-script.m4 @@ -0,0 +1,43 @@ +# ld-version-script.m4 serial 1 +dnl Copyright (C) 2008, 2009 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Simon Josefsson + +# FIXME: The test below returns a false positive for mingw +# cross-compiles, 'local:' statements does not reduce number of +# exported symbols in a DLL. Use --disable-ld-version-script to work +# around the problem. + +# gl_LD_VERSION_SCRIPT +# -------------------- +# Check if LD supports linker scripts, and define automake conditional +# HAVE_LD_VERSION_SCRIPT if so. +AC_DEFUN([gl_LD_VERSION_SCRIPT], +[ + AC_ARG_ENABLE([ld-version-script], + AS_HELP_STRING([--enable-ld-version-script], + [enable linker version script (default is enabled when possible)]), + [have_ld_version_script=$enableval], []) + if test -z "$have_ld_version_script"; then + AC_MSG_CHECKING([if LD -Wl,--version-script works]) + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map" + cat > conftest.map <