diff --git a/src/core/linker.cpp b/src/core/linker.cpp index b12dd450..f4d90679 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -575,8 +575,29 @@ void Linker::Relocate(Module* m) { } } -void Linker::Resolve(const std::string& name, Loader::SymbolType Symtype, Module* m, +template +bool contains(const std::vector& vecObj, const T& element) { + auto it = std::find(vecObj.begin(), vecObj.end(), element); + return it != vecObj.end(); +} + +Module* Linker::FindExportedModule(const ModuleInfo& module, const LibraryInfo& library) { + // std::scoped_lock lock{m_mutex}; + + for (auto& m : m_modules) { + const auto& export_libs = m->dynamic_info.export_libs; + const auto& export_modules = m->dynamic_info.export_modules; + + if (contains(export_libs, library) && contains(export_modules, module)) { + return m.get(); + } + } + return nullptr; +} + +void Linker::Resolve(const std::string& name, Loader::SymbolType sym_type, Module* m, Loader::SymbolRecord* return_info) { + // std::scoped_lock lock{m_mutex}; const auto ids = Common::SplitString(name, '#'); ASSERT_MSG(ids.size() == 3, "Symbols must be 3 parts name, library, module"); @@ -591,11 +612,18 @@ void Linker::Resolve(const std::string& name, Loader::SymbolType Symtype, Module sr.module = module->name; sr.module_version_major = module->version_major; sr.module_version_minor = module->version_minor; - sr.type = Symtype; + sr.type = sym_type; const Loader::SymbolRecord* rec = nullptr; - rec = m_hle_symbols.FindSymbol(sr); + rec = m_hle_symbols.FindSymbol(sr); + if (rec == nullptr) { + // check if it an export function + if (auto* p = FindExportedModule(*module, *library); + p != nullptr && p->export_sym.GetSize() > 0) { + rec = p->export_sym.FindSymbol(sr); + } + } if (rec != nullptr) { *return_info = *rec; } else { diff --git a/src/core/linker.h b/src/core/linker.h index d9833852..be637f31 100644 --- a/src/core/linker.h +++ b/src/core/linker.h @@ -141,6 +141,7 @@ public: private: const ModuleInfo* FindModule(const Module& m, const std::string& id); const LibraryInfo* FindLibrary(const Module& program, const std::string& id); + Module* FindExportedModule(const ModuleInfo& m, const LibraryInfo& l); std::vector> m_modules; Loader::SymbolsResolver m_hle_symbols{}; diff --git a/src/core/loader/symbols_resolver.cpp b/src/core/loader/symbols_resolver.cpp index bc1aca07..4887f978 100644 --- a/src/core/loader/symbols_resolver.cpp +++ b/src/core/loader/symbols_resolver.cpp @@ -52,4 +52,8 @@ void SymbolsResolver::DebugDump(const std::filesystem::path& file_name) { } } +int SymbolsResolver::GetSize() { + return m_symbols.size(); +} + } // namespace Core::Loader diff --git a/src/core/loader/symbols_resolver.h b/src/core/loader/symbols_resolver.h index 09428daf..e02e9e8b 100644 --- a/src/core/loader/symbols_resolver.h +++ b/src/core/loader/symbols_resolver.h @@ -60,6 +60,7 @@ public: } void DebugDump(const std::filesystem::path& file_name); + int GetSize(); private: std::vector m_symbols;