Skip to content

Commit 4dcfecf

Browse files
author
tyranid
committed
Cleanuped up the source somewhat, sorted the relocations as the order is totally screwed it seems ;)
1 parent b13b83c commit 4dcfecf

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

ProcessElf.C

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ bool CProcessElf::LoadSymbols()
371371
Elf32_Sym *pSym;
372372
int iLoop, iSymcount;
373373
u32 symidx;
374-
u32 name;
375374

376375
symidx = pSymtab->iLink;
377376
iSymcount = pSymtab->iSize / sizeof(Elf32_Sym);

ProcessPrx.C

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ int CProcessPrx::LoadSingleImport(PspModuleImport *pImport, u32 addr)
183183
COutput::Printf(LEVEL_DEBUG, "Found variable nid:0x%08X addr:0x%08X name:%s\n",
184184
pLib->vars[iLoop].nid, pLib->vars[iLoop].addr, pLib->vars[iLoop].name);
185185
varFixup = pLib->vars[iLoop].addr;
186-
while(varData = m_vMem.GetU32(varFixup))
186+
while((varData = m_vMem.GetU32(varFixup)))
187187
{
188188
COutput::Printf(LEVEL_DEBUG, "Variable Fixup: addr:%08X type:%08X\n",
189189
(varData & 0x3FFFFFF) << 2, varData >> 26);
@@ -835,7 +835,7 @@ bool CProcessPrx::ElfToPrx(FILE *fp)
835835
/* Only modify normal elf relocation tables */
836836
if(m_pElfSections[iLoop].iType == SHT_REL)
837837
{
838-
int iRelLoop;
838+
u32 iRelLoop;
839839
Elf32_Rel *reloc;
840840

841841
reloc = (Elf32_Rel*) (pElfCopy + m_pElfSections[iLoop].iOffset);
@@ -851,7 +851,7 @@ bool CProcessPrx::ElfToPrx(FILE *fp)
851851

852852
if((m_elfHeader.iShoff > 0) && (m_elfHeader.iShnum > 0) && (m_elfHeader.iShentsize > 0))
853853
{
854-
int i;
854+
u32 i;
855855
pSection = (Elf32_Shdr*) (pElfCopy + m_elfHeader.iShoff);
856856

857857
for(i = 0; i < m_elfHeader.iShnum; i++)
@@ -1026,6 +1026,27 @@ void CProcessPrx::FreeImms(ImmMap &imms)
10261026
}
10271027
}
10281028

1029+
static int reloc_sort(const void *rel1, const void *rel2)
1030+
{
1031+
const ElfReloc *pRel1, *pRel2;
1032+
int r1base, r2base;
1033+
1034+
pRel1 = static_cast<const ElfReloc *>(rel1);
1035+
pRel2 = static_cast<const ElfReloc *>(rel2);
1036+
r1base = pRel1->symbol & 0xFF;
1037+
r2base = pRel2->symbol & 0xFF;
1038+
1039+
/* First sort by program header */
1040+
if(r1base != r2base)
1041+
{
1042+
return r1base - r2base;
1043+
}
1044+
1045+
/* If same program header then sort by relative offset */
1046+
1047+
return pRel1->offset - pRel2->offset;
1048+
}
1049+
10291050
void CProcessPrx::FixupRelocs(u32 dwBase, ImmMap &imms)
10301051
{
10311052
struct RegEntry
@@ -1035,9 +1056,7 @@ void CProcessPrx::FixupRelocs(u32 dwBase, ImmMap &imms)
10351056
u32 *inst;
10361057
};
10371058

1038-
ElfSection* pModInfoSect;
10391059
int iLoop;
1040-
u32 iVal;
10411060
u32 *pData;
10421061
RegEntry regs[32];
10431062

@@ -1059,6 +1078,9 @@ void CProcessPrx::FixupRelocs(u32 dwBase, ImmMap &imms)
10591078
return;
10601079
}
10611080

