Add logging of more relocation errors.

This commit is contained in:
Unknown W. Brackets 2013-06-01 09:29:38 -07:00
parent a42f80ed55
commit cc647ed910
3 changed files with 47 additions and 44 deletions

View File

@ -15,7 +15,8 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "../MemMap.h"
#include "Core/MemMap.h"
#include "Core/Reporting.h"
#include "../MIPS/MIPSTables.h"
#include "ElfReader.h"
#include "../Debugger/SymbolMap.h"
@ -46,7 +47,7 @@ void addrToHiLo(u32 addr, u16 &hi, s16 &lo)
u32 test = (hi<<16) + lo;
if (test != addr)
{
WARN_LOG_REPORT(LOADER, "HI16/LO16 relocation failure?");
}
}
@ -77,28 +78,23 @@ void ElfReader::LoadRelocations(Elf32_Rel *rels, int numRelocs)
}
u32 relocateTo = segmentVAddr[relative];
#define R_MIPS32 2
#define R_MIPS26 4
#define R_MIPS16_HI 5
#define R_MIPS16_LO 6
switch (type)
{
case R_MIPS32:
case R_MIPS_32:
if (log)
DEBUG_LOG(LOADER,"Full address reloc %08x", addr);
//full address, no problemo
op += relocateTo;
break;
case R_MIPS26: //j, jal
case R_MIPS_26: //j, jal
//add on to put in correct address space
if (log)
DEBUG_LOG(LOADER,"j/jal reloc %08x", addr);
op = (op & 0xFC000000) | (((op&0x03FFFFFF)+(relocateTo>>2))&0x03FFFFFFF);
break;
case R_MIPS16_HI: //lui part of lui-addiu pairs
case R_MIPS_HI16: //lui part of lui-addiu pairs
{
if (log)
DEBUG_LOG(LOADER,"HI reloc %08x", addr);
@ -108,7 +104,7 @@ void ElfReader::LoadRelocations(Elf32_Rel *rels, int numRelocs)
bool found = false;
for (int t = r + 1; t<numRelocs; t++)
{
if ((rels[t].r_info & 0xF) == R_MIPS16_LO)
if ((rels[t].r_info & 0xF) == R_MIPS_LO16)
{
u32 corrLoAddr = rels[t].r_offset + segmentVAddr[readwrite];
if (log)
@ -125,13 +121,13 @@ void ElfReader::LoadRelocations(Elf32_Rel *rels, int numRelocs)
}
}
if (!found)
ERROR_LOG(LOADER, "R_MIPS16: not found");
ERROR_LOG_REPORT(LOADER, "R_MIPS_HI16: could not find R_MIPS_LO16");
op = (op & 0xFFFF0000) | (hi);
}
break;
case R_MIPS16_LO: //addiu part of lui-addiu pairs
case R_MIPS_LO16: //addiu part of lui-addiu pairs
{
if (log)
DEBUG_LOG(LOADER,"LO reloc %08x", addr);
@ -142,21 +138,28 @@ void ElfReader::LoadRelocations(Elf32_Rel *rels, int numRelocs)
}
break;
case 7: //gp
if (log)
ERROR_LOG(LOADER,"ARGH IT'S A GP!!!!!!!! %08x", addr);
case R_MIPS_GPREL16: //gp
{
char temp[256];
MIPSDisAsm(op, 0, temp);
ERROR_LOG_REPORT(LOADER, "ARGH IT'S A GP!!!!!!!! %08x : %s", addr, temp);
}
break;
case 0: // another GP reloc!
{
char temp[256];
MIPSDisAsm(op, 0, temp);
ERROR_LOG(LOADER,"WARNING: GP reloc? @ %08x : 0 : %s", addr, temp );
ERROR_LOG_REPORT(LOADER, "WARNING: GP reloc? @ %08x : 0 : %s", addr, temp);
}
break;
default:
ERROR_LOG(LOADER,"ARGH IT'S A UNKNOWN RELOCATION!!!!!!!! %08x", addr);
{
char temp[256];
MIPSDisAsm(op, 0, temp);
ERROR_LOG_REPORT(LOADER,"ARGH IT'S A UNKNOWN RELOCATION!!!!!!!! %08x, type=%d : %s", addr, type, temp);
}
break;
}
Memory::Write_U32(op, addr);
@ -224,7 +227,7 @@ void ElfReader::LoadRelocations2(int rel_seg)
rel_base = buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24);
buf += 4;
}else{
ERROR_LOG(LOADER, "Rel2: invalid size flag!");
ERROR_LOG_REPORT(LOADER, "Rel2: invalid size flag! %x", flag);
rel_base = 0;
}
}else{
@ -253,7 +256,7 @@ void ElfReader::LoadRelocations2(int rel_seg)
rel_base = buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24);;
buf += 4;
}else{
ERROR_LOG(LOADER, "Rel2: invalid relocat size flag!");
ERROR_LOG_REPORT(LOADER, "Rel2: invalid relocat size flag! %x", flag);
}
@ -270,11 +273,11 @@ void ElfReader::LoadRelocations2(int rel_seg)
lo16 |= 0xffff0000;
buf += 2;
}else{
ERROR_LOG(LOADER, "Rel2: invalid lo16 type!");
ERROR_LOG_REPORT(LOADER, "Rel2: invalid lo16 type! %x", flag);
}
op = Memory::ReadUnchecked_U32(rel_offset);
DEBUG_LOG(LOADER, "Rel2: %5d: CMD=0x%04X type=%d off_seg=%d offset=%08x addr_seg=%d op=%08x", rcount, cmd, type, off_seg, rel_base, addr_seg, op);
DEBUG_LOG(LOADER, "Rel2: %5d: CMD=0x%04X type=%d off_seg=%d offset=%08x addr_seg=%d op=%08x\n", rcount, cmd, type, off_seg, rel_base, addr_seg, op);
switch(type){
case 0:
@ -364,7 +367,7 @@ bool ElfReader::LoadInto(u32 loadAddress)
}
if (vaddr == (u32)-1) {
ERROR_LOG(LOADER, "Failed to allocate memory for ELF!");
ERROR_LOG_REPORT(LOADER, "Failed to allocate memory for ELF!");
return false;
}
@ -444,7 +447,7 @@ bool ElfReader::LoadInto(u32 loadAddress)
{
if (!(sections[sectionToModify].sh_flags & SHF_ALLOC))
{
ERROR_LOG(LOADER,"Trying to relocate non-loaded section %s",GetSectionName(sectionToModify));
ERROR_LOG_REPORT(LOADER, "Trying to relocate non-loaded section %s", GetSectionName(sectionToModify));
continue;
}
@ -457,7 +460,7 @@ bool ElfReader::LoadInto(u32 loadAddress)
}
else
{
WARN_LOG(LOADER, "sectionToModify = %i - ignoring PSP relocation sector %i", sectionToModify, i);
WARN_LOG_REPORT(LOADER, "sectionToModify = %i - ignoring PSP relocation sector %i", sectionToModify, i);
}
}
else if (s->sh_type == SHT_REL)
@ -475,15 +478,15 @@ bool ElfReader::LoadInto(u32 loadAddress)
{
if (!(sections[sectionToModify].sh_flags & SHF_ALLOC))
{
ERROR_LOG(LOADER,"Trying to relocate non-loaded section %s, ignoring",GetSectionName(sectionToModify));
ERROR_LOG_REPORT(LOADER, "Trying to relocate non-loaded section %s, ignoring", GetSectionName(sectionToModify));
continue;
}
}
else
{
WARN_LOG(LOADER, "sectionToModify = %i - ignoring relocation sector %i", sectionToModify, i);
WARN_LOG_REPORT(LOADER, "sectionToModify = %i - ignoring relocation sector %i", sectionToModify, i);
}
ERROR_LOG(LOADER,"Traditional relocations unsupported.");
ERROR_LOG_REPORT(LOADER, "Traditional relocations unsupported.");
}
}
}

View File

@ -21,6 +21,22 @@
#include "ElfTypes.h"
enum {
R_MIPS_NONE,
R_MIPS_16,
R_MIPS_32,
R_MIPS_REL32,
R_MIPS_26,
R_MIPS_HI16,
R_MIPS_LO16,
R_MIPS_GPREL16,
R_MIPS_LITERAL,
R_MIPS_GOT16,
R_MIPS_PC16,
R_MIPS_CALL16,
R_MIPS_GPREL32
};
enum KnownElfTypes
{
KNOWNELF_PSP = 0,

View File

@ -49,22 +49,6 @@ enum {
PSP_THREAD_ATTR_USER = 0x80000000
};
enum {
R_MIPS_NONE,
R_MIPS_16,
R_MIPS_32,
R_MIPS_REL32,
R_MIPS_26,
R_MIPS_HI16,
R_MIPS_LO16,
R_MIPS_GPREL16,
R_MIPS_LITERAL,
R_MIPS_GOT16,
R_MIPS_PC16,
R_MIPS_CALL16,
R_MIPS_GPREL32
};
enum {
// Function exports.
NID_MODULE_START = 0xD632ACDB,