Minor cleanups.

This commit is contained in:
Markus F.X.J. Oberhumer
2016-09-20 22:14:25 +02:00
parent 535515f296
commit 3f7c1f966b
6 changed files with 29 additions and 45 deletions
+4 -10
View File
@@ -187,18 +187,16 @@ inline int sign_extend(unsigned v, unsigned bits)
{ {
const unsigned sign_bit = 1u << (bits - 1); const unsigned sign_bit = 1u << (bits - 1);
v &= sign_bit | (sign_bit - 1); v &= sign_bit | (sign_bit - 1);
//v = (v ^ sign_bit) - sign_bit;
v |= 0 - (v & sign_bit); v |= 0 - (v & sign_bit);
return (int) v; return ACC_ICAST(int, v);
} }
inline upx_int64_t sign_extend(upx_uint64_t v, unsigned bits) inline upx_int64_t sign_extend(upx_uint64_t v, unsigned bits)
{ {
const upx_uint64_t sign_bit = UPX_UINT64_C(1) << (bits - 1); const upx_uint64_t sign_bit = UPX_UINT64_C(1) << (bits - 1);
v &= sign_bit | (sign_bit - 1); v &= sign_bit | (sign_bit - 1);
//v = (v ^ sign_bit) - sign_bit;
v |= 0 - (v & sign_bit); v |= 0 - (v & sign_bit);
return (upx_int64_t) v; return ACC_ICAST(upx_int64_t, v);
} }
inline int get_be16_signed(const void *p) inline int get_be16_signed(const void *p)
@@ -282,12 +280,12 @@ inline unsigned acc_swap32p(const upx_uint32_t *p)
inline void acc_swab16s(upx_uint16_t *p) inline void acc_swab16s(upx_uint16_t *p)
{ {
*p = (upx_uint16_t) acc_swab16(*p); *p = ACC_ICONV(upx_uint16_t, acc_swab16(*p));
} }
inline void acc_swab32s(upx_uint32_t *p) inline void acc_swab32s(upx_uint32_t *p)
{ {
*p = (upx_uint32_t) acc_swab32(*p); *p = ACC_ICONV(upx_uint32_t, acc_swab32(*p));
} }
@@ -486,15 +484,12 @@ template <class T> T* operator - (T* ptr, const LE64& v);
// global overloads // global overloads
**************************************************************************/ **************************************************************************/
#if 1 && !defined(ALIGN_DOWN)
inline unsigned ALIGN_DOWN(unsigned a, const LE32& b) { return ALIGN_DOWN(a, (unsigned) b); } inline unsigned ALIGN_DOWN(unsigned a, const LE32& b) { return ALIGN_DOWN(a, (unsigned) b); }
inline unsigned ALIGN_DOWN(const LE32& a, unsigned b) { return ALIGN_DOWN((unsigned) a, b); } inline unsigned ALIGN_DOWN(const LE32& a, unsigned b) { return ALIGN_DOWN((unsigned) a, b); }
inline unsigned ALIGN_UP (unsigned a, const LE32& b) { return ALIGN_UP (a, (unsigned) b); } inline unsigned ALIGN_UP (unsigned a, const LE32& b) { return ALIGN_UP (a, (unsigned) b); }
inline unsigned ALIGN_UP (const LE32& a, unsigned b) { return ALIGN_UP ((unsigned) a, b); } inline unsigned ALIGN_UP (const LE32& a, unsigned b) { return ALIGN_UP ((unsigned) a, b); }
#endif
#if !defined(UPX_MAX)
inline unsigned UPX_MAX(unsigned a, const BE16& b) { return UPX_MAX(a, (unsigned) b); } inline unsigned UPX_MAX(unsigned a, const BE16& b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const BE16& a, unsigned b) { return UPX_MAX((unsigned) a, b); } inline unsigned UPX_MAX(const BE16& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const BE16& b) { return UPX_MIN(a, (unsigned) b); } inline unsigned UPX_MIN(unsigned a, const BE16& b) { return UPX_MIN(a, (unsigned) b); }
@@ -514,7 +509,6 @@ inline unsigned UPX_MAX(unsigned a, const LE32& b) { return UPX_MAX(a, (unsig
inline unsigned UPX_MAX(const LE32& a, unsigned b) { return UPX_MAX((unsigned) a, b); } inline unsigned UPX_MAX(const LE32& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const LE32& b) { return UPX_MIN(a, (unsigned) b); } inline unsigned UPX_MIN(unsigned a, const LE32& b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const LE32& a, unsigned b) { return UPX_MIN((unsigned) a, b); } inline unsigned UPX_MIN(const LE32& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
#endif
/************************************************************************* /*************************************************************************
+4 -3
View File
@@ -424,7 +424,8 @@ STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outS
#if (ACC_CC_INTELC_GNUC) #if (ACC_CC_INTELC_GNUC)
# pragma warning(disable: 424) // #424: extra ";" ignored //# pragma warning(disable: 424) // #424: extra ";" ignored
# pragma warning(error: 424) // #424: extra ";" ignored
#endif #endif
#if (WITH_LZMA >= 0x449) #if (WITH_LZMA >= 0x449)
@@ -530,8 +531,8 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
os.b_pos = 0; os.b_pos = 0;
// extra stuff in first byte: 5 high bits convenience for stub decompressor // extra stuff in first byte: 5 high bits convenience for stub decompressor
unsigned t = res->lit_context_bits + res->lit_pos_bits; unsigned t = res->lit_context_bits + res->lit_pos_bits;
os.WriteByte((t << 3) | res->pos_bits); os.WriteByte(Byte((t << 3) | res->pos_bits));
os.WriteByte((res->lit_pos_bits << 4) | (res->lit_context_bits)); os.WriteByte(Byte((res->lit_pos_bits << 4) | (res->lit_context_bits)));
#endif #endif
rh = enc.Code(&is, &os, NULL, NULL, &progress); rh = enc.Code(&is, &os, NULL, NULL, &progress);
+15 -25
View File
@@ -41,7 +41,10 @@
#endif #endif
#include "miniacc.h" #include "miniacc.h"
#if !(ACC_CC_CLANG || ACC_CC_GNUC) #if !(ACC_CC_CLANG || ACC_CC_GNUC)
# error "only clang and gcc are officially supported" // other compilers may work, but we're NOT interested into supporting them
#endif
#if !defined(UINT_MAX) || (UINT_MAX != 0xffffffffL)
# error "UINT_MAX"
#endif #endif
// FIXME - quick hack for arm-wince-gcc-3.4 (Debian pocketpc-*.deb packages) // FIXME - quick hack for arm-wince-gcc-3.4 (Debian pocketpc-*.deb packages)
@@ -81,6 +84,9 @@ typedef acc_uintptr_t upx_uintptr_t;
#define UPX_INT64_C ACC_INT64_C #define UPX_INT64_C ACC_INT64_C
#define UPX_UINT64_C ACC_UINT64_C #define UPX_UINT64_C ACC_UINT64_C
#define upx_byte unsigned char
#define upx_bytep upx_byte *
/************************************************************************* /*************************************************************************
// //
@@ -132,12 +138,6 @@ typedef acc_uintptr_t upx_uintptr_t;
# undef ucl_compress_config_t # undef ucl_compress_config_t
# undef ucl_compress_config_p # undef ucl_compress_config_p
#endif #endif
#if !defined(UINT_MAX) || (UINT_MAX < 0xffffffffL)
# error "UINT_MAX"
#endif
#define upx_byte unsigned char
#define upx_bytep upx_byte *
/************************************************************************* /*************************************************************************
@@ -245,25 +245,15 @@ typedef acc_uintptr_t upx_uintptr_t;
#endif #endif
#if (ACC_CC_CLANG || ACC_CC_GNUC || (ACC_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) || ACC_CC_PATHSCALE)
# define __packed_struct(s) struct s {
# define __packed_struct_end() } __attribute__((__packed__,__aligned__(1)));
#elif (ACC_CC_WATCOMC)
# define __packed_struct(s) _Packed struct s {
# define __packed_struct_end() };
#endif
#if !defined(__packed_struct)
# define __packed_struct(s) struct s {
# define __packed_struct_end() };
#endif
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
#define UNUSED(var) ACC_UNUSED(var) #define __packed_struct(s) __acc_struct_packed(s)
#define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e) #define __packed_struct_end() __acc_struct_packed_end()
#define UNUSED(var) ACC_UNUSED(var)
#define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e)
#define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \ #define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \ typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \
@@ -503,10 +493,10 @@ struct OptVar
// optional assignments // optional assignments
template <class T> inline void oassign(T& self, const T& other) { template <class T> inline void oassign(T &self, const T &other) {
if (other.is_set) { self.v = other.v; self.is_set += 1; } if (other.is_set) { self.v = other.v; self.is_set += 1; }
} }
template <class T> inline void oassign(unsigned& v, const T& other) { template <class T> inline void oassign(unsigned &v, const T &other) {
if (other.is_set) { v = other.v; } if (other.is_set) { v = other.v; }
} }
@@ -514,7 +504,7 @@ template <class T> inline void oassign(unsigned& v, const T& other) {
struct lzma_compress_config_t struct lzma_compress_config_t
{ {
typedef OptVar<unsigned, 2u, 0u, 4u> pos_bits_t; // pb typedef OptVar<unsigned, 2u, 0u, 4u> pos_bits_t; // pb
typedef OptVar<unsigned, 0u, 0u, 4u> lit_pos_bits_t; // lb typedef OptVar<unsigned, 0u, 0u, 4u> lit_pos_bits_t; // lp
typedef OptVar<unsigned, 3u, 0u, 8u> lit_context_bits_t; // lc typedef OptVar<unsigned, 3u, 0u, 8u> lit_context_bits_t; // lc
typedef OptVar<unsigned, (1u<<22), 1u, (1u<<30) > dict_size_t; typedef OptVar<unsigned, (1u<<22), 1u, (1u<<30) > dict_size_t;
typedef OptVar<unsigned, 64u, 5u, 273u> num_fast_bytes_t; typedef OptVar<unsigned, 64u, 5u, 273u> num_fast_bytes_t;
+1 -2
View File
@@ -200,8 +200,7 @@ public:
**************************************************************************/ **************************************************************************/
#undef NORET #undef NORET
#if 0 && defined(__GNUC__) #if 1 && defined(__GNUC__)
// (noreturn) is probably not the correct semantics for throwing exceptions
#define NORET __attribute__((__noreturn__)) #define NORET __attribute__((__noreturn__))
#else #else
#define NORET /*empty*/ #define NORET /*empty*/
+1 -1
View File
@@ -313,7 +313,7 @@ void ElfLinker::preprocessRelocations(char *start, char *end)
assert(add == ull); assert(add == ull);
assert(endptr && *endptr == '\0'); assert(endptr && *endptr == '\0');
if (sign == '-') if (sign == '-')
add = -add; add = 0 - add;
} }
addRelocation(section->name, offset, t, symbol, add); addRelocation(section->name, offset, t, symbol, add);
+4 -4
View File
@@ -222,18 +222,18 @@ void PackW32Pe::defineSymbols(unsigned ncsection, unsigned upxsection,
linker->defineSymbol("vp_size", ((addr & 0xfff) + 0x28 >= 0x1000) ? linker->defineSymbol("vp_size", ((addr & 0xfff) + 0x28 >= 0x1000) ?
0x2000 : 0x1000); // 2 pages or 1 page 0x2000 : 0x1000); // 2 pages or 1 page
linker->defineSymbol("vp_base", addr &~ 0xfff); // page mask linker->defineSymbol("vp_base", addr &~ 0xfff); // page mask
linker->defineSymbol("VirtualProtect", -rvamin + linker->defineSymbol("VirtualProtect", 0u-rvamin +
ilinkerGetAddress("kernel32.dll", "VirtualProtect")); ilinkerGetAddress("kernel32.dll", "VirtualProtect"));
} }
linker->defineSymbol("reloc_delt", 0u - (unsigned) ih.imagebase - rvamin); linker->defineSymbol("reloc_delt", 0u - (unsigned) ih.imagebase - rvamin);
linker->defineSymbol("start_of_relocs", crelocs); linker->defineSymbol("start_of_relocs", crelocs);
if (!isdll) if (!isdll)
linker->defineSymbol("ExitProcess", -rvamin + linker->defineSymbol("ExitProcess", 0u-rvamin +
ilinkerGetAddress("kernel32.dll", "ExitProcess")); ilinkerGetAddress("kernel32.dll", "ExitProcess"));
linker->defineSymbol("GetProcAddress", -rvamin + linker->defineSymbol("GetProcAddress", 0u-rvamin +
ilinkerGetAddress("kernel32.dll", "GetProcAddress")); ilinkerGetAddress("kernel32.dll", "GetProcAddress"));
linker->defineSymbol("kernel32_ordinals", myimport); linker->defineSymbol("kernel32_ordinals", myimport);
linker->defineSymbol("LoadLibraryA", -rvamin + linker->defineSymbol("LoadLibraryA", 0u-rvamin +
ilinkerGetAddress("kernel32.dll", "LoadLibraryA")); ilinkerGetAddress("kernel32.dll", "LoadLibraryA"));
linker->defineSymbol("start_of_imports", myimport); linker->defineSymbol("start_of_imports", myimport);
linker->defineSymbol("compressed_imports", cimports); linker->defineSymbol("compressed_imports", cimports);