1081+
/* Sort the relocations, might work, might not */
1082+
qsort(m_pElfRelocs, m_iRelocCount, sizeof(ElfReloc), reloc_sort);
1083+
10621084
pData = NULL;
10631085
for(iLoop = 0; iLoop < m_iRelocCount; iLoop++)
10641086
{
@@ -1245,7 +1267,7 @@ static void print_row(FILE *fp, const u32* row, s32 row_size, u32 addr)
12451267

12461268
void CProcessPrx::DumpData(FILE *fp, u32 dwAddr, u32 iSize, unsigned char *pData)
12471269
{
1248-
int i;
1270+
u32 i;
12491271
u32 row[16];
12501272
int row_size;
12511273

@@ -1354,7 +1376,7 @@ bool CProcessPrx::ReadString(u32 dwAddr, std::string &str, bool unicode)
13541376

13551377
void CProcessPrx::DumpStrings(FILE *fp, u32 dwAddr, u32 iSize, unsigned char *pData)
13561378
{
1357-
int i;
1379+
u32 i;
13581380
std::string curr = "";
13591381
int iPrintHead = 0;
13601382
u32 dwRealLen = 0;
@@ -1409,7 +1431,7 @@ void CProcessPrx::DumpStrings(FILE *fp, u32 dwAddr, u32 iSize, unsigned char *pD
14091431

14101432
void CProcessPrx::Disasm(FILE *fp, u32 dwAddr, u32 iSize, unsigned char *pData, ImmMap &imms, u32 dwBase)
14111433
{
1412-
int iILoop;
1434+
u32 iILoop;
14131435
u32 *pInst;
14141436
pInst = (u32*) pData;
14151437

@@ -1427,8 +1449,8 @@ void CProcessPrx::Disasm(FILE *fp, u32 dwAddr, u32 iSize, unsigned char *pData,
14271449
fprintf(fp, "; Subroutine %s - Address 0x%08X ", s->name.c_str(), dwAddr);
14281450
if(s->alias.size() > 0)
14291451
{
1430-
fprintf(fp, "- Aliases: ", s->alias.size());
1431-
int i;
1452+
fprintf(fp, "- Aliases: ");
1453+
u32 i;
14321454
for(i = 0; i < s->alias.size()-1; i++)
14331455
{
14341456
fprintf(fp, "%s, ", s->alias[i].c_str());
@@ -1447,7 +1469,7 @@ void CProcessPrx::Disasm(FILE *fp, u32 dwAddr, u32 iSize, unsigned char *pData,
14471469

14481470
if(s->refs.size() > 0)
14491471
{
1450-
int i;
1472+
u32 i;
14511473
fprintf(fp, "\t\t; Refs: ");
14521474
for(i = 0; i < s->refs.size(); i++)
14531475
{
@@ -1585,7 +1607,7 @@ void CProcessPrx::Dump(bool blAll, FILE *fp, const char *disopts, u32 dwBase)
15851607
{
15861608
if(m_pElfSections[iLoop].iFlags & SHF_EXECINSTR)
15871609
{
1588-
int iILoop;
1610+
u32 iILoop;
15891611
u32 dwAddr;
15901612
u32 *pInst;
15911613
dwAddr = m_pElfSections[iLoop].iAddr;

SerializePrxToMap.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bool CSerializePrxToMap::EndFile()
5252

5353
bool CSerializePrxToMap::StartPrx(const char* szFilename, const PspModule *mod, u32 iSMask)
5454
{
55-
int i;
55+
u32 i;
5656
u32 addr;
5757

5858
PrintComment(m_fpOut, "Generated by prxtool");

disasm.C

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,6 @@ static char *print_jump(unsigned int addr, char *output)
869869

870870
static char *print_ofs(int ofs, int reg, char *output, unsigned int *realregs)
871871
{
872-
int len;
873-
874872
if((g_printreal) && (realregs))
875873
{
876874
output = print_jump(realregs[reg] + ofs, output);

0 commit comments

Comments
 (0)