Created
May 31, 2018 16:55
-
-
Save yamaguchi1024/77dca1045795d31e77c4a2a4ba4016d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/metacling/src/TCling.cxx b/core/metacling/src/TCling.cxx | |
index eee35d1365..2f6eaba68f 100644 | |
--- a/core/metacling/src/TCling.cxx | |
+++ b/core/metacling/src/TCling.cxx | |
@@ -5875,49 +5875,21 @@ static void* LazyFunctionCreatorAutoloadForModule(const std::string& mangled_nam | |
R__LOCKGUARD(gInterpreterMutex); | |
- static constexpr std::hash<std::string> hash_fn; | |
- // size_t is a hashed mangled_name and libs[(uint16_t)hashToLibNameIndex.second] = library's | |
- // name in string. | |
- static std::unordered_map<size_t, uint16_t> hashToLibNameIndex; | |
- // vector of library which are in table, with full path | |
- static std::vector<std::string> LoadableLibs; | |
- | |
- // If library information was already loaded to the table, just search and return that. | |
- auto iter = hashToLibNameIndex.find(hash_fn(mangled_name)); | |
- if (iter != hashToLibNameIndex.end()) { | |
- std::string LoadedLibName = LoadableLibs[iter->second]; | |
- if (!LoadedLibName.empty() && (gSystem->Load(LoadedLibName.c_str(), "", false) < 0)) | |
- Error("LazyFunctionCreatorAutoloadForModule", "Failed to load library %s", LoadedLibName.c_str()); | |
- void* addr = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(mangled_name.c_str()); | |
- return addr; | |
- } | |
- | |
static const clang::Preprocessor &PP = fInterpreter->getCI()->getPreprocessor(); | |
static const HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); | |
static const auto ModulePaths(HSOpts.PrebuiltModulePaths); | |
static cling::DynamicLibraryManager* dyLibManager = fInterpreter->getDynamicLibraryManager(); | |
- // Store the information of path so that we don't have to iterate over the same path again and again. | |
- static std::unordered_set<std::string> AlreadyLookedPath; | |
- // This is different from LoadableLibs. AlreadyLookedLibraries contains filename like "libfoo.so", so that | |
- // we can avoid the same library in different path loaded twice. | |
- static std::unordered_set<std::string> AlreadyLookedLibraries; | |
- static int cur_lib = 0; | |
- | |
// Take path here eg. "/home/foo/module-release/lib/" | |
for (auto Path : ModulePaths) { | |
// Already searched? | |
- if (AlreadyLookedPath.find(Path) != AlreadyLookedPath.end()) | |
- continue; | |
- | |
StringRef DirPath(Path); | |
if (!is_directory(DirPath)) { | |
- AlreadyLookedPath.insert(Path); | |
continue; | |
} | |
// We don't want to do directory_iterator several times because it contains HDD access | |
- std::vector<std::string> Libraries; | |
+ std::vector<void *> Libraries; | |
// Check this not a random system directory (should contain pcm) | |
std::error_code EC; | |
@@ -5929,52 +5901,19 @@ static void* LazyFunctionCreatorAutoloadForModule(const std::string& mangled_nam | |
dirHasPCM = true; | |
if (!llvm::sys::fs::is_directory(FileName) && extension(FileName) == ".so") | |
- Libraries.push_back(FileName); | |
+ Libraries.push_back(dlopen(FileName.c_str(), RTLD_LAZY)); | |
} | |
if (!dirHasPCM) { | |
- AlreadyLookedPath.insert(Path); | |
continue; | |
} | |
- std::string lib_found = ""; | |
- | |
// Iterate over files under this path. We want to get each ".so" files | |
- for (std::string LibName : Libraries) { | |
- // Is it already searched? | |
- if (AlreadyLookedLibraries.find(filename(LibName)) != AlreadyLookedLibraries.end()) | |
- continue; | |
- | |
- AlreadyLookedLibraries.insert(filename(LibName)); | |
- | |
- // TCling::IsLoaded is incredibly slow! | |
- if (dyLibManager->isLibraryLoaded(LibName.c_str())) | |
- continue; | |
- | |
- LoadableLibs.push_back(LibName); | |
- auto SoFile = ObjectFile::createObjectFile(LibName); | |
- if (SoFile) { | |
- auto RealSoFile = SoFile.get().getBinary(); | |
- auto Symbols = RealSoFile->symbols(); | |
- for (auto S : Symbols) { | |
- // DO NOT insert to table if symbol was weak or undefined | |
- if (S.getFlags() == SymbolRef::SF_Weak || S.getFlags() == SymbolRef::SF_Undefined) continue; | |
- | |
- // Put into map | |
- hashToLibNameIndex.insert(std::make_pair(hash_fn(S.getName().get()), cur_lib)); | |
- if (S.getName().get() == mangled_name) | |
- lib_found = LibName; | |
- } | |
- } | |
- cur_lib++; | |
- if (!lib_found.empty()) { | |
- if (gSystem->Load(lib_found.c_str(), "", false) < 0) | |
- Error("LazyFunctionCreatorAutoloadForModule", "Failed to load library %s", lib_found.c_str()); | |
- void* addr = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(mangled_name.c_str()); | |
- return addr; | |
- } | |
+ for (void* pointer : Libraries) { | |
+ void* dl = dlsym(pointer, mangled_name.c_str()); | |
+ if (dl) | |
+ return dl; | |
} | |
- AlreadyLookedPath.insert(Path); | |
} | |
// This means there is not library containing this mangled_name! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment