linker: Eliminate orphan news

* Most of these can just be on the stack, with the rest being std::vectors
This commit is contained in:
GPUCode 2023-10-26 23:07:15 +03:00
parent ca564b928c
commit 7cbe7c762a
2 changed files with 175 additions and 194 deletions

View file

@ -14,23 +14,6 @@ struct EntryParams {
const char* argv[3];
};
// This struct keeps neccesary info about loaded modules. Main executeable is included too as well
struct Module
{
Elf elf;
u64 aligned_base_size = 0;
u64 base_virtual_addr = 0; // Base virtual address
Linker* linker = nullptr;
void* m_dynamic = nullptr;
void* m_dynamic_data = nullptr;
DynamicModuleInfo* dynamic_info = nullptr;
SymbolsResolver* export_sym = nullptr;
SymbolsResolver* import_sym = nullptr;
};
struct ModuleInfo
{
std::string name;
@ -66,50 +49,65 @@ struct LibraryInfo
struct DynamicModuleInfo
{
void* hash_table = nullptr;
u64 hash_table_size = 0;
void* hash_table = nullptr;
u64 hash_table_size = 0;
char* str_table = nullptr;
u64 str_table_size = 0;
char* str_table = nullptr;
u64 str_table_size = 0;
elf_symbol* symbol_table = nullptr;
u64 symbol_table_total_size = 0;
u64 symbol_table_entries_size = 0;
elf_symbol* symbol_table = nullptr;
u64 symbol_table_total_size = 0;
u64 symbol_table_entries_size = 0;
u64 init_virtual_addr = 0;
u64 fini_virtual_addr = 0;
u64 pltgot_virtual_addr = 0;
u64 init_array_virtual_addr = 0;
u64 fini_array_virtual_addr = 0;
u64 preinit_array_virtual_addr = 0;
u64 init_array_size = 0;
u64 fini_array_size = 0;
u64 preinit_array_size = 0;
u64 init_virtual_addr = 0;
u64 fini_virtual_addr = 0;
u64 pltgot_virtual_addr = 0;
u64 init_array_virtual_addr = 0;
u64 fini_array_virtual_addr = 0;
u64 preinit_array_virtual_addr = 0;
u64 init_array_size = 0;
u64 fini_array_size = 0;
u64 preinit_array_size = 0;
elf_relocation* jmp_relocation_table = nullptr;
u64 jmp_relocation_table_size = 0;
s64 jmp_relocation_type = 0;
elf_relocation* jmp_relocation_table = nullptr;
u64 jmp_relocation_table_size = 0;
s64 jmp_relocation_type = 0;
elf_relocation* relocation_table = nullptr;
u64 relocation_table_size = 0;
u64 relocation_table_entries_size = 0;
elf_relocation* relocation_table = nullptr;
u64 relocation_table_size = 0;
u64 relocation_table_entries_size = 0;
u64 debug = 0;
u64 textrel = 0;
u64 flags = 0;
u64 debug = 0;
u64 textrel = 0;
u64 flags = 0;
std::vector<const char*> needed;
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
std::vector<const char*> needed;
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
};
class Linker
// This struct keeps neccesary info about loaded modules. Main executeable is included too as well
struct Module
{
Elf elf;
u64 aligned_base_size = 0;
u64 base_virtual_addr = 0; // Base virtual address
Linker* linker = nullptr;
std::vector<u08> m_dynamic;
std::vector<u08> m_dynamic_data;
DynamicModuleInfo dynamic_info{};
SymbolsResolver export_sym;
SymbolsResolver import_sym;
};
class Linker {
public:
Linker();
virtual ~Linker();
@ -119,16 +117,16 @@ public:
void LoadModuleToMemory(Module* m);
void LoadDynamicInfo(Module* m);
void LoadSymbols(Module* m);
SymbolsResolver* getHLESymbols() { return m_HLEsymbols; }
SymbolsResolver& getHLESymbols() { return m_hle_symbols; }
void Relocate(Module* m);
void Resolve(const std::string& name, int Symtype, Module* m, SymbolRecord* return_info);
void Execute();
private:
private:
const ModuleInfo* FindModule(const Module& m, const std::string& id);
const LibraryInfo* FindLibrary(const Module& program, const std::string& id);
std::vector<Module*> m_modules;
SymbolsResolver* m_HLEsymbols = nullptr;
std::vector<Module> m_modules;
SymbolsResolver m_hle_symbols{};
std::mutex m_mutex;
};