Initial symbol loading

This commit is contained in:
georgemoralis 2023-06-13 07:43:58 +03:00
parent d0931704ff
commit cfa68f2f40
3 changed files with 29 additions and 1 deletions

View File

@ -48,6 +48,7 @@ Module* Linker::LoadModule(const std::string& elf_name)
{
LoadModuleToMemory(m);
LoadDynamicInfo(m);
LoadSymbols(m);
}
else
{
@ -310,9 +311,33 @@ void Linker::LoadDynamicInfo(Module* m)
//TODO?
LOG_INFO_IF(debug_loader, "unsupported DT_SCE_MODULE_ATTR value = ..........: {:#018x}\n", dyn->d_un.d_val);
break;
case DT_SCE_EXPORT_LIB:
{
LibraryInfo info{};
info.value = dyn->d_un.d_val;
info.name = m->dynamic_info->str_table + info.name_offset;
m->dynamic_info->export_libs.push_back(info);
}
break;
default:
LOG_INFO_IF(debug_loader, "unsupported dynamic tag ..........: {:#018x}\n", dyn->d_tag);
}
}
}
void Linker::LoadSymbols(Module* m)
{
if (m->dynamic_info->symbol_table == nullptr || m->dynamic_info->str_table == nullptr || m->dynamic_info->symbol_table_total_size==0)
{
LOG_INFO_IF(debug_loader, "Symbol table not found!\n");
return;
}
for (auto* sym = m->dynamic_info->symbol_table;
reinterpret_cast<uint8_t*>(sym) < reinterpret_cast<uint8_t*>(m->dynamic_info->symbol_table) + m->dynamic_info->symbol_table_total_size;
sym++)
{
std::string id = std::string(m->dynamic_info->str_table + sym->st_name);
LOG_INFO_IF(debug_loader, "symbol {}\n", id.c_str());
}
}

View File

@ -85,6 +85,7 @@ struct DynamicModuleInfo
std::vector<ModuleInfo> import_modules;
std::vector<ModuleInfo> export_modules;
std::vector<LibraryInfo> import_libs;
std::vector<LibraryInfo> export_libs;
std::string filename;//filename with absolute path
@ -99,7 +100,8 @@ public:
Module* LoadModule(const std::string& elf_name);
Module* FindModule(/*u32 id*/);
void LoadModuleToMemory(Module* m);
void LoadDynamicInfo(Module* program);
void LoadDynamicInfo(Module* m);
void LoadSymbols(Module* m);
private:
std::vector<Module*> m_modules;

View File

@ -343,6 +343,7 @@ constexpr s64 DT_SCE_ORIGINAL_FILENAME = 0x61000009;
constexpr s64 DT_SCE_MODULE_INFO = 0x6100000d;
constexpr s64 DT_SCE_NEEDED_MODULE = 0x6100000f;
constexpr s64 DT_SCE_MODULE_ATTR = 0x61000011;
constexpr s64 DT_SCE_EXPORT_LIB = 0x61000013;
constexpr s64 DT_SCE_IMPORT_LIB = 0x61000015;
constexpr s64 DT_SCE_IMPORT_LIB_ATTR = 0x61000019;
constexpr s64 DT_SCE_HASH = 0x61000025;