Link dynamically sized exports correctly as well.

This commit is contained in:
Unknown W. Brackets 2013-05-20 23:39:43 -07:00
parent ed698692f7
commit 5fe38f525d

View file

@ -422,8 +422,8 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
u32 firstSymAddr; u32 firstSymAddr;
}; };
// Might be off, only used for logging.
int numModules = (modinfo->libstubend - modinfo->libstub)/sizeof(PspLibStubEntry); int numModules = (modinfo->libstubend - modinfo->libstub)/sizeof(PspLibStubEntry);
DEBUG_LOG(LOADER,"Num Modules: %i",numModules); DEBUG_LOG(LOADER,"Num Modules: %i",numModules);
DEBUG_LOG(LOADER,"==================================================="); DEBUG_LOG(LOADER,"===================================================");
@ -432,9 +432,8 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
bool needReport = false; bool needReport = false;
int numSyms = 0; int numSyms = 0;
//for (int m = 0; m < numModules; m++) {
while (entryPos < entryEnd) { while (entryPos < entryEnd) {
PspLibStubEntry *entry = (PspLibStubEntry *) entryPos; PspLibStubEntry *entry = (PspLibStubEntry *)entryPos;
entryPos += entry->size; entryPos += entry->size;
const char *modulename; const char *modulename;
@ -459,6 +458,7 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
WARN_LOG_REPORT(LOADER, "Unexpected module entry size %d, extra = %08x", entry->size, *(entryPos - 1)); WARN_LOG_REPORT(LOADER, "Unexpected module entry size %d, extra = %08x", entry->size, *(entryPos - 1));
} else { } else {
WARN_LOG_REPORT(LOADER, "Unexpected module entry size %d", entry->size); WARN_LOG_REPORT(LOADER, "Unexpected module entry size %d", entry->size);
needReport = true;
} }
} }
@ -482,8 +482,9 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
if (needReport) { if (needReport) {
std::string debugInfo; std::string debugInfo;
entryPos = (u32 *)Memory::GetPointer(modinfo->libstub);
while (entryPos < entryEnd) { while (entryPos < entryEnd) {
PspLibStubEntry *entry = (PspLibStubEntry *) entryPos; PspLibStubEntry *entry = (PspLibStubEntry *)entryPos;
entryPos += entry->size; entryPos += entry->size;
char temp[512]; char temp[512];
@ -497,6 +498,7 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
snprintf(temp, sizeof(temp), "%s ver=%04x, flags=%04x, size=%d, numFuncs=%d, nidData=%08x, firstSym=%08x\n", snprintf(temp, sizeof(temp), "%s ver=%04x, flags=%04x, size=%d, numFuncs=%d, nidData=%08x, firstSym=%08x\n",
modulename, entry->version, entry->flags, entry->size, entry->numFuncs, entry->nidData, entry->firstSymAddr); modulename, entry->version, entry->flags, entry->size, entry->numFuncs, entry->nidData, entry->firstSymAddr);
debugInfo += temp; debugInfo += temp;
NOTICE_LOG(LOADER, "%s", temp);
} }
Reporting::ReportMessage("Module linking debug info:\n%s", debugInfo.c_str()); Reporting::ReportMessage("Module linking debug info:\n%s", debugInfo.c_str());
@ -515,14 +517,19 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
u32 resident; u32 resident;
}; };
int numEnts = (modinfo->libentend - modinfo->libent)/sizeof(PspLibEntEntry); u32 *entPos = (u32 *)Memory::GetPointer(modinfo->libent);
PspLibEntEntry *ent = (PspLibEntEntry *)Memory::GetPointer(modinfo->libent); u32 *entEnd = (u32 *)Memory::GetPointer(modinfo->libentend);
for (int m=0; m<numEnts; m++) for (int m = 0; entPos < entEnd; ++m)
{ {
const char *name; PspLibEntEntry *ent = (PspLibEntEntry *)entPos;
if (ent->size == 0) if (ent->size == 0) {
entPos += 4;
continue; continue;
} else {
entPos += ent->size;
}
const char *name;
if (ent->name == 0) { if (ent->name == 0) {
// ? // ?
name = module->nm.name; name = module->nm.name;
@ -602,20 +609,12 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
DEBUG_LOG(LOADER, "Module SDK: %08x", Memory::Read_U32(exportAddr)); DEBUG_LOG(LOADER, "Module SDK: %08x", Memory::Read_U32(exportAddr));
break; break;
default: default:
// TODO: Do these need to be resolved or anything also?
DEBUG_LOG(LOADER, "Unexpected variable with nid: %08x", nid); DEBUG_LOG(LOADER, "Unexpected variable with nid: %08x", nid);
break; break;
} }
} }
} }
if (ent->size > 4)
{
ent = (PspLibEntEntry*)((u8*)ent + ent->size * 4);
}
else
{
ent++;
}
} }
module->nm.entry_addr = reader.GetEntryPoint(); module->nm.entry_addr = reader.GetEntryPoint();