diff --git a/src/Makefile b/src/Makefile index d37904d8..ab13c7a4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -6,7 +6,6 @@ # `make target=dos32-djggp2' # dos32 - djggp2 # `make target=win32-cygwin' # win32 - cygwin # `make target=win32-mingw32' # win32 - mingw32 -# `make target=win32-no-cygwin' # win32 - mingw32 as included in cygwin # `make target=win32-rsxnt' # win32 - rsxnt # `make target=win32-bc' # win32 - Borland C++ # `make target=win32-dm' # win32 - Digital Mars C++ diff --git a/src/Makefile.bld b/src/Makefile.bld index eeb644ef..1285f0be 100644 --- a/src/Makefile.bld +++ b/src/Makefile.bld @@ -335,22 +335,14 @@ ifeq ($(target),win32-cygwin) include $(srcdir)/Makedefs.gcc ##CXX = g++-2 e = .exe -CCARCH += -mcygwin -march=i386 -mcpu=i686 +CCARCH += -march=i386 -mcpu=i686 LDLIBS += -lwinmm endif ifeq ($(target),win32-mingw32) include $(srcdir)/Makedefs.gcc e = .exe -CCARCH += -mno-cygwin -march=i386 -mcpu=i686 -LDLIBS += -lwinmm -endif - -# mingw32 as included in cygwin -ifeq ($(target),win32-no-cygwin) -include $(srcdir)/Makedefs.gcc -e = .exe -CCARCH += -mno-cygwin -march=i386 -mcpu=i686 +CCARCH += -march=i386 -mcpu=i686 LDLIBS += -lwinmm endif @@ -473,11 +465,11 @@ ifeq ($(target),win32-mwerks) o = .obj a = .lib e = .exe -CC = mwcc -runtime ss -gccinc +CC = mwcc -gccinc CFLAGS = -w on CXXFLAGS = $(CFLAGS) CFLAGS_OUTPUT = -o $@ -LDFLAGS = -map $T.map +LDFLAGS = -lwinmm.lib -map $T.map LINK_EXE_OUTPUT = -o $@ LDLIBS = $(DOS_LDLIBS) ifeq ($(DEBUG),1) diff --git a/src/bele.h b/src/bele.h index 02a6e5f3..f7065f59 100644 --- a/src/bele.h +++ b/src/bele.h @@ -138,7 +138,7 @@ inline void set_le24(void *bb, unsigned v) inline unsigned get_le32(const void *bb) { #if (ACC_ARCH_AMD64 || ACC_ARCH_IA32) - return * (const unsigned *) bb; + return * (const acc_uint32e_t *) bb; #else const unsigned char* b = (const unsigned char*) bb; unsigned v; @@ -153,7 +153,7 @@ inline unsigned get_le32(const void *bb) inline void set_le32(void *bb, unsigned v) { #if (ACC_ARCH_AMD64 || ACC_ARCH_IA32) - (* (unsigned *) bb) = v; + (* (acc_uint32e_t *) bb) = v; #else unsigned char* b = (unsigned char*) bb; b[0] = (unsigned char) (v >> 0); @@ -222,7 +222,14 @@ class BE16 public: BE16() { } - BE16& operator = (const BE16 &v) { memcpy(d, v.d, sizeof(d)); return *this; } + BE16& operator = (const BE16 &v) { +#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32) + * (acc_uint32e_t *) d = * (const acc_uint32e_t *) v.d; +#else + memcpy(d, v.d, sizeof(d)); +#endif + return *this; + } BE16& operator = (unsigned v) { set_be16(d, v); return *this; } BE16& operator += (unsigned v) { set_be16(d, get_be16(d) + v); return *this; } @@ -241,7 +248,14 @@ class BE32 public: BE32() { } - BE32& operator = (const BE32 &v) { memcpy(d, v.d, sizeof(d)); return *this; } + BE32& operator = (const BE32 &v) { +#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32) + * (unsigned int *) d = * (const unsigned int *) v.d; +#else + memcpy(d, v.d, sizeof(d)); +#endif + return *this; + } BE32& operator = (unsigned v) { set_be32(d, v); return *this; } BE32& operator += (unsigned v) { set_be32(d, get_be32(d) + v); return *this; } @@ -288,7 +302,7 @@ public: LE32() { } LE32& operator = (const LE32 &v) { #if (ACC_ARCH_AMD64 || ACC_ARCH_IA32) - * (unsigned int *) d = * (const unsigned int *) v.d; + * (acc_uint32e_t *) d = * (const acc_uint32e_t *) v.d; #else memcpy(d, v.d, sizeof(d)); #endif @@ -372,15 +386,21 @@ int __acc_cdecl_qsort le32_compare_signed(const void *e1, const void *e2); // just for testing... -#if (1 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && ACC_CC_GNUC >= 0x030200) +#if 1 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_GNUC >= 0x030200) typedef unsigned short LE16_unaligned __attribute__((__aligned__(1))); - typedef unsigned int LE32_unaligned __attribute__((__aligned__(1))); + typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1))); # define LE16 LE16_unaligned # define LE32 LE32_unaligned #endif -#if (0 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && ACC_CC_MSC) - typedef unsigned short LE16_unaligned; - typedef unsigned int LE32_unaligned; +#if 0 && (ACC_ARCH_IA32) && (ACC_CC_INTELC) + typedef __declspec(align(1)) unsigned short LE16_unaligned; + typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned; +# define LE16 LE16_unaligned +# define LE32 LE32_unaligned +#endif +#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_MSC) && (_MSC_VER >= 1200) + typedef __declspec(align(1)) unsigned short LE16_unaligned; + typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned; # define LE16 LE16_unaligned # define LE32 LE32_unaligned # pragma warning(disable: 4244) // Wx: conversion, possible loss of data diff --git a/src/conf.h b/src/conf.h index 837a755f..516985fc 100644 --- a/src/conf.h +++ b/src/conf.h @@ -37,13 +37,13 @@ **************************************************************************/ #include "acc/acc.h" -#if (ACC_OS_WIN32 && ACC_CC_MWERKS) && defined(__MSL__) +#if ((ACC_OS_WIN32 || ACC_OS_WIN64) && ACC_CC_MWERKS) && defined(__MSL__) # undef HAVE_UTIME_H /* this pulls in */ #endif #include "acc/acc_incd.h" #include "acc/acc_ince.h" #include "acc/acc_lib.h" -#if (ACC_OS_WIN32 || ACC_OS_WIN64) +#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64) # if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR) # error "something pulled in " # endif @@ -300,11 +300,33 @@ /************************************************************************* -// memory util +// **************************************************************************/ -#define UNUSED ACC_UNUSED -#define COMPILE_TIME_ASSERT ACC_COMPILE_TIME_ASSERT +#define UNUSED(var) ACC_UNUSED(var) +#define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e) + +#if 1 +# define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \ + typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \ + struct acc_tmp_t { acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z[7]; }; \ + COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \ + } +#else +# define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \ + struct acc_tmp_t { b x; a y; b z[7]; }; \ + COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \ + } +#endif + +#if defined(acc_alignof) +# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \ + __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) \ + COMPILE_TIME_ASSERT(acc_alignof(a) == sizeof(b)) +#else +# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \ + __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) +#endif #define TABLESIZE(table) ((sizeof(table)/sizeof((table)[0]))) @@ -512,7 +534,7 @@ int upx_test_overlap ( const upx_bytep buf, upx_uint src_off, #endif /* __cplusplus */ -#if (ACC_OS_WIN32 || ACC_OS_WIN64) +#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64) # if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR) # error "something pulled in " # endif diff --git a/src/main.cpp b/src/main.cpp index f17cf20b..c9b29dff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1028,36 +1028,16 @@ void upx_sanity_check(void) COMPILE_TIME_ASSERT(sizeof(LE16) == 2) COMPILE_TIME_ASSERT(sizeof(LE32) == 4) -#if defined(acc_alignof) - COMPILE_TIME_ASSERT(acc_alignof(BE16) == 1) - COMPILE_TIME_ASSERT(acc_alignof(BE32) == 1) - COMPILE_TIME_ASSERT(acc_alignof(LE16) == 1) - COMPILE_TIME_ASSERT(acc_alignof(LE32) == 1) -#endif - -#if !defined(ACC_CC_WATCOMC) - struct foo1a_t { char c1; LE16 v[4]; } __attribute_packed; - struct align_assertion_1a_t { foo1a_t d[3]; } __attribute_packed; - struct foo1b_t { char c1; char v[4*2]; } __attribute_packed; - struct align_assertion_1b_t { foo1b_t d[3]; } __attribute_packed; - struct foo2a_t { char c1; LE32 v[4]; } __attribute_packed; - struct align_assertion_2a_t { foo2a_t d[3]; } __attribute_packed; - struct foo2b_t { char c1; char v[4*4]; } __attribute_packed; - struct align_assertion_2b_t { foo2b_t d[3]; } __attribute_packed; - //printf("%d\n", (int) sizeof(align_assertion_1a_t)); - //printf("%d\n", (int) sizeof(align_assertion_1b_t)); - //printf("%d\n", (int) sizeof(align_assertion_2a_t)); - //printf("%d\n", (int) sizeof(align_assertion_2b_t)); - COMPILE_TIME_ASSERT(sizeof(align_assertion_1a_t) == sizeof(align_assertion_1b_t)) - COMPILE_TIME_ASSERT(sizeof(align_assertion_2a_t) == sizeof(align_assertion_2b_t)) - COMPILE_TIME_ASSERT(sizeof(align_assertion_1a_t) == 3*9) - COMPILE_TIME_ASSERT(sizeof(align_assertion_2a_t) == 3*17) -#endif + COMPILE_TIME_ASSERT_ALIGNOF(BE16, char) + COMPILE_TIME_ASSERT_ALIGNOF(BE32, char) + COMPILE_TIME_ASSERT_ALIGNOF(LE16, char) + COMPILE_TIME_ASSERT_ALIGNOF(LE32, char) COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1) assert(strlen(UPX_VERSION_STRING4) == 4); assert(memcmp(UPX_VERSION_STRING4, UPX_VERSION_STRING, 4) == 0); +#if 1 const unsigned char dd[4] = { 0xff, 0xfe, 0xfd, 0xfc }; assert(upx_adler32(dd, 4) == 0x09f003f7); assert(upx_adler32(dd, 4, 0) == 0x09ec03f6); @@ -1079,6 +1059,7 @@ void upx_sanity_check(void) assert(find_le16(dd, sizeof(dd), 0xfeff) == 0); assert(find_be32(dd, sizeof(dd), 0xfffefdfc) == 0); assert(find_le32(dd, sizeof(dd), 0xfcfdfeff) == 0); +#endif } diff --git a/src/p_djgpp2.cpp b/src/p_djgpp2.cpp index c47a5cb2..e676aa9d 100644 --- a/src/p_djgpp2.cpp +++ b/src/p_djgpp2.cpp @@ -49,6 +49,8 @@ PackDjgpp2::PackDjgpp2(InputFile *f) : COMPILE_TIME_ASSERT(sizeof(external_scnhdr_t) == 40); COMPILE_TIME_ASSERT(sizeof(coff_header_t) == 0xa8); COMPILE_TIME_ASSERT(sizeof(stubify_stub) == 2048); + COMPILE_TIME_ASSERT_ALIGNOF(external_scnhdr_t, char) + COMPILE_TIME_ASSERT_ALIGNOF(coff_header_t, char) #if defined(STUBIFY_STUB_ADLER32) //printf("0x%08x\n", upx_adler32(stubify_stub, sizeof(stubify_stub))); assert(upx_adler32(stubify_stub, sizeof(stubify_stub)) == STUBIFY_STUB_ADLER32); diff --git a/src/p_exe.cpp b/src/p_exe.cpp index 6c18ab49..13fdee31 100644 --- a/src/p_exe.cpp +++ b/src/p_exe.cpp @@ -668,13 +668,13 @@ void PackExe::unpack(OutputFile *fo) oh.ss = ih.ss; if (flag & MAXMEM) - imagesize -= 2, oh.max = get_le16(ibuf+imagesize); + { imagesize -= 2; oh.max = get_le16(ibuf+imagesize); } if (flag & MINMEM) - imagesize -= 2, oh.min = get_le16(ibuf+imagesize); + { imagesize -= 2; oh.min = get_le16(ibuf+imagesize); } if (flag & SP) - imagesize -= 2, oh.sp = get_le16(ibuf+imagesize); + { imagesize -= 2; oh.sp = get_le16(ibuf+imagesize); } if (flag & SS) - imagesize -= 2, oh.ss = get_le16(ibuf+imagesize); + { imagesize -= 2; oh.ss = get_le16(ibuf+imagesize); } unsigned ip = (flag & USEJUMP) ? get_le32(ibuf+imagesize-4) : (unsigned) ih.firstreloc; oh.ip = ip & 0xffff;