[pulseaudio-commits] r1838 - in /branches/lennart: configure.ac src/Makefile.am src/daemon/ltdl-bind-now.c src/daemon/ltdl-bind-now.h src/daemon/main.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Mon Sep 17 05:31:08 PDT 2007
Author: lennart
Date: Mon Sep 17 14:31:06 2007
New Revision: 1838
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1838&root=pulseaudio&view=rev
Log:
Add a special ltdl .so loader that avoids lazy frelocations during runtime
Added:
branches/lennart/src/daemon/ltdl-bind-now.c (with props)
branches/lennart/src/daemon/ltdl-bind-now.h (with props)
Modified:
branches/lennart/configure.ac
branches/lennart/src/Makefile.am
branches/lennart/src/daemon/main.c
Modified: branches/lennart/configure.ac
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/configure.ac?rev=1838&root=pulseaudio&r1=1837&r2=1838&view=diff
==============================================================================
--- branches/lennart/configure.ac (original)
+++ branches/lennart/configure.ac Mon Sep 17 14:31:06 2007
@@ -187,7 +187,7 @@
AC_CHECK_HEADERS([arpa/inet.h glob.h grp.h netdb.h netinet/in.h \
netinet/in_systm.h netinet/tcp.h pwd.h sched.h \
sys/mman.h sys/resource.h sys/select.h sys/socket.h sys/wait.h \
- syslog.h])
+ syslog.h sys/dl.h dlfcn.h])
AC_CHECK_HEADERS([netinet/ip.h], [], [],
[#include <sys/types.h>
#if HAVE_NETINET_IN_H
Modified: branches/lennart/src/Makefile.am
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/Makefile.am?rev=1838&root=pulseaudio&r1=1837&r2=1838&view=diff
==============================================================================
--- branches/lennart/src/Makefile.am (original)
+++ branches/lennart/src/Makefile.am Mon Sep 17 14:31:06 2007
@@ -132,6 +132,7 @@
daemon/cpulimit.c daemon/cpulimit.h \
daemon/daemon-conf.c daemon/daemon-conf.h \
daemon/dumpmodules.c daemon/dumpmodules.h \
+ daemon/ltdl-bind-now.c daemon/ltdl-bind-now.h \
daemon/main.c \
pulsecore/gccmacro.h
Added: branches/lennart/src/daemon/ltdl-bind-now.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/daemon/ltdl-bind-now.c?rev=1838&root=pulseaudio&view=auto
==============================================================================
--- branches/lennart/src/daemon/ltdl-bind-now.c (added)
+++ branches/lennart/src/daemon/ltdl-bind-now.c Mon Sep 17 14:31:06 2007
@@ -1,0 +1,160 @@
+/* $Id$ */
+
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2004-2006 Lennart Poettering
+ Copyright 2006 Pierre Ossman <ossman at cendio.se> for Cendio AB
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#if HAVE_SYS_DL_H
+#include <sys/dl.h>
+#endif
+
+#include <ltdl.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/mutex.h>
+#include <pulsecore/thread.h>
+#include <pulsecore/log.h>
+
+#include "ltdl-bind-now.h"
+
+#ifdef RTLD_NOW
+#define PA_BIND_NOW RTLD_NOW
+#elif defined(DL_NOW)
+#define PA_BIND_NOW DL_NOW
+#else
+#undef PA_BIND_NOW
+#endif
+
+static pa_mutex *libtool_mutex = NULL;
+
+PA_STATIC_TLS_DECLARE_NO_FREE(libtool_tls);
+
+static void libtool_lock(void) {
+ pa_mutex_lock(libtool_mutex);
+}
+
+static void libtool_unlock(void) {
+ pa_mutex_unlock(libtool_mutex);
+}
+
+static void libtool_set_error(const char *error) {
+ PA_STATIC_TLS_SET(libtool_tls, (char*) error);
+}
+
+static const char *libtool_get_error(void) {
+ return PA_STATIC_TLS_GET(libtool_tls);
+}
+
+#ifdef PA_BIND_NOW
+
+/*
+ To avoid lazy relocations during runtime in our RT threads we add
+ our own shared object loader with uses RTLD_NOW if it is
+ available. The standard ltdl loader prefers RTLD_LAZY.
+
+ Please note that this loader doesn't have any influence on
+ relocations on any libraries that are already loaded into our
+ process, i.e. because the pulseaudio binary links directly to
+ them. To disable lazy relocations for those libraries it is possible
+ to set $LT_BIND_NOW before starting the pulsaudio binary.
+*/
+
+static lt_module bind_now_open(lt_user_data d, const char *fname) {
+ lt_module m;
+
+ pa_assert(fname);
+
+ if (!(m = dlopen(fname, PA_BIND_NOW))) {
+ libtool_set_error(dlerror());
+ return NULL;
+ }
+
+ return m;
+}
+
+static int bind_now_close(lt_user_data d, lt_module m) {
+
+ pa_assert(m);
+
+ if (dlclose(m) != 0){
+ libtool_set_error(dlerror());
+ return 1;
+ }
+
+ return 0;
+}
+
+static lt_ptr bind_now_find_sym(lt_user_data d, lt_module m, const char *symbol) {
+ lt_ptr ptr;
+
+ pa_assert(m);
+ pa_assert(symbol);
+
+ if (!(ptr = dlsym(m, symbol))) {
+ libtool_set_error(dlerror());
+ return NULL;
+ }
+
+ return ptr;
+}
+
+#endif
+
+void pa_ltdl_init(void) {
+
+#ifdef PA_BIND_NOW
+ lt_dlloader *place;
+ static const struct lt_user_dlloader loader = {
+ .module_open = bind_now_open,
+ .module_close = bind_now_close,
+ .find_sym = bind_now_find_sym
+ };
+#endif
+
+ pa_assert_se(lt_dlinit() == 0);
+ pa_assert_se(libtool_mutex = pa_mutex_new(TRUE, FALSE));
+ pa_assert_se(lt_dlmutex_register(libtool_lock, libtool_unlock, libtool_set_error, libtool_get_error) == 0);
+
+#ifdef PA_BIND_NOW
+
+ if (!(place = lt_dlloader_find("dlopen")))
+ place = lt_dlloader_next(NULL);
+
+ /* Add our BIND_NOW loader as the default module loader. */
+ if (lt_dlloader_add(place, &loader, "bind-now-loader") != 0)
+ pa_log_warn("Failed to add bind-now-loader.");
+#endif
+}
+
+void pa_ltdl_done(void) {
+ pa_assert_se(lt_dlexit() == 0);
+ pa_mutex_free(libtool_mutex);
+ libtool_mutex = NULL;
+}
+
Propchange: branches/lennart/src/daemon/ltdl-bind-now.c
------------------------------------------------------------------------------
svn:keywords = Id
Added: branches/lennart/src/daemon/ltdl-bind-now.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/daemon/ltdl-bind-now.h?rev=1838&root=pulseaudio&view=auto
==============================================================================
--- branches/lennart/src/daemon/ltdl-bind-now.h (added)
+++ branches/lennart/src/daemon/ltdl-bind-now.h Mon Sep 17 14:31:06 2007
@@ -1,0 +1,32 @@
+#ifndef foopulsecoreltdlbindnowhfoo
+#define foopulsecoreltdlbindnowhfoo
+
+/* $Id$ */
+
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2004-2006 Lennart Poettering
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+
+void pa_ltdl_init(void);
+void pa_ltdl_done(void);
+
+#endif
+
Propchange: branches/lennart/src/daemon/ltdl-bind-now.h
------------------------------------------------------------------------------
svn:keywords = Id
Modified: branches/lennart/src/daemon/main.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/daemon/main.c?rev=1838&root=pulseaudio&r1=1837&r2=1838&view=diff
==============================================================================
--- branches/lennart/src/daemon/main.c (original)
+++ branches/lennart/src/daemon/main.c Mon Sep 17 14:31:06 2007
@@ -93,6 +93,7 @@
#include "daemon-conf.h"
#include "dumpmodules.h"
#include "caps.h"
+#include "ltdl-bind-now.h"
#ifdef HAVE_LIBWRAP
/* Only one instance of these variables */
@@ -309,38 +310,6 @@
}
#endif
-static pa_mutex *libtool_mutex = NULL;
-
-static void libtool_lock(void) {
- pa_mutex_lock(libtool_mutex);
-}
-
-static void libtool_unlock(void) {
- pa_mutex_unlock(libtool_mutex);
-}
-
-PA_STATIC_TLS_DECLARE_NO_FREE(libtool_tls);
-
-static void libtool_set_error(const char * error) {
- PA_STATIC_TLS_SET(libtool_tls, (char*) error);
-}
-
-static const char *libtool_get_error(void) {
- return PA_STATIC_TLS_GET(libtool_tls);
-}
-
-static void libtool_init(void) {
- pa_assert_se(libtool_mutex = pa_mutex_new(TRUE, FALSE));
- pa_assert_se(lt_dlmutex_register(libtool_lock, libtool_unlock, libtool_set_error, libtool_get_error) == 0);
- pa_assert_se(lt_dlinit() == 0);
-}
-
-static void libtool_done(void) {
- pa_assert_se(lt_dlexit() == 0);
- pa_mutex_free(libtool_mutex);
- libtool_mutex = NULL;
-}
-
int main(int argc, char *argv[]) {
pa_core *c = NULL;
pa_strbuf *buf = NULL;
@@ -396,7 +365,7 @@
LTDL_SET_PRELOADED_SYMBOLS();
- libtool_init();
+ pa_ltdl_init();
#ifdef OS_IS_WIN32
{
@@ -747,7 +716,7 @@
WSACleanup();
#endif
- libtool_done();
+ pa_ltdl_done();
#ifdef HAVE_DBUS
dbus_shutdown();
More information about the pulseaudio-commits
mailing list