From 6717482662b16a4ecb5ce317c4b2ab9a54a3bee4 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 4 Jul 2023 18:34:23 +0300 Subject: [PATCH] initial work on relocations --- src/Core/PS4/Linker.cpp | 22 ++++++++++++++++++++++ src/Core/PS4/Linker.h | 1 + src/Core/PS4/Loader/Elf.h | 3 +++ 3 files changed, 26 insertions(+) diff --git a/src/Core/PS4/Linker.cpp b/src/Core/PS4/Linker.cpp index c0144d10..f3654a03 100644 --- a/src/Core/PS4/Linker.cpp +++ b/src/Core/PS4/Linker.cpp @@ -78,6 +78,7 @@ Module* Linker::LoadModule(const std::string& elf_name) LoadModuleToMemory(m); LoadDynamicInfo(m); LoadSymbols(m); + Relocate(m); } else { @@ -495,4 +496,25 @@ void Linker::LoadSymbols(Module* m) } } } +} +void Linker::Relocate(Module* m) +{ + u32 idx = 0; + for (auto* rel = m->dynamic_info->relocation_table; reinterpret_cast(rel) < reinterpret_cast(m->dynamic_info->relocation_table) + m->dynamic_info->relocation_table_size; rel++, idx++) + { + auto type = rel->GetType(); + auto symbol = rel->GetSymbol(); + auto addend = rel->rel_addend; + + LOG_INFO_IF(debug_loader, "rel type {:#010x} rel symbol : {:#010x}\n", type, symbol); + } + idx = 0; + for (auto* rel = m->dynamic_info->jmp_relocation_table; reinterpret_cast(rel) < reinterpret_cast(m->dynamic_info->jmp_relocation_table) + m->dynamic_info->jmp_relocation_table_size; rel++, idx++) + { + auto type = rel->GetType(); + auto symbol = rel->GetSymbol(); + auto addend = rel->rel_addend; + + LOG_INFO_IF(debug_loader, "jmprel type {:#010x} rel symbol : {:#010x}\n", type, symbol); + } } \ No newline at end of file diff --git a/src/Core/PS4/Linker.h b/src/Core/PS4/Linker.h index bc7ce63b..4763bdf6 100644 --- a/src/Core/PS4/Linker.h +++ b/src/Core/PS4/Linker.h @@ -110,6 +110,7 @@ public: void LoadDynamicInfo(Module* m); void LoadSymbols(Module* m); SymbolsResolver* getHLESymbols() { return m_HLEsymbols; } + void Relocate(Module* m); private: const ModuleInfo* FindModule(const Module& m, const std::string& id); diff --git a/src/Core/PS4/Loader/Elf.h b/src/Core/PS4/Loader/Elf.h index 58d096fe..565f6d06 100644 --- a/src/Core/PS4/Loader/Elf.h +++ b/src/Core/PS4/Loader/Elf.h @@ -435,6 +435,9 @@ struct elf_symbol struct elf_relocation { + u32 GetSymbol() const { return static_cast(rel_info >> 32u); } + u32 GetType() const { return static_cast(rel_info & 0xffffffff); } + u64 rel_offset; u64 rel_info; s64 rel_addend;