mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-29 06:46:22 -05:00
Implement simple LoadSymbols for ELF files
This commit is contained in:
parent
d046cfbba1
commit
67095f8083
1 changed files with 12 additions and 62 deletions
|
@ -6,13 +6,10 @@
|
||||||
|
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
|
|
||||||
|
#include "common/symbols.h"
|
||||||
#include "core/mem_map.h"
|
#include "core/mem_map.h"
|
||||||
#include "core/elf/elf_reader.h"
|
#include "core/elf/elf_reader.h"
|
||||||
|
|
||||||
//#include "Core/Debugger/Debugger_SymbolMap.h"
|
|
||||||
//#include "Core/HW/Memmap.h"
|
|
||||||
//#include "Core/PowerPC/PPCSymbolDB.h"
|
|
||||||
|
|
||||||
//void bswap(Elf32_Word &w) {w = Common::swap32(w);}
|
//void bswap(Elf32_Word &w) {w = Common::swap32(w);}
|
||||||
//void bswap(Elf32_Half &w) {w = Common::swap16(w);}
|
//void bswap(Elf32_Half &w) {w = Common::swap16(w);}
|
||||||
|
|
||||||
|
@ -71,16 +68,9 @@ ElfReader::ElfReader(void *ptr)
|
||||||
segments = (Elf32_Phdr *)(base + header->e_phoff);
|
segments = (Elf32_Phdr *)(base + header->e_phoff);
|
||||||
sections = (Elf32_Shdr *)(base + header->e_shoff);
|
sections = (Elf32_Shdr *)(base + header->e_shoff);
|
||||||
|
|
||||||
//for (int i = 0; i < GetNumSegments(); i++)
|
|
||||||
//{
|
|
||||||
// byteswapSegment(segments[i]);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//for (int i = 0; i < GetNumSections(); i++)
|
|
||||||
//{
|
|
||||||
// byteswapSection(sections[i]);
|
|
||||||
//}
|
|
||||||
entryPoint = header->e_entry;
|
entryPoint = header->e_entry;
|
||||||
|
|
||||||
|
LoadSymbols();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *ElfReader::GetSectionName(int section) const
|
const char *ElfReader::GetSectionName(int section) const
|
||||||
|
@ -101,9 +91,6 @@ bool ElfReader::LoadInto(u32 vaddr)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(MASTER_LOG,"String section: %i", header->e_shstrndx);
|
DEBUG_LOG(MASTER_LOG,"String section: %i", header->e_shstrndx);
|
||||||
|
|
||||||
// sectionOffsets = new u32[GetNumSections()];
|
|
||||||
// sectionAddrs = new u32[GetNumSections()];
|
|
||||||
|
|
||||||
// Should we relocate?
|
// Should we relocate?
|
||||||
bRelocate = (header->e_type != ET_EXEC);
|
bRelocate = (header->e_type != ET_EXEC);
|
||||||
|
|
||||||
|
@ -153,29 +140,7 @@ bool ElfReader::LoadInto(u32 vaddr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
LOG(MASTER_LOG,"%i sections:", header->e_shnum);
|
|
||||||
|
|
||||||
for (int i=0; i<GetNumSections(); i++)
|
|
||||||
{
|
|
||||||
Elf32_Shdr *s = §ions[i];
|
|
||||||
const char *name = GetSectionName(i);
|
|
||||||
|
|
||||||
u32 writeAddr = s->sh_addr + baseAddress;
|
|
||||||
sectionOffsets[i] = writeAddr - vaddr;
|
|
||||||
sectionAddrs[i] = writeAddr;
|
|
||||||
|
|
||||||
if (s->sh_flags & SHF_ALLOC)
|
|
||||||
{
|
|
||||||
LOG(MASTER_LOG,"Data Section found: %s Sitting at %08x, size %08x", name, writeAddr, s->sh_size);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG(MASTER_LOG,"NonData Section found: %s Ignoring (size=%08x) (flags=%08x)", name, s->sh_size, s->sh_flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
INFO_LOG(MASTER_LOG,"Done loading.");
|
INFO_LOG(MASTER_LOG,"Done loading.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -192,8 +157,6 @@ SectionID ElfReader::GetSectionByName(const char *name, int firstSection) const
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO(bunnei): The following is verbatim from Dolphin - needs to be updated for this project:
|
|
||||||
|
|
||||||
bool ElfReader::LoadSymbols()
|
bool ElfReader::LoadSymbols()
|
||||||
{
|
{
|
||||||
bool hasSymbols = false;
|
bool hasSymbols = false;
|
||||||
|
@ -208,33 +171,20 @@ bool ElfReader::LoadSymbols()
|
||||||
int numSymbols = sections[sec].sh_size / sizeof(Elf32_Sym);
|
int numSymbols = sections[sec].sh_size / sizeof(Elf32_Sym);
|
||||||
for (int sym = 0; sym < numSymbols; sym++)
|
for (int sym = 0; sym < numSymbols; sym++)
|
||||||
{
|
{
|
||||||
int size = Common::swap32(symtab[sym].st_size);
|
int size = symtab[sym].st_size;
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// int bind = symtab[sym].st_info >> 4;
|
// int bind = symtab[sym].st_info >> 4;
|
||||||
int type = symtab[sym].st_info & 0xF;
|
int type = symtab[sym].st_info & 0xF;
|
||||||
int sectionIndex = Common::swap16(symtab[sym].st_shndx);
|
|
||||||
int value = Common::swap32(symtab[sym].st_value);
|
|
||||||
const char *name = stringBase + Common::swap32(symtab[sym].st_name);
|
|
||||||
if (bRelocate)
|
|
||||||
value += sectionAddrs[sectionIndex];
|
|
||||||
|
|
||||||
int symtype = Symbol::SYMBOL_DATA;
|
const char *name = stringBase + symtab[sym].st_name;
|
||||||
switch (type)
|
|
||||||
{
|
Symbols::Add(symtab[sym].st_value, name, size, type);
|
||||||
case STT_OBJECT:
|
|
||||||
symtype = Symbol::SYMBOL_DATA; break;
|
|
||||||
case STT_FUNC:
|
|
||||||
symtype = Symbol::SYMBOL_FUNCTION; break;
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
g_symbolDB.AddKnownSymbol(value, size, name, symtype);
|
|
||||||
hasSymbols = true;
|
hasSymbols = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_symbolDB.Index();
|
|
||||||
return hasSymbols;
|
return hasSymbols;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
Loading…
Reference in a new issue