Added some more debugging support to Linker.
This commit is contained in:
+33
-9
@@ -372,6 +372,7 @@ int ElfLinker::addLoader(const char *sname)
|
|||||||
Section *section = findSection(sect);
|
Section *section = findSection(sect);
|
||||||
if (section->p2align) {
|
if (section->p2align) {
|
||||||
assert(tail);
|
assert(tail);
|
||||||
|
assert(tail != section);
|
||||||
unsigned const v = ~0u << section->p2align;
|
unsigned const v = ~0u << section->p2align;
|
||||||
if (unsigned const l = ~v & -(tail->offset + tail->size)) {
|
if (unsigned const l = ~v & -(tail->offset + tail->size)) {
|
||||||
alignCode(l);
|
alignCode(l);
|
||||||
@@ -452,6 +453,7 @@ void ElfLinker::relocate()
|
|||||||
value = rel->value->section->offset +
|
value = rel->value->section->offset +
|
||||||
rel->value->offset + rel->add;
|
rel->value->offset + rel->add;
|
||||||
}
|
}
|
||||||
|
//printf("%-28s %-28s %-10s 0x%08x 0x%08x\n", rel->section->name, rel->value->name, rel->type, value, value - rel->section->offset - rel->offset);
|
||||||
upx_byte *location = rel->section->output + rel->offset;
|
upx_byte *location = rel->section->output + rel->offset;
|
||||||
relocate1(rel, location, value, rel->type);
|
relocate1(rel, location, value, rel->type);
|
||||||
}
|
}
|
||||||
@@ -484,17 +486,36 @@ void ElfLinker::defineSymbol(const char *name, unsigned value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// debugging support
|
// debugging support
|
||||||
|
void ElfLinker::dumpSymbol(const Symbol *symbol, unsigned flags, FILE *fp) const
|
||||||
|
{
|
||||||
|
if ((flags & 1) && symbol->section->output == NULL)
|
||||||
|
return;
|
||||||
|
fprintf(fp, "%-28s 0x%08x | %-28s 0x%08x\n",
|
||||||
|
symbol->name, symbol->offset, symbol->section->name, symbol->section->offset);
|
||||||
|
}
|
||||||
void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const
|
void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const
|
||||||
{
|
{
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
fp = stdout;
|
fp = stdout;
|
||||||
for (unsigned ic = 0; ic < nsymbols; ic++)
|
if ((flags & 2) == 0)
|
||||||
{
|
{
|
||||||
const Symbol *symbol = symbols[ic];
|
// default: dump symbols in used section order
|
||||||
if ((flags & 1) && symbol->section->output == NULL)
|
for (const Section *section = head; section; section = section->next)
|
||||||
continue;
|
{
|
||||||
fprintf(fp, "%-28s 0x%08x | %-28s 0x%08x\n",
|
fprintf(fp, "%-42s%-28s 0x%08x\n", "", section->name, section->offset);
|
||||||
symbol->name, symbol->offset, symbol->section->name, symbol->section->offset);
|
for (unsigned ic = 0; ic < nsymbols; ic++)
|
||||||
|
{
|
||||||
|
const Symbol *symbol = symbols[ic];
|
||||||
|
if (symbol->section == section && strcmp(symbol->name, section->name) != 0)
|
||||||
|
dumpSymbol(symbol, flags, fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// dump all symbols
|
||||||
|
for (unsigned ic = 0; ic < nsymbols; ic++)
|
||||||
|
dumpSymbol(symbols[ic], flags, fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -654,12 +675,15 @@ void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location,
|
|||||||
value -= rel->section->offset + rel->offset;
|
value -= rel->section->offset + rel->offset;
|
||||||
type += 2;
|
type += 2;
|
||||||
}
|
}
|
||||||
if (strcmp(type, "8") == 0)
|
if (strcmp(type, "8") == 0) {
|
||||||
*location += value;
|
*location += value;
|
||||||
else if (strcmp(type, "16") == 0)
|
}
|
||||||
|
else if (strcmp(type, "16") == 0) {
|
||||||
set_be16(location, get_be16(location) + value);
|
set_be16(location, get_be16(location) + value);
|
||||||
else if (strcmp(type, "32") == 0)
|
}
|
||||||
|
else if (strcmp(type, "32") == 0) {
|
||||||
set_be32(location, get_be32(location) + value);
|
set_be32(location, get_be32(location) + value);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
super::relocate1(rel, location, value, type);
|
super::relocate1(rel, location, value, type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ public:
|
|||||||
virtual void relocate();
|
virtual void relocate();
|
||||||
virtual void defineSymbol(const char *name, unsigned value);
|
virtual void defineSymbol(const char *name, unsigned value);
|
||||||
virtual unsigned getSymbolOffset(const char *) const;
|
virtual unsigned getSymbolOffset(const char *) const;
|
||||||
|
|
||||||
|
virtual void dumpSymbol(const Symbol *, unsigned flags, FILE *fp) const;
|
||||||
virtual void dumpSymbols(unsigned flags=0, FILE *fp=NULL) const;
|
virtual void dumpSymbols(unsigned flags=0, FILE *fp=NULL) const;
|
||||||
|
|
||||||
void alignWithByte(unsigned len, unsigned char b);
|
void alignWithByte(unsigned len, unsigned char b);
|
||||||
|
|||||||
Reference in New Issue
Block a user