From b76118802ac282a244ef3200eee5d42a21005fdd Mon Sep 17 00:00:00 2001 From: John Reiser Date: Sun, 9 Jul 2006 19:52:23 -0700 Subject: [PATCH] ElfLinkerPpc32 --- src/linker.cpp | 30 ++++++++++++++++++++++++++++++ src/linker.h | 10 ++++++++++ src/p_lx_elf.cpp | 16 +++++++--------- src/p_lx_elf.h | 2 +- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/linker.cpp b/src/linker.cpp index be5d5515..34c34008 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -680,6 +680,11 @@ void ElfLinkerAMD64::align(unsigned len) alignWithByte(len, 0x90); } +void ElfLinkerPpc32::align(unsigned len) +{ + alignWithByte(len, 0); +} + void ElfLinkerX86::relocate1(Relocation *rel, upx_byte *location, unsigned value, const char *type) { @@ -726,6 +731,31 @@ void ElfLinkerAMD64::relocate1(Relocation *rel, upx_byte *location, super::relocate1(rel, location, value, type); } +void ElfLinkerPpc32::relocate1(Relocation *rel, upx_byte *location, + unsigned value, const char *type) +{ + if (strncmp(type, "R_PPC_", 6)) + return super::relocate1(rel, location, value, type); + type += 6; + + if (strncmp(type, "REL", 3) == 0) + { + value -= rel->section->offset + rel->offset; + type += 3; + } + + // FIXME: more relocs + + if (strcmp(type, "8") == 0) + *location += value; + else if (strcmp(type, "16") == 0) + set_le16(location, get_le16(location) + value); + else if (strcmp(type, "32") == 0) + set_le32(location, get_le32(location) + value); + else + super::relocate1(rel, location, value, type); +} + void ElfLinkerArmLE::relocate1(Relocation *rel, upx_byte *location, unsigned value, const char *type) { diff --git a/src/linker.h b/src/linker.h index 111e92ca..64c9ea23 100644 --- a/src/linker.h +++ b/src/linker.h @@ -268,6 +268,16 @@ protected: unsigned value, const char *type); }; +class ElfLinkerPpc32 : public ElfLinker +{ + typedef ElfLinker super; + +protected: + virtual void align(unsigned len); + virtual void relocate1(Relocation *, upx_byte *location, + unsigned value, const char *type); +}; + class ElfLinkerArmLE : public ElfLinker { typedef ElfLinker super; diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 3c684f33..7c4596a9 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -302,6 +302,11 @@ PackLinuxElf32ppc::~PackLinuxElf32ppc() { } +Linker* PackLinuxElf32ppc::newLinker() const +{ + return new ElfLinkerPpc32; +} + PackLinuxElf64amd::PackLinuxElf64amd(InputFile *f) : super(f) { @@ -528,6 +533,7 @@ PackLinuxElf32::buildLinuxLoader( addLoader("FOLDEXEC", NULL); freezeLoader(); + linker->relocate(); return getLoaderSize(); } @@ -583,18 +589,10 @@ PackLinuxElf64::buildLinuxLoader( addLoader("FOLDEXEC", NULL); freezeLoader(); + linker->relocate(); return getLoaderSize(); } -void -PackLinuxElf64amd::addStubEntrySections( - upx_byte const *const /*proto*/, - unsigned const /*szproto*/ -) -{ - // FIXME -} - static const #include "stub/i386-linux.elf-entry.h" static const diff --git a/src/p_lx_elf.h b/src/p_lx_elf.h index 8e0a890e..8d8988ed 100644 --- a/src/p_lx_elf.h +++ b/src/p_lx_elf.h @@ -288,7 +288,6 @@ protected: virtual const int *getCompressionMethods(int method, int level) const; virtual int buildLoader(const Filter *); virtual Linker* newLinker() const; - virtual void addStubEntrySections(upx_byte const *, unsigned); }; /************************************************************************* @@ -308,6 +307,7 @@ protected: virtual void pack1(OutputFile *, Filter &); // generate executable header virtual const int *getCompressionMethods(int method, int level) const; virtual int buildLoader(const Filter *); + virtual Linker* newLinker() const; }; /*************************************************************************