From 9eca502026ffddbba936528c9be36b16606b6da1 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sat, 18 Nov 2006 14:37:22 +0100 Subject: [PATCH] Make upx build with gcc-2.95 again. --- src/conf.h | 1 + src/linker.cpp | 31 +++++++++++++++++++++++++++++++ src/linker.h | 9 +++++++++ src/main.cpp | 12 ++++++++++++ src/p_ps1.cpp | 25 +------------------------ 5 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/conf.h b/src/conf.h index 8e98d177..ecbbfcdc 100644 --- a/src/conf.h +++ b/src/conf.h @@ -470,6 +470,7 @@ struct upx_callback_t template struct OptVar { + typedef T Type; static const T default_value_c = default_value; static const T min_value_c = min_value; static const T max_value_c = max_value; diff --git a/src/linker.cpp b/src/linker.cpp index ea738d84..155da926 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -695,6 +695,37 @@ void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location, } +void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location, + unsigned value, const char *type) +{ +#define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15)) +#define MIPS_LO(a) ((a) & 0xffff) +#define MIPS_PC16(a) ((a) >> 2) +#define MIPS_PC26(a) (((a) & 0x0fffffff) >> 2) + + if (strcmp(type, "R_MIPS_HI16") == 0) + set_le16(location, get_le16(location) + MIPS_HI(value)); + else if (strcmp(type, "R_MIPS_LO16") == 0) + set_le16(location, get_le16(location) + MIPS_LO(value)); + else if (strcmp(type, "R_MIPS_PC16") == 0) + { + value -= rel->section->offset + rel->offset; + set_le16(location, get_le16(location) + MIPS_PC16(value)); + } + else if (strcmp(type, "R_MIPS_26") == 0) + set_le32(location, get_le32(location) + MIPS_PC26(value)); + else if (strcmp(type, "R_MIPS_32") == 0) + set_le32(location, get_le32(location) + value); + else + super::relocate1(rel, location, value, type); + +#undef MIPS_HI +#undef MIPS_LO +#undef MIPS_PC16 +#undef MIPS_PC26 +} + + void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location, unsigned value, const char *type) { diff --git a/src/linker.h b/src/linker.h index c9144993..e96cfb83 100644 --- a/src/linker.h +++ b/src/linker.h @@ -180,6 +180,15 @@ protected: }; +class ElfLinkerMipsLE : public ElfLinker +{ + typedef ElfLinker super; +protected: + virtual void relocate1(const Relocation *, upx_byte *location, + unsigned value, const char *type); +}; + + class ElfLinkerPpc32 : public ElfLinker { typedef ElfLinker super; diff --git a/src/main.cpp b/src/main.cpp index b30fea5a..006aeec3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -442,6 +442,7 @@ done: return r; } +#if 1 && (ACC_CC_GNUC >= 0x030300) template int getoptvar(OptVar *var, const char *arg_fatal) { @@ -451,6 +452,17 @@ int getoptvar(OptVar *var, const char *arg_ *var = v; return r; } +#else +template +int getoptvar(T *var, const char *arg_fatal) +{ + typename T::Type v = T::default_value_c; + int r = getoptvar(&v, T::min_value_c, T::max_value_c, arg_fatal); + if (r == 0) + *var = v; + return r; +} +#endif static int do_option(int optc, const char *arg) diff --git a/src/p_ps1.cpp b/src/p_ps1.cpp index 3c03dfce..b209bc52 100644 --- a/src/p_ps1.cpp +++ b/src/p_ps1.cpp @@ -61,6 +61,7 @@ static const #define MIPS_PC16(a) ((a) >> 2) #define MIPS_PC26(a) (((a) & 0x0fffffff) >> 2) + /************************************************************************* // ps1 exe looks like this: // 1.
2048 bytes @@ -110,30 +111,6 @@ const int *PackPs1::getFilters() const Linker* PackPs1::newLinker() const { - class ElfLinkerMipsLE : public ElfLinker - { - typedef ElfLinker super; - - virtual void relocate1(const Relocation *rel, upx_byte *location, - unsigned value, const char *type) - { - if (strcmp(type, "R_MIPS_HI16") == 0) - set_le16(location, get_le16(location) + MIPS_HI(value)); - else if (strcmp(type, "R_MIPS_LO16") == 0) - set_le16(location, get_le16(location) + MIPS_LO(value)); - else if (strcmp(type, "R_MIPS_PC16") == 0) - { - value -= rel->section->offset + rel->offset; - set_le16(location, get_le16(location) + MIPS_PC16(value)); - } - else if (strcmp(type, "R_MIPS_26") == 0) - set_le32(location, get_le32(location) + MIPS_PC26(value)); - else if (strcmp(type, "R_MIPS_32") == 0) - set_le32(location, get_le32(location) + value); - else - super::relocate1(rel, location, value, type); - } - }; return new ElfLinkerMipsLE; }