Link dbus-daemon and dbus-daemon-lauch-helper against libdbus
authorBertrand SIMONNET <bsimonnet@chromium.org>
Wed, 20 Aug 2014 22:43:23 +0000 (15:43 -0700)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Fri, 20 Feb 2015 20:49:45 +0000 (20:49 +0000)
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
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
bus/Makefile.am
cmake/CMakeLists.txt
cmake/dbus/CMakeLists.txt
configure.ac
dbus/Makefile.am
dbus/Version.in [new file with mode: 0644]
m4/ld-version-script.m4 [new file with mode: 0644]
test/Makefile.am
test/name-test/Makefile.am

index 9d3cb00..0b9998d 100644 (file)
@@ -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:
index 9a1be6c..adc6d4b 100644 (file)
@@ -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 )
 
index a6aaba0..7c6b1ee 100644 (file)
@@ -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)
index 6dcf64a..f197f07 100644 (file)
@@ -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
index 2dcb0c3..56668d3 100644 (file)
@@ -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 (file)
index 0000000..f6cc367
--- /dev/null
@@ -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 (file)
index 0000000..228f52f
--- /dev/null
@@ -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 <<EOF
+VERS_1 {
+       global: sym;
+};
+
+VERS_2 {
+        global: sym;
+} VERS_1;
+EOF
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+                   [have_ld_version_script=yes], [have_ld_version_script=no])
+    rm -f conftest.map
+    LDFLAGS="$save_LDFLAGS"
+    AC_MSG_RESULT($have_ld_version_script)
+  fi
+])
index 92fbdef..723d776 100644 (file)
@@ -4,23 +4,15 @@
 SUBDIRS= . name-test 
 DIST_SUBDIRS=name-test
 
-# CPPFLAGS for binaries that are normally dynamic
 AM_CPPFLAGS = \
        -I$(top_srcdir) \
-       $(DBUS_STATIC_BUILD_CPPFLAGS) \
+       -DDBUS_COMPILATION \
        $(GLIB_CFLAGS) \
        $(NULL)
 
 # improve backtraces from test stuff
 AM_LDFLAGS = @R_DYNAMIC_LDFLAG@
 
-# CPPFLAGS for binaries that are always static
-static_cppflags = \
-       $(AM_CPPFLAGS) \
-       -DDBUS_STATIC_BUILD \
-       -DDBUS_COMPILATION \
-       $(NULL)
-
 noinst_LTLIBRARIES = libdbus-testutils.la
 
 libdbus_testutils_la_SOURCES = \
@@ -35,13 +27,11 @@ libdbus_testutils_la_SOURCES += \
        $(NULL)
 endif
 
-testutils_shared_if_possible_cppflags = $(static_cppflags)
+testutils_shared_if_possible_cppflags = $(AM_CPPFLAGS)
 testutils_shared_if_possible_libs = libdbus-testutils.la
 
-libdbus_testutils_la_CPPFLAGS = \
-       $(static_cppflags) \
-       $(NULL)
 libdbus_testutils_la_LIBADD = \
+       $(top_builddir)/dbus/libdbus-1.la \
        $(top_builddir)/dbus/libdbus-internal.la \
        $(NULL)
 
@@ -80,43 +70,31 @@ endif !DBUS_ENABLE_EMBEDDED_TESTS
 
 noinst_PROGRAMS= $(TEST_BINARIES)
 
-test_service_CPPFLAGS = $(static_cppflags)
 test_service_LDADD = libdbus-testutils.la
-test_names_CPPFLAGS = $(static_cppflags)
 test_names_LDADD = libdbus-testutils.la
-## break_loader_CPPFLAGS = $(static_cppflags)
 ## break_loader_LDADD = $(top_builddir)/dbus/libdbus-internal.la
-test_shell_service_CPPFLAGS = $(static_cppflags)
 test_shell_service_LDADD = libdbus-testutils.la
 test_shell_SOURCES = shell-test.c
-test_shell_CPPFLAGS = $(static_cppflags)
 test_shell_LDADD = libdbus-testutils.la
 test_spawn_SOURCES = spawn-test.c
-test_spawn_CPPFLAGS = $(static_cppflags)
 test_spawn_LDADD = $(top_builddir)/dbus/libdbus-internal.la
 
 test_printf_SOURCES = internals/printf.c
-test_printf_CPPFLAGS = $(static_cppflags)
 test_printf_LDADD = $(top_builddir)/dbus/libdbus-internal.la
 
 test_refs_SOURCES = internals/refs.c
-test_refs_CPPFLAGS = $(static_cppflags)
 test_refs_LDADD = libdbus-testutils.la $(GLIB_LIBS)
 
 test_syslog_SOURCES = internals/syslog.c
-test_syslog_CPPFLAGS = $(static_cppflags)
 test_syslog_LDADD = libdbus-testutils.la $(GLIB_LIBS)
 
 manual_dir_iter_SOURCES = manual-dir-iter.c
-manual_dir_iter_CPPFLAGS = $(static_cppflags)
 manual_dir_iter_LDADD = $(top_builddir)/dbus/libdbus-internal.la
 
 manual_paths_SOURCES = manual-paths.c
-manual_paths_CPPFLAGS = $(static_cppflags)
 manual_paths_LDADD = $(top_builddir)/dbus/libdbus-internal.la
 
 manual_tcp_SOURCES = manual-tcp.c
-manual_tcp_CPPFLAGS = $(static_cppflags)
 manual_tcp_LDADD = $(top_builddir)/dbus/libdbus-internal.la
 
 EXTRA_DIST = dbus-test-runner
@@ -265,9 +243,6 @@ test_uid_permissions_LDADD = \
 test_fdpass_SOURCES = \
     fdpass.c \
     $(NULL)
-test_fdpass_CPPFLAGS = \
-    $(static_cppflags) \
-    $(NULL)
 test_fdpass_LDADD = \
     libdbus-testutils.la \
     $(GLIB_LIBS) \
index 8df9899..b28a7e8 100644 (file)
@@ -1,8 +1,6 @@
-# Everything in this directory is statically-linked to libdbus-internal
 AM_CPPFLAGS = \
        -I$(top_srcdir) \
        -DDBUS_COMPILATION \
-       -DDBUS_STATIC_BUILD \
        $(NULL)
 
 # if assertions are enabled, improve backtraces
@@ -34,10 +32,10 @@ if DBUS_ENABLE_EMBEDDED_TESTS
 ## build even when not doing "make check"
 noinst_PROGRAMS=test-pending-call-dispatch test-pending-call-timeout test-threads-init test-ids test-shutdown test-privserver test-privserver-client test-autolaunch
 
-test_pending_call_dispatch_LDADD=$(top_builddir)/dbus/libdbus-internal.la
-test_pending_call_timeout_LDADD=$(top_builddir)/dbus/libdbus-internal.la
-test_threads_init_LDADD=$(top_builddir)/dbus/libdbus-internal.la
-test_ids_LDADD=$(top_builddir)/dbus/libdbus-internal.la
+test_pending_call_dispatch_LDADD=$(top_builddir)/dbus/libdbus-1.la
+test_pending_call_timeout_LDADD=$(top_builddir)/dbus/libdbus-1.la
+test_threads_init_LDADD=$(top_builddir)/dbus/libdbus-1.la
+test_ids_LDADD=$(top_builddir)/dbus/libdbus-1.la
 
 test_shutdown_LDADD=../libdbus-testutils.la
 test_privserver_LDADD=../libdbus-testutils.la