1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Portability fixes.

This commit is contained in:
Markus F.X.J. Oberhumer 2007-01-10 17:16:59 +01:00
parent a354f18a2d
commit 0b988176fa
15 changed files with 45 additions and 23 deletions

View File

@ -619,12 +619,12 @@ namespace N_BELE_RTP {
namespace N_BELE_CTP { namespace N_BELE_CTP {
template <class T> template <class T>
static inline const N_BELE_RTP::AbstractPolicy* getRTP(); inline const N_BELE_RTP::AbstractPolicy* getRTP();
template <> template <>
static inline const N_BELE_RTP::AbstractPolicy* getRTP<BEPolicy>() inline const N_BELE_RTP::AbstractPolicy* getRTP<BEPolicy>()
{ return &N_BELE_RTP::be_policy; } { return &N_BELE_RTP::be_policy; }
template <> template <>
static inline const N_BELE_RTP::AbstractPolicy* getRTP<LEPolicy>() inline const N_BELE_RTP::AbstractPolicy* getRTP<LEPolicy>()
{ return &N_BELE_RTP::le_policy; } { return &N_BELE_RTP::le_policy; }
} }

View File

@ -169,6 +169,10 @@ STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outS
} // namespace } // namespace
#if (ACC_CC_INTELC) && defined(__linux__)
# pragma warning(disable: 424) // #424: extra ";" ignored
#endif
#include "C/Common/Alloc.cpp" #include "C/Common/Alloc.cpp"
#include "C/Common/CRC.cpp" #include "C/Common/CRC.cpp"
//#include "C/7zip/Common/InBuffer.cpp" //#include "C/7zip/Common/InBuffer.cpp"

View File

@ -58,7 +58,7 @@ static int F(Filter *f)
{ {
unsigned char buf[256]; unsigned char buf[256];
unsigned short wbuf[256]; unsigned short wbuf[256];
const size_t WW = (size_t)0 - (~(size_t)0) << W_CTO; // ??? const size_t WW = (size_t)0 - ((~(size_t)0) << W_CTO); // ???
memset(wbuf, 0, sizeof(wbuf)); memset(wbuf, 0, sizeof(wbuf));
memset(buf , 0, WW); memset(buf , 0, WW);
memset(buf + WW, 1, 256 - WW); memset(buf + WW, 1, 256 - WW);

View File

@ -414,7 +414,7 @@ int ElfLinker::addLoader(const char *sname)
assert(tail); assert(tail);
assert(tail != section); 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 & (0u-(tail->offset + tail->size))) {
alignCode(l); alignCode(l);
tail->size += l; tail->size += l;
} }

View File

