diff --git a/src/Makefile b/src/Makefile index 6ee659e6..5f681e3a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -7,10 +7,11 @@ # `make target=cygwin' # win32 - cygwin 1.3.x # `make target=mingw32' # win32 - mingw32 # `make target=no-cygwin' # win32 - mingw32 as included in cygwin 1.3.x -# `make target=bcc' # win32 - Borland C++ 5.5.1 -# `make target=dmc' # win32 - Digital Mars C++ 8.32 -# `make target=vc6' # win32 - Visual C++ 6.0 -# `make target=wcc' # win32 - Watcom C++ 11.0c +# `make target=bc' # win32 - Borland C++ 5.5.1 +# `make target=dm' # win32 - Digital Mars C++ 8.32 +# `make target=ic' # win32 - Intel C++ 7.0 +# `make target=vc' # win32 - Visual C++ 6 +# `make target=wc' # win32 - Watcom C++ 11.0c # `make target=cross-m68k-linux' # m68k-linux cross compiler # `make target=cross-mingw32' # i586-mingw32msvc cross compiler # `make target=cross-mint' # m68k-atari-mint cross compiler @@ -24,6 +25,7 @@ ifeq ($(strip $(UCLDIR)),) UCLDIR = $(HOME)/local/src/ucl-1.01 endif +## you can set the default target here ##target = DEBUG = 0 @@ -47,12 +49,16 @@ VPATH = $(srcdir) # auto-detect the target unless given on the commandline +ifeq ($(strip $(target)),) + # try environment variable UPX_TARGET + target := $(UPX_TARGET) +endif ifeq ($(strip $(target)),) ifneq ($(strip $(wildcard /usr/include/linux)),) target = linux endif ##ifneq ($(strip $(wildcard /platform/sun4?/kernel/unix)),) -##target = sparc +##target = sparc-sun-solaris ##endif endif @@ -191,18 +197,18 @@ endif ### -### Linux +### linux ### ifeq ($(target),linux) -include $(srcdir)/Makedefs.gcc override arch := $(shell uname -m | sed -e 's/^i[3456789]86$$/i386/') -DEFS += '-DUPX_CONFIG_H="config_h/linux.h"' -DEFS += -D_FILE_OFFSET_BITS=64 -LDLIBS += -lmcheck +include $(srcdir)/Makedefs.gcc ifeq ($(arch),i386) CCARCH += -march=i386 -mcpu=i686 endif +DEFS += '-DUPX_CONFIG_H="config_h/linux.h"' +DEFS += -D_FILE_OFFSET_BITS=64 +LDLIBS += -lmcheck ##CFLAGS_WERROR = -Werror ifeq ($(DEBUG),0) @@ -218,12 +224,13 @@ endif # linux ### -### Linux/i386 with Intel C++ 7.0 +### linux/i386 - Intel C++ 7.0 ### ifeq ($(target),linux-intelc70) CC = icc CXX = icc +CCARCH += -march=i386 -mcpu=i686 CFLAGS_OUTPUT = -o $@ LINK_EXE_OUTPUT = -o $@ @@ -257,10 +264,10 @@ endif # cross-m68k-linux ### sparc-sun-solaris2.8 ### -ifeq ($(target),sparc) +ifeq ($(target),sparc-sun-solaris) include $(srcdir)/Makedefs.gcc DEFS += '-DUPX_CONFIG_H="config_h/sparc_sun_solaris28.h"' -endif # sparc +endif ### @@ -293,7 +300,7 @@ endif ### -### djgpp2 +### dos32 - djgpp2 ### ifeq ($(target),djgpp2) @@ -312,13 +319,13 @@ endif # djgpp2 ### -### cygwin / mingw32 +### win32 - cygwin / mingw32 ### ifeq ($(target),cygwin) include $(srcdir)/Makedefs.gcc e = .exe -CCARCH += -march=i386 -mcpu=i686 +CCARCH += -mcygwin -march=i386 -mcpu=i686 endif ifeq ($(target),mingw32) @@ -345,15 +352,15 @@ endif ### -### Borland C++ 5.5.1 +### win32 - Borland C++ 5.5.1 ### -ifeq ($(target),bcc) +ifeq ($(target),bc) o = .obj a = .lib e = .exe CC = bcc32 -q -3 -CFLAGS = -w -w-aus -g1 +CFLAGS = -w -w-aus -w-inl -g1 CXXFLAGS_2 = $(CXXFLAGS) -x- -xd- -RT- CFLAGS_OUTPUT = -o$@ LDFLAGS = @@ -375,10 +382,10 @@ endif # bcc ### -### Digital Mars C++ 8.32 +### win32 - Digital Mars C++ 8.32 ### -ifeq ($(target),dmc) +ifeq ($(target),dm) o = .obj a = .lib e = .exe @@ -406,10 +413,44 @@ endif # dmc ### -### Visual C++ 6 (aka Microsoft C/C++ Compiler 12.00) +### win32 - Intel C++ 7.0 ### -ifeq ($(target),vc6) +ifeq ($(target),ic) +o = .obj +a = .lib +e = .exe +CC = icl -nologo -MD +CFLAGS = -W3 -WX +CXXFLAGS_1 = $(CXXFLAGS) -EHac -GR +LDFLAGS = +LINK_EXE_OUTPUT = -Fe$@ +LDLIBS = $(DOS_LDLIBS) setargv.obj +LINK_EXE_LDFLAGS = /link /map:$T.map +##LINK_EXE_LDFLAGS += /verbose + +ifneq ($(strip $(DOS_LIBDIRS)),) +LIB := $(DOS_LIBDIRS);$(LIB) +endif +export LIB + +ifeq ($(DEBUG),1) + CFLAGS += -Od -ZI + LINK_EXE_LDFLAGS += /debug +else + CFLAGS += -O1 -GF + LINK_EXE_LDFLAGS += /release +endif +RESOURCES = upx.res + +endif # icl + + +### +### win32 - Visual C++ 6 +### + +ifeq ($(target),vc) o = .obj a = .lib e = .exe @@ -439,7 +480,7 @@ ifeq ($(DEBUG),1) CFLAGS += -Od -ZI LINK_EXE_LDFLAGS += /debug else - CFLAGS += -O2 -GF + CFLAGS += -O1 -GF LINK_EXE_LDFLAGS += /release endif RESOURCES = upx.res @@ -448,10 +489,10 @@ endif # vc6 ### -### Watcom C++ 11.0c / Open Watcom C++ 1.0 +### win32 - Watcom C++ 11.0c / Open Watcom C++ 1.0 ### -ifeq ($(target),wcc) +ifeq ($(target),wc) o = .obj a = .lib e = .exe diff --git a/src/bele.h b/src/bele.h index 1fb115ce..e80a85ae 100644 --- a/src/bele.h +++ b/src/bele.h @@ -355,7 +355,7 @@ int le32_compare_signed(const void *e1, const void *e2); // just for testing... #if 0 && defined(__i386__) && defined(__GNUC_VERSION_HEX__) -# if (__GNUC_VERSION_HEX__ >= 0x030100) +# if (__GNUC_VERSION_HEX__ >= 0x030200) typedef unsigned short LE16_unaligned __attribute__((__packed__,__aligned__(1))); typedef unsigned int LE32_unaligned __attribute__((__packed__,__aligned__(1))); # define LE16 LE16_unaligned diff --git a/src/conf.h b/src/conf.h index 4a5d51b8..5df890ea 100644 --- a/src/conf.h +++ b/src/conf.h @@ -61,7 +61,7 @@ # elif defined(__GNUC__) || defined(__DMC__) # define upx_int64l long long int # define upx_uint64l unsigned long long int -# elif defined(__BORLANDC__) || defined(_MSC_VER) || defined(__WATCOMC__) +# elif defined(__BORLANDC__) || defined(__INTEL_COMPILER) || defined(_MSC_VER) || defined(__WATCOMC__) # define upx_int64l __int64 # define upx_uint64l unsigned __int64 # else @@ -350,7 +350,7 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int); #undef __attribute_packed -#if defined(__GNUC__) +#if defined(__GNUC__) || defined(__INTEL_COMPILER) # if 1 && defined(__i386__) # define __attribute_packed # else diff --git a/src/except.h b/src/except.h index c60bb130..95e0fba3 100644 --- a/src/except.h +++ b/src/except.h @@ -60,10 +60,7 @@ private: // disable assignment Throwable& operator= (Throwable const &); // disable dynamic allocation -#ifndef new - static void *operator new (size_t); // {} - static void *operator new[] (size_t); // {} -#endif + DISABLE_NEW_DELETE private: static long counter; // for debugging diff --git a/src/main.cpp b/src/main.cpp index a6ddeb23..00c1275e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1032,7 +1032,7 @@ void upx_sanity_check(void) COMPILE_TIME_ASSERT(sizeof(LE16) == 2); COMPILE_TIME_ASSERT(sizeof(LE32) == 4); -#if defined(__GNUC__) +#if defined(__GNUC__) || defined(__INTEL_COMPILER) COMPILE_TIME_ASSERT(__alignof__(BE16) == 1); COMPILE_TIME_ASSERT(__alignof__(BE32) == 1); COMPILE_TIME_ASSERT(__alignof__(LE16) == 1); diff --git a/src/mem.cpp b/src/mem.cpp index ac5227b8..39695f11 100644 --- a/src/mem.cpp +++ b/src/mem.cpp @@ -127,8 +127,9 @@ void MemBuffer::allocForUncompression(unsigned uncompressed_size, unsigned extra // **************************************************************************/ -#define MAGIC1(p) (((unsigned)(p) & 0xffffffff) ^ 0xfefdbeeb) -#define MAGIC2(p) (((unsigned)(p) & 0xffffffff) ^ 0xfefdbeeb ^ 0x80024001) +#define PTR(p) ((unsigned)(p) & 0xffffffff) +#define MAGIC1(p) (PTR(p) ^ 0xfefdbeeb) +#define MAGIC2(p) (PTR(p) ^ 0xfefdbeeb ^ 0x80024001) unsigned MemBuffer::global_alloc_counter = 0; diff --git a/src/mem.h b/src/mem.h index e79d0835..e6ad13b4 100644 --- a/src/mem.h +++ b/src/mem.h @@ -67,14 +67,7 @@ private: MemBuffer& operator= (MemBuffer const &); // { return *this; } // disable dynamic allocation -#ifndef new - static void *operator new (size_t); // {} - static void *operator new[] (size_t); // {} -#endif -#ifndef delete - //static void operator delete (void *) {} - //static void operator delete[] (void *) {} -#endif + DISABLE_NEW_DELETE }; #endif /* already included */ diff --git a/src/stdcxx.h b/src/stdcxx.h index 0f90e1b1..6c5ed40a 100644 --- a/src/stdcxx.h +++ b/src/stdcxx.h @@ -32,7 +32,54 @@ #ifdef __cplusplus -//#define NOTHROW throw() +#if !defined(NOTHROW) +# define NOTHROW throw() +#endif + + +/************************************************************************* +// disable dynamic allocation of an object +**************************************************************************/ + +#if defined(new) || defined(delete) + +// debug +# define DISABLE_NEW_DELETE + +#else + +# if 1 +# define DISABLE_NEW_DELETE_PLACEMENT_NEW \ + static void *operator new(size_t, void *); +# else +# define DISABLE_NEW_DELETE_PLACEMENT_NEW +# endif +# if defined(__GNUC__) && (__GNUC__ >= 3) +# define DISABLE_NEW_DELETE_PLACEMENT_DELETE \ + static void operator delete(void *, void *) NOTHROW { } +# elif defined(__INTEL_COMPILER) +# define DISABLE_NEW_DELETE_PLACEMENT_DELETE \ + static void operator delete(void *, void *) NOTHROW { } +# elif defined(_MSC_VER) && (_MSC_VER >= 1200) +# define DISABLE_NEW_DELETE_PLACEMENT_DELETE \ + static void operator delete(void *, void *) NOTHROW { } +# else +# define DISABLE_NEW_DELETE_PLACEMENT_DELETE +# endif + +# define DISABLE_NEW_DELETE \ +private: \ + static void *operator new(size_t); \ + static void *operator new[](size_t); \ + DISABLE_NEW_DELETE_PLACEMENT_NEW \ +protected: \ + static void operator delete(void *) NOTHROW { } \ + static void operator delete[](void *) NOTHROW { } \ + DISABLE_NEW_DELETE_PLACEMENT_DELETE \ +private: + +#endif + /************************************************************************* diff --git a/src/tailor.h b/src/tailor.h index 9992321a..d81fa6e9 100644 --- a/src/tailor.h +++ b/src/tailor.h @@ -134,7 +134,7 @@ # define HAVE_UTIME 1 #elif defined(__BORLANDC__) # if (__BORLANDC__ < 0x551) -# error "need Borland C 5.5.1 or newer" +# error "need Borland C++ 5.5.1 or newer" # endif # define __UPX_CDECL __cdecl # define SIGTYPEENTRY __cdecl @@ -157,12 +157,30 @@ # define HAVE_CHMOD 1 # define HAVE_UTIME 1 #elif defined(__INTEL_COMPILER) -# if (__INTEL_COMPILER >= 700) +# if (__INTEL_COMPILER < 700) +# error "need Intel C++ 7.0 or newer" +# endif +# if defined(_WIN32) +# define __UPX_CDECL __cdecl +# define SIGTYPEENTRY __cdecl +# define HAVE_CONIO_H 1 +# define HAVE_IO_H 1 +# define HAVE_MALLOC_H 1 +# define HAVE_SHARE_H 1 +# define HAVE_SYS_UTIME_H 1 +# define HAVE_CHMOD 1 +# define HAVE_UTIME 1 +# define HAVE_VSNPRINTF 1 +# define vsnprintf _vsnprintf +# else # pragma warning(disable: 810) // #810: conversion from "A" to "B" may lose significant bits # pragma warning(disable: 981) // #981: operands are evaluated in unspecified order # pragma warning(disable: 1418) // #1418: external definition with no prior declaration # endif #elif defined(_MSC_VER) +# if (_MSC_VER < 1100) +# error "need Visual C++ 5.0 or newer" +# endif # define __UPX_CDECL __cdecl # define SIGTYPEENTRY __cdecl # define HAVE_CONIO_H 1 @@ -184,7 +202,7 @@ # endif #elif defined(__WATCOMC__) # if (__WATCOMC__ < 1100) -# error "need Watcom C 11.0c or newer" +# error "need Watcom C++ 11.0c or newer" # define NO_BOOL 1 # endif # define __UPX_CDECL __cdecl diff --git a/src/ui.cpp b/src/ui.cpp index 47c03dc9..6074245d 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -158,7 +158,7 @@ static const char *mkline(unsigned long fu_len, unsigned long fc_len, strcpy(r, "999.99%"); #endif else - upx_snprintf(r, sizeof(r), "%3d.%02d%%", ratio / 10000, (ratio % 10000) / 100); + upx_snprintf(r, sizeof(r), "%3u.%02u%%", ratio / 10000, (ratio % 10000) / 100); if (decompress) f = "%10ld <-%10ld %7s %13s %s"; else