From e3fc9d9e9105708684fb1865ebf1830132515a85 Mon Sep 17 00:00:00 2001 From: Bertrand SIMONNET Date: Wed, 20 Aug 2014 15:43:23 -0700 Subject: [PATCH 6/6] 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@. [Altered by Simon McVittie and Ralf Habacker to clear up some problematic linking.] Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83115 --- bus/Makefile.am | 19 ++++++++++++++++--- cmake/CMakeLists.txt | 7 +------ cmake/dbus/CMakeLists.txt | 7 +------ configure.ac | 8 ++++++++ dbus/Makefile.am | 23 +++++++++-------------- dbus/Version.in | 10 ++++++++++ m4/ld-version-script.m4 | 43 +++++++++++++++++++++++++++++++++++++++++++ test/Makefile.am | 31 +++---------------------------- test/name-test/Makefile.am | 10 ++++------ 9 files changed, 95 insertions(+), 63 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 9d3cb00..0b9998d 100644 --- a/bus/Makefile.am +++ b/bus/Makefile.am @@ -112,6 +112,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) @@ -136,7 +137,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. @@ -146,6 +148,7 @@ dbus_daemon_launch_helper_test_SOURCES= \ $(LAUNCH_HELPER_SOURCES) dbus_daemon_launch_helper_test_LDADD= \ + $(top_builddir)/dbus/libdbus-1.la \ $(top_builddir)/dbus/libdbus-internal.la \ $(DBUS_LAUNCHER_LIBS) @@ -160,8 +163,10 @@ test_bus_launch_helper_SOURCES= \ $(LAUNCH_HELPER_SOURCES) test_bus_launch_helper_LDADD= \ + $(top_builddir)/dbus/libdbus-1.la \ $(top_builddir)/dbus/libdbus-internal.la \ $(DBUS_LAUNCHER_LIBS) + $(NULL) test_bus_launch_helper_CPPFLAGS = \ $(AM_CPPFLAGS) \ @@ -205,13 +210,21 @@ 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 \ + $(top_builddir)/dbus/libdbus-internal.la \ + $(DBUS_BUS_LIBS) \ + $(NULL) 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 \ + $(top_builddir)/dbus/libdbus-internal.la \ + $(DBUS_BUS_LIBS) \ + $(NULL) ## mop up the gcov files clean-local: diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 9a1be6c..adc6d4b 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -475,13 +475,8 @@ endif (DBUS_BUILD_TESTS) set(DBUS_LIBRARIES dbus-1) set(DBUS_INTERNAL_LIBRARIES dbus-internal) -# settings for building and using static internal lib -# important note: DBUS_INTERNAL_xxxxx_DEFINITIONS must *not* be set when building dbus-1 library set (DBUS_INTERNAL_ADD_LIBRARY_OPTIONS STATIC) -set (DBUS_INTERNAL_LIBRARY_DEFINITIONS "-DDBUS_STATIC_BUILD") -# For now, the CMake build system doesn't support replacing the internal -# main loop with dbus-glib -set (DBUS_INTERNAL_CLIENT_DEFINITIONS "-DDBUS_STATIC_BUILD -DDBUS_COMPILATION") +set (DBUS_INTERNAL_CLIENT_DEFINITIONS "-DDBUS_COMPILATION") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h ) diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt index a6aaba0..7c6b1ee 100644 --- a/cmake/dbus/CMakeLists.txt +++ b/cmake/dbus/CMakeLists.txt @@ -291,15 +291,10 @@ install_files(/include/dbus FILES ${dbusinclude_HEADERS}) ### Internal library, used for the daemon, tools and tests, compiled statically. add_library(dbus-internal ${DBUS_INTERNAL_ADD_LIBRARY_OPTIONS} - ${DBUS_LIB_SOURCES} - ${DBUS_LIB_HEADERS} - ${DBUS_SHARED_SOURCES} - ${DBUS_SHARED_HEADERS} ${DBUS_UTIL_SOURCES} ${DBUS_UTIL_HEADERS} ) -target_link_libraries(dbus-internal) -set_target_properties(dbus-internal PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_LIBRARY_DEFINITIONS}) +target_link_libraries(dbus-internal dbus-1) if(WIN32) if(WINCE) target_link_libraries(dbus-internal ws2) diff --git a/configure.ac b/configure.ac index 6dcf64a..f197f07 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,8 @@ LT_AGE=12 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 @@ -1418,6 +1420,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) @@ -1824,6 +1831,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 2dcb0c3..56668d3 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -54,9 +54,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@ @@ -275,34 +272,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 @@ -312,7 +308,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 <