mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-20 11:35:45 +00:00
some improvements on symbols types
This commit is contained in:
parent
bf69754b5e
commit
eb306fccfa
4 changed files with 38 additions and 17 deletions
|
@ -434,7 +434,7 @@ void Linker::LoadSymbols(Module* m) {
|
|||
nidName = "UNK";
|
||||
}
|
||||
|
||||
Loader::SymbolRes sym_r{};
|
||||
Loader::SymbolResolver sym_r{};
|
||||
sym_r.name = ids.at(0);
|
||||
sym_r.nidName = nidName;
|
||||
sym_r.library = library->name;
|
||||
|
@ -442,8 +442,21 @@ void Linker::LoadSymbols(Module* m) {
|
|||
sym_r.module = module->name;
|
||||
sym_r.module_version_major = module->version_major;
|
||||
sym_r.module_version_minor = module->version_minor;
|
||||
sym_r.type = type;
|
||||
|
||||
switch (type) {
|
||||
case STT_NOTYPE:
|
||||
sym_r.type = Loader::SymbolType::NoType;
|
||||
break;
|
||||
case STT_FUN:
|
||||
sym_r.type = Loader::SymbolType::Function;
|
||||
break;
|
||||
case STT_OBJECT:
|
||||
sym_r.type = Loader::SymbolType::Object;
|
||||
break;
|
||||
default:
|
||||
sym_r.type = Loader::SymbolType::Unknown;
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_sym_export) {
|
||||
m->export_sym.AddSymbol(sym_r, sym->st_value + m->base_virtual_addr);
|
||||
} else {
|
||||
|
@ -471,7 +484,7 @@ void Linker::Relocate(Module* m) {
|
|||
u64 rel_base_virtual_addr = m->base_virtual_addr;
|
||||
u64 rel_virtual_addr = m->base_virtual_addr + rel->rel_offset;
|
||||
bool rel_isResolved = false;
|
||||
u8 rel_sym_type = 0;
|
||||
Loader::SymbolType rel_sym_type = Loader::SymbolType::Unknown;
|
||||
std::string rel_name;
|
||||
|
||||
switch (type) {
|
||||
|
@ -495,10 +508,10 @@ void Linker::Relocate(Module* m) {
|
|||
Loader::SymbolRecord symrec{};
|
||||
switch (sym_type) {
|
||||
case STT_FUN:
|
||||
rel_sym_type = 2;
|
||||
rel_sym_type = Loader::SymbolType::Function;
|
||||
break;
|
||||
case STT_OBJECT:
|
||||
rel_sym_type = 1;
|
||||
rel_sym_type = Loader::SymbolType::Object;
|
||||
break;
|
||||
default:
|
||||
LOG_INFO(Core_Linker, "unknown symbol type {}", sym_type);
|
||||
|
@ -558,7 +571,7 @@ void Linker::Relocate(Module* m) {
|
|||
}
|
||||
}
|
||||
|
||||
void Linker::Resolve(const std::string& name, int Symtype, Module* m,
|
||||
void Linker::Resolve(const std::string& name, Loader::SymbolType Symtype, Module* m,
|
||||
Loader::SymbolRecord* return_info) {
|
||||
const auto ids = Common::SplitString(name, '#');
|
||||
if (ids.size() == 3) // symbols are 3 parts name , library , module
|
||||
|
@ -567,7 +580,7 @@ void Linker::Resolve(const std::string& name, int Symtype, Module* m,
|
|||
const auto* module = FindModule(*m, ids.at(2));
|
||||
|
||||
if (library != nullptr && module != nullptr) {
|
||||
Loader::SymbolRes sr{};
|
||||
Loader::SymbolResolver sr{};
|
||||
sr.name = ids.at(0);
|
||||
sr.library = library->name;
|
||||
sr.library_version = library->version;
|
||||
|
|
|
@ -124,7 +124,7 @@ public:
|
|||
return m_hle_symbols;
|
||||
}
|
||||
void Relocate(Module* m);
|
||||
void Resolve(const std::string& name, int Symtype, Module* m,
|
||||
void Resolve(const std::string& name, Loader::SymbolType Symtype, Module* m,
|
||||
Loader::SymbolRecord* return_info);
|
||||
void Execute();
|
||||
|
||||
|
|
|
@ -7,19 +7,19 @@
|
|||
|
||||
namespace Core::Loader {
|
||||
|
||||
void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) {
|
||||
void SymbolsResolver::AddSymbol(const SymbolResolver& s, u64 virtual_addr) {
|
||||
SymbolRecord r{};
|
||||
r.name = GenerateName(s);
|
||||
r.virtual_address = virtual_addr;
|
||||
m_symbols.push_back(r);
|
||||
}
|
||||
|
||||
std::string SymbolsResolver::GenerateName(const SymbolRes& s) {
|
||||
std::string SymbolsResolver::GenerateName(const SymbolResolver& s) {
|
||||
return fmt::format("{} lib[{}_v{}]mod[{}_v{}.{}]", s.name, s.library, s.library_version,
|
||||
s.module, s.module_version_major, s.module_version_minor);
|
||||
}
|
||||
|
||||
const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const {
|
||||
const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolResolver& s) const {
|
||||
const std::string name = GenerateName(s);
|
||||
for (u32 i = 0; i < m_symbols.size(); i++) {
|
||||
if (m_symbols[i].name.compare(name) == 0) {
|
||||
|
|
|
@ -10,12 +10,20 @@
|
|||
|
||||
namespace Core::Loader {
|
||||
|
||||
enum class SymbolType {
|
||||
Unknown,
|
||||
Function,
|
||||
Object,
|
||||
Tls,
|
||||
NoType,
|
||||
};
|
||||
|
||||
struct SymbolRecord {
|
||||
std::string name;
|
||||
u64 virtual_address;
|
||||
};
|
||||
|
||||
struct SymbolRes {
|
||||
struct SymbolResolver {
|
||||
std::string name;
|
||||
std::string nidName;
|
||||
std::string library;
|
||||
|
@ -23,7 +31,7 @@ struct SymbolRes {
|
|||
std::string module;
|
||||
u8 module_version_major;
|
||||
u8 module_version_minor;
|
||||
u32 type;
|
||||
SymbolType type;
|
||||
};
|
||||
|
||||
class SymbolsResolver {
|
||||
|
@ -31,10 +39,10 @@ public:
|
|||
SymbolsResolver() = default;
|
||||
virtual ~SymbolsResolver() = default;
|
||||
|
||||
void AddSymbol(const SymbolRes& s, u64 virtual_addr);
|
||||
const SymbolRecord* FindSymbol(const SymbolRes& s) const;
|
||||
void AddSymbol(const SymbolResolver& s, u64 virtual_addr);
|
||||
const SymbolRecord* FindSymbol(const SymbolResolver& s) const;
|
||||
|
||||
static std::string GenerateName(const SymbolRes& s);
|
||||
static std::string GenerateName(const SymbolResolver& s);
|
||||
|
||||
private:
|
||||
std::vector<SymbolRecord> m_symbols;
|
||||
|
|
Loading…
Add table
Reference in a new issue