From b2949259c5af524cc314ae8417ffd96f9346232c Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Tue, 27 May 2003 21:30:25 +0000 Subject: [PATCH] Portability updates. committer: mfx 1054071025 +0000 --- src/Makedefs.upx | 54 +++++++++++++++++++++++++++--------------------- src/bele.h | 24 ++++++++++----------- src/c_screen.cpp | 2 +- src/conf.h | 9 +++++++- src/main.cpp | 4 ++-- src/msg.cpp | 10 ++++++++- src/p_w32pe.cpp | 2 +- src/s_win32.cpp | 8 ++++--- src/snprintf.cpp | 8 +++---- src/snprintf.h | 8 +++---- src/stdcxx.cpp | 11 ++++++++++ src/stdcxx.h | 4 +++- src/util.cpp | 22 +++++++++++++------- 13 files changed, 105 insertions(+), 61 deletions(-) diff --git a/src/Makedefs.upx b/src/Makedefs.upx index 2d46751a..be714df8 100644 --- a/src/Makedefs.upx +++ b/src/Makedefs.upx @@ -149,7 +149,7 @@ ifeq ($(DEBUG),0) ##LDFLAGS += -static STUBEDIT_EXE = objcopy -S -R .comment -R .note $@ ifeq ($(arch),i386) - STUBIFY_EXE = perl $(srcdir)/stub/scripts/brandelf.pl $@ +## STUBIFY_EXE = perl $(srcdir)/stub/scripts/brandelf.pl $@ endif endif CHMOD_EXE = chmod 755 $@ @@ -158,7 +158,7 @@ endif # linux ### -### linux/i386 - Intel C++ 7.0 +### linux/i386 - Intel C++ 7.x ### ifeq ($(target),linux-intelc70) @@ -183,6 +183,30 @@ LDFLAGS += -Wl,-Map,$T.map endif +### +### linux/i386 - Borland C++ 5.7 (Kylix 3) +### + +ifeq ($(target),linux-bc57) +##DEPMODE := XXX_linux +CC = bc++ -q -3 +CFLAGS = -w -w-aus -w-inl -w! +CFLAGS_OUTPUT = -o$@ +LDFLAGS += -ls +LINK_EXE_OUTPUT = -e$@ +ifeq ($(WITH_ZLIB),1) +LDLIBS += -lz +endif +ifeq ($(DEBUG),1) + CFLAGS += -Od -d +else + CFLAGS += -O2 -d +endif +# transform `-lxx -lyy' into `libxx.a libyy.a' +LDLIBS := $(shell echo "$(LDLIBS)" | perl -pe 's/-l(.*?)\b/lib\1.a/g') +endif + + ### ### Linux cross compilers ### @@ -297,14 +321,14 @@ endif ### -### win32 - Borland C++ 5.5.1 +### win32 - Borland C++ ### ifeq ($(target),bc) o = .obj a = .lib e = .exe -CC = bcc32 -q -3 +CC = bcc32 -q -6 CFLAGS = -w -w-aus -w-inl -g1 CFLAGS_OUTPUT = -o$@ LDFLAGS = -ls @@ -326,7 +350,7 @@ endif # bc ### -### win32 - Digital Mars C++ 8.33 +### win32 - Digital Mars C++ ### ifeq ($(target),dm) @@ -356,7 +380,7 @@ endif # dm ### -### win32 - Intel C++ 7.0 +### win32 - Intel C++ ### ifeq ($(target),ic) @@ -390,7 +414,7 @@ endif # ic ### -### win32 - Visual C++ 6 +### win32 - Visual C++ ### ifeq ($(target),vc) @@ -524,17 +548,6 @@ distclean: clean maintainer-clean: distclean -untabify: - mfxtu -d4 -t *.ch *.cpp *.h - mfxtu -d8 -t stub/[ln]*.asm stub/*.ash stub/*.[cs] - -tags TAGS: - ctags *.ch *.cpp *.h - -ID: - mkid *.ch *.cpp *.h - - # /*********************************************************************** # // rules # ************************************************************************/ @@ -545,11 +558,6 @@ ID: %$o : %.cpp $(strip $(CXX_COMPILE)) -ifneq ($(strip $(OBJECTS2)),) -$(OBJECTS2): %$o : %.cpp - $(strip $(CXX_COMPILE)) -endif - %.res : %.rc rc -l 0x409 -fo$@ $< diff --git a/src/bele.h b/src/bele.h index bd53328a..d9366648 100644 --- a/src/bele.h +++ b/src/bele.h @@ -339,18 +339,18 @@ inline T* operator - (T* ptr, const LE32& v) { return ptr - (unsigned) v; } **************************************************************************/ // for use with qsort() -int be16_compare(const void *e1, const void *e2); -int be24_compare(const void *e1, const void *e2); -int be32_compare(const void *e1, const void *e2); -int le16_compare(const void *e1, const void *e2); -int le24_compare(const void *e1, const void *e2); -int le32_compare(const void *e1, const void *e2); -int be16_compare_signed(const void *e1, const void *e2); -int be24_compare_signed(const void *e1, const void *e2); -int be32_compare_signed(const void *e1, const void *e2); -int le16_compare_signed(const void *e1, const void *e2); -int le24_compare_signed(const void *e1, const void *e2); -int le32_compare_signed(const void *e1, const void *e2); +int __UPX_CDECL be16_compare(const void *e1, const void *e2); +int __UPX_CDECL be24_compare(const void *e1, const void *e2); +int __UPX_CDECL be32_compare(const void *e1, const void *e2); +int __UPX_CDECL le16_compare(const void *e1, const void *e2); +int __UPX_CDECL le24_compare(const void *e1, const void *e2); +int __UPX_CDECL le32_compare(const void *e1, const void *e2); +int __UPX_CDECL be16_compare_signed(const void *e1, const void *e2); +int __UPX_CDECL be24_compare_signed(const void *e1, const void *e2); +int __UPX_CDECL be32_compare_signed(const void *e1, const void *e2); +int __UPX_CDECL le16_compare_signed(const void *e1, const void *e2); +int __UPX_CDECL le24_compare_signed(const void *e1, const void *e2); +int __UPX_CDECL le32_compare_signed(const void *e1, const void *e2); // just for testing... diff --git a/src/c_screen.cpp b/src/c_screen.cpp index 6a749617..6caf93a3 100644 --- a/src/c_screen.cpp +++ b/src/c_screen.cpp @@ -88,7 +88,7 @@ static screen_t *do_construct(screen_t *s, int fd) static screen_t *screen = NULL; -static void do_destroy(void) +static void __UPX_CDECL do_destroy(void) { if (screen) { diff --git a/src/conf.h b/src/conf.h index 8df68658..f3b4bc1d 100644 --- a/src/conf.h +++ b/src/conf.h @@ -41,6 +41,9 @@ #endif #include "acc/acc.h" #include "acc/acc_ince.h" +#if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR) +# error "something pulled in " +#endif #if defined(__BORLANDC__) @@ -77,6 +80,7 @@ # endif # define __UPX_CDECL __cdecl # define SIGTYPEENTRY __cdecl +# pragma warning(disable: 4096) // __cdecl + '...' # pragma warning(disable: 4097) // W3: typedef-name 'A' used as synonym for class-name 'B' # pragma warning(disable: 4511) // W3: 'class': copy constructor could not be generated # pragma warning(disable: 4512) // W4: 'class': assignment operator could not be generated @@ -86,12 +90,15 @@ # if (__WATCOMC__ < 1100) # error "need Watcom C++ 11.0c or newer" # endif -# define __UPX_CDECL __cdecl # if defined(__cplusplus) # pragma warning 656 9 // w5: define this function inside its class definition (may improve code quality) # endif #endif +#if !defined(__UPX_CDECL) +# define __UPX_CDECL +#endif + /************************************************************************* // diff --git a/src/main.cpp b/src/main.cpp index 6215d226..d445763f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1034,7 +1034,7 @@ void upx_sanity_check(void) COMPILE_TIME_ASSERT(sizeof(LE16) == 2); COMPILE_TIME_ASSERT(sizeof(LE32) == 4); -#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#if defined(__GNUC__) || (ACC_CC_INTELC >= 700) COMPILE_TIME_ASSERT(__alignof__(BE16) == 1); COMPILE_TIME_ASSERT(__alignof__(BE32) == 1); COMPILE_TIME_ASSERT(__alignof__(LE16) == 1); @@ -1118,7 +1118,7 @@ void upx_sanity_check(void) #if !defined(WITH_GUI) -int main(int argc, char *argv[]) +int __UPX_CDECL main(int argc, char *argv[]) { int i; static char default_argv0[] = "upx"; diff --git a/src/msg.cpp b/src/msg.cpp index c70d3ff7..95b38d1c 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -116,8 +116,16 @@ void printErr(const char *iname, const Throwable *e) if (l < sizeof(buf) && e->getMsg()) upx_snprintf(buf+l, sizeof(buf)-l, ": %s", e->getMsg()); l = strlen(buf); - if (l < sizeof(buf) && e->getErrno()) + if (l < sizeof(buf) && e->getErrno()) { upx_snprintf(buf+l, sizeof(buf)-l, ": %s", strerror(e->getErrno())); +#if 1 + // some compilers (e.g. Borland C++) put a trailing '\n' + // into strerror() result + l = strlen(buf); + while (l-- > 0 && (buf[l] == '\n' || buf[l] == ' ')) + buf[l] = 0; +#endif + } pr_error(iname,buf,e->isWarning()); } diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index bac99e6d..c75a2c61 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -63,7 +63,7 @@ static const #if defined(__BORLANDC__) # undef strcpy -# define strcpy(a,b) std::strcpy((char *)(a),(const char *)(b)) +# define strcpy(a,b) strcpy((char *)(a),(const char *)(b)) #endif diff --git a/src/s_win32.cpp b/src/s_win32.cpp index 15002947..e75c1aed 100644 --- a/src/s_win32.cpp +++ b/src/s_win32.cpp @@ -42,10 +42,12 @@ // direct screen access **************************************************************************/ -#if defined(_MSC_VER) && (_MSC_VER < 1200) -# pragma warning(disable: 4201) // nonstandard extension used: nameless struct/union +#if (ACC_CC_MSC && _MSC_VER >= 1000 && _MSC_VER < 1200) + /* avoid -W4 warnings in */ +# pragma warning(disable: 4032) + /* avoid -W4 warnings in */ +# pragma warning(disable: 4201 4214 4514) #endif - #if defined(__RSXNT__) # define timeval win32_timeval /* struct timeval already in */ #endif diff --git a/src/snprintf.cpp b/src/snprintf.cpp index 3ddd0a8b..deaaf621 100644 --- a/src/snprintf.cpp +++ b/src/snprintf.cpp @@ -795,13 +795,13 @@ static int xdopr(char *buffer, size_t maxlen, const char *format, va_list args) } -int upx_vsnprintf(char *str, size_t count, const char *format, va_list ap) +int __UPX_CDECL upx_vsnprintf(char *str, size_t count, const char *format, va_list ap) { return xdopr(str, count, format, ap); } -int upx_snprintf(char *str, size_t count, const char *format,...) +int __UPX_CDECL upx_snprintf(char *str, size_t count, const char *format,...) { va_list ap; int ret; @@ -813,7 +813,7 @@ int upx_snprintf(char *str, size_t count, const char *format,...) } -int upx_vasprintf(char **ptr, const char *format, va_list ap) +int __UPX_CDECL upx_vasprintf(char **ptr, const char *format, va_list ap) { int ret; @@ -832,7 +832,7 @@ int upx_vasprintf(char **ptr, const char *format, va_list ap) } -int upx_asprintf(char **ptr, const char *format, ...) +int __UPX_CDECL upx_asprintf(char **ptr, const char *format, ...) { va_list ap; int ret; diff --git a/src/snprintf.h b/src/snprintf.h index c7423847..72273d6f 100644 --- a/src/snprintf.h +++ b/src/snprintf.h @@ -38,10 +38,10 @@ extern "C" { // **************************************************************************/ -int upx_vsnprintf(char *str, size_t count, const char *format, va_list ap); -int upx_snprintf(char *str, size_t count, const char *format,...); -int upx_vasprintf(char **ptr, const char *format, va_list ap); -int upx_asprintf(char **ptr, const char *format, ...); +int __UPX_CDECL upx_vsnprintf(char *str, size_t count, const char *format, va_list ap); +int __UPX_CDECL upx_snprintf(char *str, size_t count, const char *format,...); +int __UPX_CDECL upx_vasprintf(char **ptr, const char *format, va_list ap); +int __UPX_CDECL upx_asprintf(char **ptr, const char *format, ...); #if 1 # undef sprintf diff --git a/src/stdcxx.cpp b/src/stdcxx.cpp index 087c2f0f..a4dde5da 100644 --- a/src/stdcxx.cpp +++ b/src/stdcxx.cpp @@ -31,6 +31,17 @@ #include "stdcxx.h" +#if 0 +#undef _Nomemory +namespace std { +void __cdecl _Nomemory() { + static const bad_alloc ba; + throw ba; +} +} +#endif + + #ifdef WANT_STL #if defined(__GNUC__) diff --git a/src/stdcxx.h b/src/stdcxx.h index fc6ebd8d..1f86f8ef 100644 --- a/src/stdcxx.h +++ b/src/stdcxx.h @@ -114,7 +114,9 @@ class bad_alloc { }; #endif -#if defined(__EMX__) +#if defined(__BORLANDC__) +using namespace std; +#elif defined(__EMX__) #define std #elif defined(__WATCOMC__) #define std diff --git a/src/util.cpp b/src/util.cpp index 86c5e3d8..b476d70f 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -29,6 +29,12 @@ #include "conf.h" #include "util.h" +#if (ACC_CC_MSC && _MSC_VER >= 1000 && _MSC_VER < 1200) + /* avoid -W4 warnings in */ +# pragma warning(disable: 4032) + /* avoid -W4 warnings in */ +# pragma warning(disable: 4201 4214 4514) +#endif #include "acc/acc_lib.ch" @@ -36,28 +42,28 @@ // qsort() util **************************************************************************/ -int be16_compare(const void *e1, const void *e2) +int __UPX_CDECL be16_compare(const void *e1, const void *e2) { const unsigned d1 = get_be16(e1); const unsigned d2 = get_be16(e2); return (d1 < d2) ? -1 : ((d1 > d2) ? 1 : 0); } -int be32_compare(const void *e1, const void *e2) +int __UPX_CDECL be32_compare(const void *e1, const void *e2) { const unsigned d1 = get_be32(e1); const unsigned d2 = get_be32(e2); return (d1 < d2) ? -1 : ((d1 > d2) ? 1 : 0); } -int le16_compare(const void *e1, const void *e2) +int __UPX_CDECL le16_compare(const void *e1, const void *e2) { const unsigned d1 = get_le16(e1); const unsigned d2 = get_le16(e2); return (d1 < d2) ? -1 : ((d1 > d2) ? 1 : 0); } -int le32_compare(const void *e1, const void *e2) +int __UPX_CDECL le32_compare(const void *e1, const void *e2) { const unsigned d1 = get_le32(e1); const unsigned d2 = get_le32(e2); @@ -65,28 +71,28 @@ int le32_compare(const void *e1, const void *e2) } -int be16_compare_signed(const void *e1, const void *e2) +int __UPX_CDECL be16_compare_signed(const void *e1, const void *e2) { const int d1 = get_be16_signed(e1); const int d2 = get_be16_signed(e2); return (d1 < d2) ? -1 : ((d1 > d2) ? 1 : 0); } -int be32_compare_signed(const void *e1, const void *e2) +int __UPX_CDECL be32_compare_signed(const void *e1, const void *e2) { const int d1 = get_be32_signed(e1); const int d2 = get_be32_signed(e2); return (d1 < d2) ? -1 : ((d1 > d2) ? 1 : 0); } -int le16_compare_signed(const void *e1, const void *e2) +int __UPX_CDECL le16_compare_signed(const void *e1, const void *e2) { const int d1 = get_le16_signed(e1); const int d2 = get_le16_signed(e2); return (d1 < d2) ? -1 : ((d1 > d2) ? 1 : 0); } -int le32_compare_signed(const void *e1, const void *e2) +int __UPX_CDECL le32_compare_signed(const void *e1, const void *e2) { const int d1 = get_le32_signed(e1); const int d2 = get_le32_signed(e2);