@ -912,7 +912,7 @@ PackLinuxElf64amd::canPack()
// The first PT_LOAD64 must cover the beginning of the file (0==p_offset). // The first PT_LOAD64 must cover the beginning of the file (0==p_offset).
unsigned const e_phnum = get_native16(&ehdr->e_phnum); unsigned const e_phnum = get_native16(&ehdr->e_phnum);
Elf64_Phdr const *phdr = (Elf64_Phdr const *)(buf + e_phoff); Elf64_Phdr const *phdr = (Elf64_Phdr const *)(buf + (unsigned) e_phoff);
for (unsigned j=0; j < e_phnum; ++phdr, ++j) { for (unsigned j=0; j < e_phnum; ++phdr, ++j) {
if (j >= 14) if (j >= 14)
return false; return false;

View File

@ -204,7 +204,7 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) ; ((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) ;
unsigned nw = fo->getBytesWritten(); unsigned nw = fo->getBytesWritten();
elfout.phdr[0].p_filesz = nw; elfout.phdr[0].p_filesz = nw;
nw = -(-elfout.phdr[0].p_align & -nw); // ALIGN_UP nw = 0u-((0u-elfout.phdr[0].p_align) & (0u-nw)); // ALIGN_UP
super::pack4(fo, ft); // write PackHeader and overlay_offset super::pack4(fo, ft); // write PackHeader and overlay_offset
set_stub_brk(&elfout.phdr[1], nw + elfout.phdr[0].p_vaddr); set_stub_brk(&elfout.phdr[1], nw + elfout.phdr[0].p_vaddr);

View File

@ -195,8 +195,8 @@ PackMachPPC32::pack3(OutputFile *fo, Filter &ft) // append loader
BE32 disp; BE32 disp;
unsigned const zero = 0; unsigned const zero = 0;
unsigned len = fo->getBytesWritten(); unsigned len = fo->getBytesWritten();
fo->write(&zero, 3& -len); fo->write(&zero, 3& (0u-len));
len += (3& -len) + sizeof(disp); len += (3& (0u-len)) + sizeof(disp);
set_be32(&disp, 4+ len - sz_mach_headers); // 4: sizeof(instruction) set_be32(&disp, 4+ len - sz_mach_headers); // 4: sizeof(instruction)
fo->write(&disp, sizeof(disp)); fo->write(&disp, sizeof(disp));

View File

@ -53,7 +53,7 @@ static const
#define K0_BS (0x80000000) #define K0_BS (0x80000000)
#define K1_BS (0xa0000000) #define K1_BS (0xa0000000)
#define EXE_BS (ih.epc & K0_BS) #define EXE_BS (ih.epc & K0_BS)
#define FIX_PSVR (K1_BS - EXE_BS) + (PS_HDR_SIZE - HD_CODE_OFS) #define FIX_PSVR ((K1_BS - EXE_BS) + (PS_HDR_SIZE - HD_CODE_OFS))
// lui / addiu // lui / addiu
#define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15)) #define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15))
@ -152,7 +152,7 @@ bool PackPs1::readBkupHeader()
} }
#define INIT_BH_BKUP(p, l) {(p)->id = '1'; (p)->len = l;} #define INIT_BH_BKUP(p, l) {(p)->id = '1'; (p)->len = l;}
#define ADLER16(a) ((a) >> 16 ^ ((a) & 0xffff)) #define ADLER16(a) (((a) >> 16) ^ ((a) & 0xffff))
void PackPs1::putBkupHeader(const unsigned char *src, unsigned char *dst, unsigned *len) void PackPs1::putBkupHeader(const unsigned char *src, unsigned char *dst, unsigned *len)
{ {
@ -390,7 +390,7 @@ void PackPs1::buildLoader(const Filter *)
#define REG1(x) (((x) >> 5) & 0x1f) #define REG1(x) (((x) >> 5) & 0x1f)
#define REG2(x) ((x) & 0x1f) #define REG2(x) ((x) & 0x1f)
#define MIPS_IMM(a,b) (((a) - (((b) & 0x8000) >> 15) << 16) | (b)) #define MIPS_IMM(a,b) ((((a) - (((b) & 0x8000) >> 15)) << 16) | (b))
// Type // Type
#define REGIMM 1 #define REGIMM 1

View File

@ -112,7 +112,7 @@ protected:
} }
__attribute_packed; __attribute_packed;
typedef struct bss_nfo struct bss_nfo
{ {
LE16 hi1, op1, lo1, op2; LE16 hi1, op1, lo1, op2;
LE16 hi2, op3, lo2, op4; LE16 hi2, op3, lo2, op4;

View File

@ -80,7 +80,7 @@ int PackVmlinuxBase<T>::getStrategy(Filter &/*ft*/)
// If user specified the filter, then use it (-2==strategy). // If user specified the filter, then use it (-2==strategy).
// Else try the first two filters, and pick the better (2==strategy). // Else try the first two filters, and pick the better (2==strategy).
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2)); return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
}; }
template <class T> template <class T>
int __acc_cdecl_qsort int __acc_cdecl_qsort
@ -251,7 +251,7 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
for (unsigned j = 0; j < ehdri.e_phnum; ++j) { for (unsigned j = 0; j < ehdri.e_phnum; ++j) {
if (Phdr::PT_LOAD==phdri[j].p_type) { if (Phdr::PT_LOAD==phdri[j].p_type) {
fi->seek(phdri[j].p_offset, SEEK_SET); fi->seek(phdri[j].p_offset, SEEK_SET);
fi->readx(ibuf + (phdri[j].p_paddr - paddr_min), phdri[j].p_filesz); fi->readx(ibuf + ((unsigned) phdri[j].p_paddr - paddr_min), phdri[j].p_filesz);
} }
} }
checkAlreadyPacked(ibuf + ph.u_len - 1024, 1024); checkAlreadyPacked(ibuf + ph.u_len - 1024, 1024);
@ -291,7 +291,7 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
fo_off += write_vmlinux_head(fo, &shdro[1]); fo_off += write_vmlinux_head(fo, &shdro[1]);
fo->write(obuf, txt_c_len); fo_off += txt_c_len; fo->write(obuf, txt_c_len); fo_off += txt_c_len;
unsigned const a = (shdro[1].sh_addralign -1) & -txt_c_len; unsigned const a = (shdro[1].sh_addralign -1) & (0u-txt_c_len);
if (0!=a) { // align if (0!=a) { // align
fo_off += a; fo_off += a;
shdro[1].sh_size += a; shdro[1].sh_size += a;
@ -756,7 +756,7 @@ unsigned PackVmlinuxARM::write_vmlinux_head(
U32 tmp_u32; U32 tmp_u32;
unsigned const t = (0xff000000 & unsigned const t = (0xff000000 &
BeLePolicy::get32(&stub_arm_linux_kernel_vmlinux_head[4])) BeLePolicy::get32(&stub_arm_linux_kernel_vmlinux_head[4]))
| (0x00ffffff & (-1+ ((3+ ph.c_len)>>2))); | (0x00ffffff & (0u - 1 + ((3+ ph.c_len)>>2)));
tmp_u32 = t; tmp_u32 = t;
fo->write(&tmp_u32, 4); fo->write(&tmp_u32, 4);
@ -775,7 +775,7 @@ bool PackVmlinuxARM::has_valid_vmlinux_head()
//unsigned const word0 = buf[0]; //unsigned const word0 = buf[0];
unsigned const word1 = buf[1]; unsigned const word1 = buf[1];
if (0xeb==(word1>>24) if (0xeb==(word1>>24)
&& (0x00ffffff& word1)==(-1+ ((3+ ph.c_len)>>2))) { && (0x00ffffff& word1)==(0u - 1 + ((3+ ph.c_len)>>2))) {
return true; return true;
} }
return false; return false;

View File

@ -59,7 +59,7 @@ protected:
virtual void encodeFixups(); virtual void encodeFixups();
virtual void decodeFixups(); virtual void decodeFixups();
virtual void encodeImage(const Filter *ft); virtual void encodeImage(Filter *ft);
virtual void decodeImage(); virtual void decodeImage();
}; };

