Commit b75b97a2 by Geoff Lang Committed by Commit Bot

Support the SearchType argument for loading libraries with posix.

When a local shared library should be loaded, resolve its full path before calling dlopen. This logic matches SwiftShader's library loading. This is a speculative fix for Chrome being unable to load ANGLE libraries when they are distributed as part of a Chromium.app and have a different path than the executable. BUG=982294 Change-Id: Ib70096eac7460417ea7ea32941e2273dd368e6ac Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1724910 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarClemen Deng <clemendeng@google.com>
parent 2613cdba
......@@ -214,14 +214,22 @@ bool RunApp(const std::vector<const char *> &args,
class PosixLibrary : public Library
{
public:
PosixLibrary(const char *libraryName)
PosixLibrary(const char *libraryName, SearchType searchType)
{
char buffer[1000];
int ret = snprintf(buffer, 1000, "%s.%s", libraryName, GetSharedLibraryExtension());
if (ret > 0 && ret < 1000)
std::string directory;
if (searchType == SearchType::ApplicationDir)
{
mModule = dlopen(buffer, RTLD_NOW);
static int dummySymbol = 0;
Dl_info dlInfo;
if (dladdr(&dummySymbol, &dlInfo) != 0)
{
std::string moduleName = dlInfo.dli_fname;
directory = moduleName.substr(0, moduleName.find_last_of('/') + 1);
}
}
std::string fullPath = directory + libraryName + "." + GetSharedLibraryExtension();
mModule = dlopen(fullPath.c_str(), RTLD_NOW);
}
~PosixLibrary() override
......@@ -250,7 +258,7 @@ class PosixLibrary : public Library
Library *OpenSharedLibrary(const char *libraryName, SearchType searchType)
{
return new PosixLibrary(libraryName);
return new PosixLibrary(libraryName, searchType);
}
bool IsDirectory(const char *filename)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment