[COMMITTED] cli: use $LIB to handle multilib automagically on glibc

Alexander Monakov amonakov at ispras.ru
Wed Oct 16 10:09:24 PDT 2013


Hello,

I have pushed the following patch that simplifies apitrace usage on
multilib/multiarch Linux distributions.  The `apitrace trace' command now will
set `LD_PRELOAD=/usr/bin/../$LIB/apitrace/wrappers/glxtrace.so', so that the
dynamic linker will pick appropriate wrapper library for the executable.

Maintainers who package apitrace on Linux no longer need to build a separate
`apitrace32' binary to allow tracing 32-bit apps on a 64-bit distro.

diff --git a/cli/cli_resources.cpp b/cli/cli_resources.cpp
index a4797e1..d6d0a55 100644
--- a/cli/cli_resources.cpp
+++ b/cli/cli_resources.cpp
@@ -32,6 +32,27 @@
 
 #include "cli_resources.hpp"
 
+#ifdef __GLIBC__
+
+#include <dlfcn.h>
+
+static bool
+tryLib(const os::String &path, bool verbose)
+{
+    void *handle = dlopen(path.str(), RTLD_LAZY);
+    bool exists = (handle != NULL);
+    if (verbose) {
+        if (exists) {
+            std::cerr << "info: found " << path.str() << "\n";
+        } else {
+            std::cerr << "info: did not find " << dlerror() << "\n";
+        }
+    }
+    if (exists)
+        dlclose(handle);
+    return exists;
+}
+#endif
 
 static bool
 tryPath(const os::String &path, bool verbose)
@@ -93,6 +114,17 @@ findWrapper(const char *wrapperFilename, bool verbose)
         return wrapperPath;
     }
 
+#ifdef __GLIBC__
+    // We want to take advantage of $LIB dynamic string token expansion in
+    // glibc dynamic linker to handle multilib layout for us
+    wrapperPath = processDir;
+    wrapperPath.join("../$LIB/apitrace/wrappers");
+    wrapperPath.join(wrapperFilename);
+    if (tryLib(wrapperPath, verbose)) {
+        return wrapperPath;
+    }
+#endif
+
     // Try relative install directory
     wrapperPath = processDir;
 #if defined(_WIN32)



More information about the apitrace mailing list