View File

@ -35,7 +35,7 @@
class PackW32Pe : public PeFile class PackW32Pe : public PeFile
{ {
typedef PeFile super;; typedef PeFile super;
public: public:
PackW32Pe(InputFile *f); PackW32Pe(InputFile *f);

View File

@ -1055,15 +1055,22 @@ void Packer::initLoader(const void *pdata, int plen, int small)
linker->addSection("IDENTSTR", ident, size, 0); linker->addSection("IDENTSTR", ident, size, 0);
} }
#if 1 && (ACC_CC_BORLANDC)
#else
void Packer::addLoader(const char *s) void Packer::addLoader(const char *s)
{ {
if (s) if (s)
linker->addLoader(s); linker->addLoader(s);
} }
#endif
// provide specialization for [T = char] #if 1 && (ACC_CC_BORLANDC)
void __acc_cdecl_va Packer::addLoader(const char *s, ...)
#else
// provide specialization for [T = const char *]
template <> template <>
void __acc_cdecl_va Packer::addLoader<char>(const char *s, ...) void __acc_cdecl_va Packer::addLoader<char>(const char *s, ...)
#endif
{ {
va_list ap; va_list ap;

View File

@ -226,10 +226,13 @@ protected:
virtual upx_byte *getLoader() const; virtual upx_byte *getLoader() const;
virtual int getLoaderSize() const; virtual int getLoaderSize() const;
virtual void initLoader(const void *pdata, int plen, int small=-1); virtual void initLoader(const void *pdata, int plen, int small=-1);
#if 1 && (ACC_CC_BORLANDC)
void __acc_cdecl_va addLoader(const char *, ...);
#elif 1 && (ACC_CC_GNUC >= 0x040100)
void addLoader(const char *); void addLoader(const char *);
#if 1 && (ACC_CC_GNUC >= 0x040100)
template <class T> void __acc_cdecl_va addLoader(const T *, ...) __attribute__((__sentinel__)); template <class T> void __acc_cdecl_va addLoader(const T *, ...) __attribute__((__sentinel__));
#else #else
void addLoader(const char *);
template <class T> void __acc_cdecl_va addLoader(const T *, ...); template <class T> void __acc_cdecl_va addLoader(const T *, ...);
#endif #endif
virtual int getLoaderSection(const char *name, int *slen=NULL) const; virtual int getLoaderSection(const char *name, int *slen=NULL) const;
@ -306,8 +309,11 @@ private:
}; };
#if 1 && (ACC_CC_BORLANDC)
#else
template <> template <>
void __acc_cdecl_va Packer::addLoader<char>(const char *s, ...); void __acc_cdecl_va Packer::addLoader<char>(const char *, ...);
#endif
#endif /* already included */ #endif /* already included */

View File

@ -582,6 +582,11 @@ extern "C" {
int dup(int fd) { UNUSED(fd); return -1; } int dup(int fd) { UNUSED(fd); return -1; }
#endif #endif
// FIXME - quick hack for wrt54gl
#if 1 && (ACC_ARCH_MIPS) && (ACC_OS_POSIX_LINUX) && (ACC_LIBC_UCLIBC)
clock_t clock(void) { return 0; }
#endif
#if defined(__DJGPP__) #if defined(__DJGPP__)
int _is_executable(const char *, int, const char *) int _is_executable(const char *, int, const char *)
{ {