From 3f9c2ecf18d8fa37fad5a7062f80952692eaa8e7 Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Wed, 16 Oct 2013 20:51:47 +0400 Subject: [PATCH] cli: use $LIB to handle multilib automagically on glibc --- cli/cli_resources.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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 + +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) -- 2.43.0