From 6c519c237e87b5f733a1b8eab78b9fec0f179c23 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Mon, 28 Aug 2006 08:58:43 +0200 Subject: [PATCH] Renamed Linker::align() to alignCode(). We still have to add some way to express alignData(). --- src/linker.cpp | 14 +++++--------- src/linker.h | 8 +++++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/linker.cpp b/src/linker.cpp index 144c9768..bbd841c9 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -317,7 +317,7 @@ int ElfLinker::addLoader(const char *sname) if (unsigned l = (hex(sect[2]) - tail->offset - tail->size) % hex(sect[1])) { - align(l); + alignCode(l); tail->size += l; outputlen += l; } @@ -329,7 +329,7 @@ int ElfLinker::addLoader(const char *sname) unsigned const v = ~0u << section->align; assert(tail); if (unsigned const l = ~v & -(tail->offset + tail->size)) { - align(l); + alignCode(l); tail->size += l; outputlen += l; } @@ -457,11 +457,6 @@ void ElfLinker::alignWithByte(unsigned len, upx_byte b) memset(output + outputlen, b, len); } -void ElfLinker::align(unsigned len) -{ - alignWithByte(len, 0); -} - void ElfLinker::relocate1(const Relocation *rel, upx_byte *, unsigned, const char *) { @@ -472,6 +467,7 @@ void ElfLinker::relocate1(const Relocation *rel, upx_byte *, /************************************************************************* // ElfLinker arch subclasses +// FIXME: add more displacment overflow checks **************************************************************************/ void ElfLinkerAMD64::relocate1(const Relocation *rel, upx_byte *location, @@ -490,7 +486,7 @@ void ElfLinkerAMD64::relocate1(const Relocation *rel, upx_byte *location, if (strcmp(type, "8") == 0) { int displ = (signed char) *location + (int) value; - if (displ < -127 || displ > 128) + if (displ < -128 || displ > 127) { printf("target out of range (%d) in reloc %s:%x\n", displ, rel->section->name, rel->offset); @@ -645,7 +641,7 @@ void ElfLinkerX86::relocate1(const Relocation *rel, upx_byte *location, if (strcmp(type, "8") == 0) { int displ = (signed char) *location + (int) value; - if (range_check && (displ < -127 || displ > 128)) { + if (range_check && (displ < -128 || displ > 127)) { printf("target out of range (%d) in reloc %s:%x\n", displ, rel->section->name, rel->offset); abort(); diff --git a/src/linker.h b/src/linker.h index 652f1c8b..2599b630 100644 --- a/src/linker.h +++ b/src/linker.h @@ -88,7 +88,9 @@ public: virtual unsigned getSymbolOffset(const char *) const; void alignWithByte(unsigned len, upx_byte b); - virtual void align(unsigned len); + virtual void alignCode(unsigned len) { alignWithByte(len, 0); } + virtual void alignData(unsigned len) { alignWithByte(len, 0); } + virtual void relocate1(const Relocation *, upx_byte *location, unsigned value, const char *type); }; @@ -141,7 +143,7 @@ class ElfLinkerAMD64 : public ElfLinker { typedef ElfLinker super; protected: - virtual void align(unsigned len) { alignWithByte(len, 0x90); } + virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); } virtual void relocate1(const Relocation *, upx_byte *location, unsigned value, const char *type); }; @@ -187,7 +189,7 @@ class ElfLinkerX86 : public ElfLinker { typedef ElfLinker super; protected: - virtual void align(unsigned len) { alignWithByte(len, 0x90); } + virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); } virtual void relocate1(const Relocation *, upx_byte *location, unsigned value, const char *type); };