initial work on relocations

This commit is contained in:
georgemoralis 2023-07-04 18:34:23 +03:00
parent bc2facaee4
commit 6717482662
3 changed files with 26 additions and 0 deletions

View File

@ -78,6 +78,7 @@ Module* Linker::LoadModule(const std::string& elf_name)
LoadModuleToMemory(m); LoadModuleToMemory(m);
LoadDynamicInfo(m); LoadDynamicInfo(m);
LoadSymbols(m); LoadSymbols(m);
Relocate(m);
} }
else else
{ {
@ -496,3 +497,24 @@ void Linker::LoadSymbols(Module* m)
} }
} }
} }
void Linker::Relocate(Module* m)
{
u32 idx = 0;
for (auto* rel = m->dynamic_info->relocation_table; reinterpret_cast<u08*>(rel) < reinterpret_cast<u08*>(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<u08*>(rel) < reinterpret_cast<u08*>(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);
}
}

View File

@ -110,6 +110,7 @@ public:
void LoadDynamicInfo(Module* m); void LoadDynamicInfo(Module* m);
void LoadSymbols(Module* m); void LoadSymbols(Module* m);
SymbolsResolver* getHLESymbols() { return m_HLEsymbols; } SymbolsResolver* getHLESymbols() { return m_HLEsymbols; }
void Relocate(Module* m);
private: private:
const ModuleInfo* FindModule(const Module& m, const std::string& id); const ModuleInfo* FindModule(const Module& m, const std::string& id);

View File

@ -435,6 +435,9 @@ struct elf_symbol
struct elf_relocation struct elf_relocation
{ {
u32 GetSymbol() const { return static_cast<u32>(rel_info >> 32u); }
u32 GetType() const { return static_cast<u32>(rel_info & 0xffffffff); }
u64 rel_offset; u64 rel_offset;
u64 rel_info; u64 rel_info;
s64 rel_addend; s64 rel_addend;