mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-23 18:45:36 +00:00
Handle exports resolve
This commit is contained in:
parent
ab04333ebd
commit
7dfdf4c259
@ -576,7 +576,28 @@ void Linker::Relocate(Module* m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool contains(const std::vector<T>& vecObj, const T& element) {
|
||||||
|
auto it = std::find(vecObj.begin(), vecObj.end(), element);
|
||||||
|
return it != vecObj.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
Module* Linker::FindModuleExp(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void Linker::Resolve(const std::string& name, int Symtype, Module* m, Loader::SymbolRecord* return_info) {
|
void Linker::Resolve(const std::string& name, int Symtype, Module* m, Loader::SymbolRecord* return_info) {
|
||||||
|
//std::scoped_lock lock{m_mutex};
|
||||||
const auto ids = Common::SplitString(name, '#');
|
const auto ids = Common::SplitString(name, '#');
|
||||||
if (ids.size() == 3) // symbols are 3 parts name , library , module
|
if (ids.size() == 3) // symbols are 3 parts name , library , module
|
||||||
{
|
{
|
||||||
@ -596,6 +617,12 @@ void Linker::Resolve(const std::string& name, int Symtype, Module* m, Loader::Sy
|
|||||||
const Loader::SymbolRecord* rec = nullptr;
|
const Loader::SymbolRecord* rec = nullptr;
|
||||||
rec = m_hle_symbols.FindSymbol(sr);
|
rec = m_hle_symbols.FindSymbol(sr);
|
||||||
|
|
||||||
|
if (rec == nullptr) {
|
||||||
|
if (auto* p = FindModuleExp(*module, *library); p != nullptr && p->export_sym.GetSize()>0) {
|
||||||
|
rec = p->export_sym.FindSymbol(sr);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
if (rec != nullptr) {
|
if (rec != nullptr) {
|
||||||
*return_info = *rec;
|
*return_info = *rec;
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,6 +17,11 @@ struct EntryParams {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ModuleInfo {
|
struct ModuleInfo {
|
||||||
|
|
||||||
|
bool operator==(const ModuleInfo& other) const {
|
||||||
|
return version_major == other.version_major && version_minor == other.version_minor && name == other.name;
|
||||||
|
}
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
union {
|
union {
|
||||||
u64 value;
|
u64 value;
|
||||||
@ -31,6 +36,9 @@ struct ModuleInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct LibraryInfo {
|
struct LibraryInfo {
|
||||||
|
|
||||||
|
bool operator==(const LibraryInfo& other) const { return version == other.version && name == other.name; }
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
union {
|
union {
|
||||||
u64 value;
|
u64 value;
|
||||||
@ -119,6 +127,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
const ModuleInfo* FindModule(const Module& m, const std::string& id);
|
const ModuleInfo* FindModule(const Module& m, const std::string& id);
|
||||||
const LibraryInfo* FindLibrary(const Module& program, const std::string& id);
|
const LibraryInfo* FindLibrary(const Module& program, const std::string& id);
|
||||||
|
Module* Linker::FindModuleExp(const ModuleInfo& m, const LibraryInfo& l);
|
||||||
|
|
||||||
std::vector<Module> m_modules;
|
std::vector<Module> m_modules;
|
||||||
Loader::SymbolsResolver m_hle_symbols{};
|
Loader::SymbolsResolver m_hle_symbols{};
|
||||||
|
@ -1,24 +1,26 @@
|
|||||||
|
#include "core/loader/symbols_resolver.h"
|
||||||
|
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/types.h"
|
#include "common/types.h"
|
||||||
#include "core/loader/symbols_resolver.h"
|
|
||||||
|
|
||||||
namespace Core::Loader {
|
namespace Core::Loader {
|
||||||
|
|
||||||
void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) {
|
void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) {
|
||||||
SymbolRecord r{};
|
SymbolRecord r{};
|
||||||
r.name = GenerateName(s);
|
r.name = GenerateName(s);
|
||||||
r.virtual_address = virtual_addr;
|
r.virtual_address = virtual_addr;
|
||||||
m_symbols.push_back(r);
|
m_symbols.push_back(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SymbolsResolver::GetSize() { return m_symbols.size(); }
|
||||||
|
|
||||||
std::string SymbolsResolver::GenerateName(const SymbolRes& s) {
|
std::string SymbolsResolver::GenerateName(const SymbolRes& s) {
|
||||||
return fmt::format("{} lib[{}_v{}]mod[{}_v{}.{}]",
|
return fmt::format("{} lib[{}_v{}]mod[{}_v{}.{}]", s.name, s.library, s.library_version, s.module, s.module_version_major,
|
||||||
s.name, s.library, s.library_version,
|
s.module_version_minor);
|
||||||
s.module, s.module_version_major, s.module_version_minor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const {
|
const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const {
|
||||||
const std::string name = GenerateName(s);
|
const std::string name = GenerateName(s);
|
||||||
for (u32 i = 0; i < m_symbols.size(); i++) {
|
for (u32 i = 0; i < m_symbols.size(); i++) {
|
||||||
if (m_symbols[i].name.compare(name) == 0) {
|
if (m_symbols[i].name.compare(name) == 0) {
|
||||||
return &m_symbols[i];
|
return &m_symbols[i];
|
||||||
@ -26,7 +28,7 @@ const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("Unresolved! {}\n", name);
|
LOG_INFO("Unresolved! {}\n", name);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Core::Loader
|
} // namespace Core::Loader
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
|
|
||||||
void AddSymbol(const SymbolRes& s, u64 virtual_addr);
|
void AddSymbol(const SymbolRes& s, u64 virtual_addr);
|
||||||
const SymbolRecord* FindSymbol(const SymbolRes& s) const;
|
const SymbolRecord* FindSymbol(const SymbolRes& s) const;
|
||||||
|
int GetSize();
|
||||||
static std::string GenerateName(const SymbolRes& s);
|
static std::string GenerateName(const SymbolRes& s);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user