From d045b7f223c59a6178d34774262ba8828bb31282 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sat, 2 Jan 2021 16:45:58 +0100 Subject: [PATCH] Update bele.h to better work with modern compilers. --- src/bele.h | 357 +++++++++++++++++++++++++--------------------- src/bele_policy.h | 40 +++--- src/conf.h | 25 ++++ src/main.cpp | 51 +++++-- src/p_lx_exc.cpp | 2 +- src/p_mach_enum.h | 11 +- src/p_vmlinz.cpp | 2 +- src/packer.cpp | 8 +- src/packer_c.cpp | 2 +- src/stdcxx.h | 1 + src/util.cpp | 1 - 11 files changed, 286 insertions(+), 214 deletions(-) diff --git a/src/bele.h b/src/bele.h index ef56f026..83757082 100644 --- a/src/bele.h +++ b/src/bele.h @@ -29,168 +29,240 @@ #ifndef __UPX_BELE_H #define __UPX_BELE_H 1 +// BE - Big Endian +// LE - Little Endian +// NE - Native Endiannes (aka host endianness) +// TE - Target Endiannes /************************************************************************* -// core +// core - NE +**************************************************************************/ + +__acc_static_forceinline unsigned get_ne16(const void *p) +{ + upx_uint16_t v = 0; + upx_memcpy_inline(&v, p, sizeof(v)); + return v; +} + +__acc_static_forceinline unsigned get_ne32(const void *p) +{ + upx_uint32_t v = 0; + upx_memcpy_inline(&v, p, sizeof(v)); + return v; +} + +__acc_static_forceinline upx_uint64_t get_ne64(const void *p) +{ + upx_uint64_t v = 0; + upx_memcpy_inline(&v, p, sizeof(v)); + return v; +} + +__acc_static_forceinline void set_ne16(void *p, unsigned vv) +{ + upx_uint16_t v = (upx_uint16_t) (vv & 0xffff); + upx_memcpy_inline(p, &v, sizeof(v)); +} + +__acc_static_forceinline void set_ne32(void *p, unsigned vv) +{ + upx_uint32_t v = vv; + upx_memcpy_inline(p, &v, sizeof(v)); +} + +__acc_static_forceinline void set_ne64(void *p, upx_uint64_t vv) +{ + upx_uint64_t v = vv; + upx_memcpy_inline(p, &v, sizeof(v)); +} + + +/************************************************************************* +// core - bswap +**************************************************************************/ + +#if (ACC_CC_MSC) + +ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) + +__acc_static_forceinline unsigned bswap16(unsigned v) +{ + return (unsigned) _byteswap_ulong(v << 16); +} +__acc_static_forceinline unsigned bswap32(unsigned v) +{ + return (unsigned) _byteswap_ulong(v); +} +__acc_static_forceinline upx_uint64_t bswap64(upx_uint64_t v) +{ + return _byteswap_uint64(v); +} + +#else + +__acc_static_forceinline constexpr unsigned bswap16(unsigned v) +{ + //return __builtin_bswap16((upx_uint16_t) v); + //return (unsigned) __builtin_bswap64((upx_uint64_t) v << 48); + return __builtin_bswap32(v << 16); +} +__acc_static_forceinline constexpr unsigned bswap32(unsigned v) +{ + //return (unsigned) __builtin_bswap64((upx_uint64_t) v << 32); + return __builtin_bswap32(v); +} +__acc_static_forceinline constexpr upx_uint64_t bswap64(upx_uint64_t v) +{ + return __builtin_bswap64(v); +} + +#endif + +__acc_static_forceinline constexpr unsigned no_bswap16(unsigned v) +{ + return v & 0xffff; // needed so that this is equivalent to bswap16() above +} + +__acc_static_forceinline constexpr unsigned no_bswap32(unsigned v) +{ + return v; +} + +__acc_static_forceinline constexpr upx_uint64_t no_bswap64(upx_uint64_t v) +{ + return v; +} + + +#if (ACC_ABI_BIG_ENDIAN) +# define ne16_to_be16(v) no_bswap16(v) +# define ne32_to_be32(v) no_bswap32(v) +# define ne64_to_be64(v) no_bswap64(v) +# define ne16_to_le16(v) bswap16(v) +# define ne32_to_le32(v) bswap32(v) +# define ne64_to_le64(v) bswap64(v) +#else +# define ne16_to_be16(v) bswap16(v) +# define ne32_to_be32(v) bswap32(v) +# define ne64_to_be64(v) bswap64(v) +# define ne16_to_le16(v) no_bswap16(v) +# define ne32_to_le32(v) no_bswap32(v) +# define ne64_to_le64(v) no_bswap64(v) +#endif + + +/************************************************************************* +// get/set 16/32/64 **************************************************************************/ inline unsigned get_be16(const void *p) { -#if defined(ACC_UA_GET_BE16) - return ACC_UA_GET_BE16(p); -#else - return acc_ua_get_be16(p); -#endif + return ne16_to_be16(get_ne16(p)); } inline void set_be16(void *p, unsigned v) { -#if defined(ACC_UA_SET_BE16) - ACC_UA_SET_BE16(p, v); -#else - acc_ua_set_be16(p, v); -#endif -} - -inline unsigned get_be24(const void *p) -{ -#if defined(ACC_UA_GET_BE24) - return ACC_UA_GET_BE24(p); -#else - return acc_ua_get_be24(p); -#endif -} - -inline void set_be24(void *p, unsigned v) -{ -#if defined(ACC_UA_SET_BE24) - ACC_UA_SET_BE24(p, v); -#else - acc_ua_set_be24(p, v); -#endif + set_ne16(p, ne16_to_be16(v)); } inline unsigned get_be32(const void *p) { -#if defined(ACC_UA_GET_BE32) - return ACC_UA_GET_BE32(p); -#else - return acc_ua_get_be32(p); -#endif + return ne32_to_be32(get_ne32(p)); } inline void set_be32(void *p, unsigned v) { -#if defined(ACC_UA_SET_BE32) - ACC_UA_SET_BE32(p, v); -#else - acc_ua_set_be32(p, v); -#endif + set_ne32(p, ne32_to_be32(v)); } inline upx_uint64_t get_be64(const void *p) { -#if defined(ACC_UA_GET_BE64) - return ACC_UA_GET_BE64(p); -#else - return acc_ua_get_be64(p); -#endif + return ne64_to_be64(get_ne64(p)); } inline void set_be64(void *p, upx_uint64_t v) { -#if defined(ACC_UA_SET_BE64) - ACC_UA_SET_BE64(p, v); -#else - acc_ua_set_be64(p, v); -#endif + set_ne64(p, ne64_to_be64(v)); } inline unsigned get_le16(const void *p) { -#if defined(ACC_UA_GET_LE16) - return ACC_UA_GET_LE16(p); -#else - return acc_ua_get_le16(p); -#endif + return ne16_to_le16(get_ne16(p)); } inline void set_le16(void *p, unsigned v) { -#if defined(ACC_UA_SET_LE16) - ACC_UA_SET_LE16(p, v); -#else - acc_ua_set_le16(p, v); -#endif -} - -inline unsigned get_le24(const void *p) -{ -#if defined(ACC_UA_GET_LE24) - return ACC_UA_GET_LE24(p); -#else - return acc_ua_get_le24(p); -#endif -} - -inline void set_le24(void *p, unsigned v) -{ -#if defined(ACC_UA_SET_LE24) - ACC_UA_SET_LE24(p, v); -#else - acc_ua_set_le24(p, v); -#endif -} - -inline unsigned get_le26(const void *p) -{ - const acc_hbyte_p b = ACC_CCAST(const acc_hbyte_p, p); - return ACC_ICONV(acc_uint32l_t, b[0] ) | ( ACC_ICONV(acc_uint32l_t, b[1]) << 8) | - (ACC_ICONV(acc_uint32l_t, b[2]) << 16) | (((ACC_ICONV(acc_uint32l_t, b[3]) & 3)<< 24)); -} - -inline void set_le26(void *p, unsigned v) -{ - acc_hbyte_p b = ACC_PCAST(acc_hbyte_p, p); - b[0] = ACC_ICONV(unsigned char, (v >> 0) & 0xff); - b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff); - b[2] = ACC_ICONV(unsigned char, (v >> 16) & 0xff); - b[3] = ACC_ICONV(unsigned char, (v >> 24) & 0x03) | (0xFC & b[3]); + set_ne16(p, ne16_to_le16(v)); } inline unsigned get_le32(const void *p) { -#if defined(ACC_UA_GET_LE32) - return ACC_UA_GET_LE32(p); -#else - return acc_ua_get_le32(p); -#endif + return ne32_to_le32(get_ne32(p)); } inline void set_le32(void *p, unsigned v) { -#if defined(ACC_UA_SET_LE32) - ACC_UA_SET_LE32(p, v); -#else - acc_ua_set_le32(p, v); -#endif + set_ne32(p, ne32_to_le32(v)); } inline upx_uint64_t get_le64(const void *p) { -#if defined(ACC_UA_GET_LE64) - return ACC_UA_GET_LE64(p); -#else - return acc_ua_get_le64(p); -#endif + return ne64_to_le64(get_ne64(p)); } inline void set_le64(void *p, upx_uint64_t v) { -#if defined(ACC_UA_SET_LE64) - ACC_UA_SET_LE64(p, v); + set_ne64(p, ne64_to_le64(v)); +} + + +/************************************************************************* +// get/set 24/26 +**************************************************************************/ + +inline unsigned get_be24(const void *p) +{ + const unsigned char *b = ACC_CCAST(const unsigned char *, p); + return (b[0] << 16) | (b[1] << 8) | (b[2] << 0); +} + +inline void set_be24(void *p, unsigned v) +{ + unsigned char *b = ACC_PCAST(unsigned char *, p); + b[0] = ACC_ICONV(unsigned char, (v >> 16) & 0xff); + b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff); + b[2] = ACC_ICONV(unsigned char, (v >> 0) & 0xff); +} + +inline unsigned get_le24(const void *p) +{ + const unsigned char *b = ACC_CCAST(const unsigned char *, p); + return (b[0] << 0) | (b[1] << 8) | (b[2] << 16); +} + +inline void set_le24(void *p, unsigned v) +{ + unsigned char *b = ACC_PCAST(unsigned char *, p); + b[0] = ACC_ICONV(unsigned char, (v >> 0) & 0xff); + b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff); + b[2] = ACC_ICONV(unsigned char, (v >> 16) & 0xff); +} + + +inline unsigned get_le26(const void *p) +{ + return get_le32(p) & 0x03ffffff; +} + +inline void set_le26(void *p, unsigned v) +{ + // preserve the top 6 bits +#if 0 + set_le32(p, (get_le32(p) & 0xfc000000) | (v & 0x03ffffff)); #else - acc_ua_set_le64(p, v); + // optimized version, saving a bswap32 + set_ne32(p, (get_ne32(p) & ne32_to_le32(0xfc000000)) | ne32_to_le32(v & 0x03ffffff)); #endif } @@ -264,58 +336,6 @@ inline upx_int64_t get_le64_signed(const void *p) } -/************************************************************************* -// swab (bswap) -**************************************************************************/ - -inline unsigned acc_swab16(unsigned v) -{ - return ((v & 0x00ff) << 8) | - ((v & 0xff00) >> 8); -} - -inline unsigned acc_swab32(unsigned v) -{ - return ((v & 0x000000ff) << 24) | - ((v & 0x0000ff00) << 8) | - ((v & 0x00ff0000) >> 8) | - ((v & 0xff000000) >> 24); -} - - -inline unsigned acc_swab16p(const upx_uint16_t *p) -{ - return acc_swab16(*p); -} - -inline unsigned acc_swap32p(const upx_uint32_t *p) -{ - return acc_swab32(*p); -} - - -inline void acc_swab16s(upx_uint16_t *p) -{ - *p = ACC_ICONV(upx_uint16_t, acc_swab16(*p)); -} - -inline void acc_swab32s(upx_uint32_t *p) -{ - *p = ACC_ICONV(upx_uint32_t, acc_swab32(*p)); -} - - -inline void acc_ua_swab16s(void *p) -{ - set_be16(p, get_le16(p)); -} - -inline void acc_ua_swab32s(void *p) -{ - set_be32(p, get_le32(p)); -} - - /************************************************************************* // classes for portable unaligned access // @@ -435,6 +455,17 @@ __packed_struct(LE64) __packed_struct_end() +#if (ACC_ABI_BIG_ENDIAN) +typedef BE16 NE16; +typedef BE32 NE32; +typedef BE64 NE64; +#else +typedef LE16 NE16; +typedef LE32 NE32; +typedef LE64 NE64; +#endif + + /************************************************************************* // global operators **************************************************************************/ diff --git a/src/bele_policy.h b/src/bele_policy.h index af0a8d71..2d712e92 100644 --- a/src/bele_policy.h +++ b/src/bele_policy.h @@ -68,10 +68,10 @@ struct AbstractPolicy V void set32(void *p, unsigned v) C = 0; V void set64(void *p, upx_uint64_t v) C = 0; - V unsigned get16_signed(const void *p) C = 0; - V unsigned get24_signed(const void *p) C = 0; - V unsigned get32_signed(const void *p) C = 0; - V upx_uint64_t get64_signed(const void *p) C = 0; + V int get16_signed(const void *p) C = 0; + V int get24_signed(const void *p) C = 0; + V int get32_signed(const void *p) C = 0; + V upx_int64_t get64_signed(const void *p) C = 0; S u16_compare(const void *a, const void *b) C = 0; S u24_compare(const void *a, const void *b) C = 0; @@ -125,14 +125,14 @@ struct BEPolicy V void set64(void *p, upx_uint64_t v) C { set_be64(p, v); } - V unsigned get16_signed(const void *p) C - { return (unsigned)get_be16_signed(p); } - V unsigned get24_signed(const void *p) C - { return (unsigned)get_be24_signed(p); } - V unsigned get32_signed(const void *p) C - { return (unsigned)get_be32_signed(p); } - V upx_uint64_t get64_signed(const void *p) C - { return (upx_uint64_t)get_be64_signed(p); } + V int get16_signed(const void *p) C + { return get_be16_signed(p); } + V int get24_signed(const void *p) C + { return get_be24_signed(p); } + V int get32_signed(const void *p) C + { return get_be32_signed(p); } + V upx_int64_t get64_signed(const void *p) C + { return get_be64_signed(p); } S u16_compare(const void *a, const void *b) C { return be16_compare(a, b); } @@ -202,14 +202,14 @@ struct LEPolicy V void set64(void *p, upx_uint64_t v) C { set_le64(p, v); } - V unsigned get16_signed(const void *p) C - { return (unsigned)get_le16_signed(p); } - V unsigned get24_signed(const void *p) C - { return (unsigned)get_le24_signed(p); } - V unsigned get32_signed(const void *p) C - { return (unsigned)get_le32_signed(p); } - V upx_uint64_t get64_signed(const void *p) C - { return (upx_uint64_t)get_le64_signed(p); } + V int get16_signed(const void *p) C + { return get_le16_signed(p); } + V int get24_signed(const void *p) C + { return get_le24_signed(p); } + V int get32_signed(const void *p) C + { return get_le32_signed(p); } + V upx_int64_t get64_signed(const void *p) C + { return get_le64_signed(p); } S u16_compare(const void *a, const void *b) C { return le16_compare(a, b); } diff --git a/src/conf.h b/src/conf.h index f7c8a647..e268b7b8 100644 --- a/src/conf.h +++ b/src/conf.h @@ -64,6 +64,8 @@ #if !defined(UINT_MAX) || (UINT_MAX != 0xffffffffL) # error "UINT_MAX" #endif +ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_BIT == 8) +ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(short) == 2) ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4) ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(long long) == 8) // check sane compiler mandatory flags @@ -274,6 +276,21 @@ typedef size_t upx_rsize_t; // **************************************************************************/ +#if !defined(__has_builtin) +# define __has_builtin(x) 0 +#endif + +#if __has_builtin(__builtin_memcpy_inline) +# define upx_memcpy_inline __builtin_memcpy_inline +#elif __has_builtin(__builtin_memcpy) +# define upx_memcpy_inline __builtin_memcpy +#elif defined(__GNUC__) +# define upx_memcpy_inline __builtin_memcpy +#else +# define upx_memcpy_inline memcpy +#endif + + #if (ACC_CC_MSC) #define __packed_struct(s) struct s { #define __packed_struct_end() }; @@ -325,6 +342,7 @@ inline const T& UPX_MIN(const T& a, const T& b) { if (a < b) return a; return b; #define ByteArray(var, size) Array(unsigned char, var, size) + class noncopyable { protected: @@ -659,6 +677,13 @@ struct upx_compress_result_t #include "util.h" #include "console.h" +ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same::value)) +ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same::value)) +ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same::value)) +ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same::value)) +ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same::value)) +ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same::value)) + // classes class ElfLinker; diff --git a/src/main.cpp b/src/main.cpp index 7895f433..67ebdd56 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1251,7 +1251,7 @@ static void first_options(int argc, char **argv) **************************************************************************/ template struct TestBELE { -static bool test(void) +__acc_static_noinline bool test(void) { COMPILE_TIME_ASSERT_ALIGNED1(T) __packed_struct(test1_t) char a; T b; __packed_struct_end() @@ -1267,7 +1267,7 @@ static bool test(void) COMPILE_TIME_ASSERT(__acc_alignof(t1) == 1) COMPILE_TIME_ASSERT(__acc_alignof(t2) == 1) #endif -#if 1 && !defined(UPX_OFFICIAL_BUILD) +#if 1 T allbits; allbits = 0; allbits -= 1; //++allbits; allbits++; --allbits; allbits--; T v1; v1 = 1; v1 *= 2; v1 -= 1; @@ -1288,11 +1288,11 @@ static bool test(void) return true; }}; -template struct TestNoStrictAliasingStruct { - __acc_static_noinline bool test(A *a, B *b) { *a = 0; *b = (B)((B)0-1); return *a != 0; } +template struct TestNoAliasingStruct { + __acc_static_noinline bool test(A *a, B *b) { *a = 0; *b = 0; *b -= 3; return *a != 0; } }; -template static inline bool testNoStrictAliasing(A *a, B *b) { - return TestNoStrictAliasingStruct::test(a, b); +template __acc_static_forceinline bool testNoAliasing(A *a, B *b) { + return TestNoAliasingStruct::test(a, b); } template struct TestIntegerWrap { static inline bool inc(T x) { return x + 1 > x; } @@ -1359,15 +1359,12 @@ void upx_compiler_sanity_check(void) assert(TestBELE::test()); assert(TestBELE::test()); { - static const unsigned char dd[32] -#if 1 && (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) && defined(__ELF__) - __attribute__((__aligned__(16))) -#endif - = { 0, 0, 0, 0, 0, 0, 0, + alignas(16) static const unsigned char dd[32] = { + 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0, 0, 0, 0, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78, - 0, 0, 0, 0, 0 }; + 0, 0, 0, 0, 0 }; const unsigned char *d; const N_BELE_RTP::AbstractPolicy *bele; d = dd + 7; @@ -1405,10 +1402,34 @@ void upx_compiler_sanity_check(void) assert(get_be32_signed(d) == 2138996092); assert(get_be64_signed(d) == UPX_INT64_C(9186918263483431288)); } + { + unsigned dd; + void *d = ⅆ + dd = ne32_to_le32(0xf7f6f5f4); + assert(get_le26(d) == 0x03f6f5f4); + set_le26(d, 0); + assert(get_le26(d) == 0); + assert(dd == ne32_to_le32(0xf4000000)); + set_le26(d, 0xff020304); + assert(get_le26(d) == 0x03020304); + assert(dd == ne32_to_le32(0xf7020304)); + } +#endif + union { + short v_short; int v_int; long v_long; long long v_llong; + BE16 b16; BE32 b32; BE64 b64; LE16 l16; LE32 l32; LE64 l64; + } u; + assert(testNoAliasing(&u.v_short, &u.b32)); + assert(testNoAliasing(&u.v_short, &u.l32)); + assert(testNoAliasing(&u.v_int, &u.b64)); + assert(testNoAliasing(&u.v_int, &u.l64)); +#if 0 + // check working -fno-strict-aliasing + assert(testNoAliasing(&u.v_short, &u.v_int)); + assert(testNoAliasing(&u.v_int, &u.v_long)); + assert(testNoAliasing(&u.v_int, &u.v_llong)); + assert(testNoAliasing(&u.v_long, &u.v_llong)); #endif - - union { short v_short; int v_int; long v_long; } u; - assert(testNoStrictAliasing(&u.v_short, &u.v_long)); assert( TestIntegerWrap::inc(0)); assert(!TestIntegerWrap::inc(INT_MAX)); diff --git a/src/p_lx_exc.cpp b/src/p_lx_exc.cpp index 984fa5ec..ee74f521 100644 --- a/src/p_lx_exc.cpp +++ b/src/p_lx_exc.cpp @@ -380,7 +380,7 @@ PackLinuxI386::buildLinuxLoader( (res->lit_pos_bits << 8) | (res->pos_bits << 16); if (linker->bele->isBE()) // big endian - bswap32 - acc_swab32s(&properties); + properties = bswap32(properties); linker->defineSymbol("lzma_properties", properties); // -2 for properties linker->defineSymbol("lzma_c_len", ph.c_len - 2); diff --git a/src/p_mach_enum.h b/src/p_mach_enum.h index 11ba4ac1..98acc19a 100644 --- a/src/p_mach_enum.h +++ b/src/p_mach_enum.h @@ -35,13 +35,9 @@ #ifdef WANT_MACH_HEADER_ENUM /*{*/ #undef WANT_MACH_HEADER_ENUM -# if 0 - enum { // magic + enum : unsigned { // magic MH_MAGIC = 0xfeedface }; -# else - static const unsigned MH_MAGIC = 0xfeedface; -# endif enum { // cputype CPU_TYPE_I386 = 7, CPU_TYPE_X86_64 = 0x01000007, @@ -138,9 +134,8 @@ S_16BYTE_LITERALS, S_DTRACE_DOF }; - static const unsigned S_ATTR_PURE_INSTRUCTIONS = 0x80000000; - enum { // section flags (high 24 bits) - //S_ATTR_PURE_INSTRUCTIONS = 0x80000000, + enum : unsigned { // section flags (high 24 bits) + S_ATTR_PURE_INSTRUCTIONS = 0x80000000, S_ATTR_NO_TOC = 0x40000000, S_ATTR_STRIP_STATIC_SYMS = 0x20000000, S_ATTR_NO_DEAD_STRIP = 0x10000000, diff --git a/src/p_vmlinz.cpp b/src/p_vmlinz.cpp index d01db70c..ea5d06d5 100644 --- a/src/p_vmlinz.cpp +++ b/src/p_vmlinz.cpp @@ -595,7 +595,7 @@ void PackBvmlinuzI386::pack(OutputFile *fo) (res->lit_pos_bits << 8) | (res->pos_bits << 16); if (linker->bele->isBE()) // big endian - bswap32 - acc_swab32s(&properties); + properties = bswap32(properties); linker->defineSymbol("lzma_properties", properties); // -2 for properties linker->defineSymbol("lzma_c_len", ph.c_len - 2); diff --git a/src/packer.cpp b/src/packer.cpp index 5914a99e..b35d9244 100644 --- a/src/packer.cpp +++ b/src/packer.cpp @@ -961,7 +961,7 @@ upx_byte *Packer::optimizeReloc(upx_byte *in, unsigned relocnum, if (bswap) { if (bits == 32) - acc_ua_swab32s(image + pc); + set_be32(image + pc, get_le32(image + pc)); else if (bits == 64) set_be64(image + pc, get_le64(image + pc)); else @@ -1027,15 +1027,15 @@ unsigned Packer::unoptimizeReloc(upx_byte **in, upx_byte *image, if (bswap && image) { if (bits == 32) { - acc_ua_swab32s(image + jc); - if ((unsigned long)(p - (image + jc)) < 4) { + set_be32(image + jc, get_le32(image + jc)); + if ((size_t)(p - (image + jc)) < 4) { // data must not overlap control p = (4 - 1) + image + jc; // -1: 'for' also increments } } else if (bits == 64) { set_be64(image + jc, get_le64(image + jc)); - if ((unsigned long)(p - (image + jc)) < 8) { + if ((size_t)(p - (image + jc)) < 8) { // data must not overlap control p = (8 - 1) + image + jc; // -1: 'for' also increments } diff --git a/src/packer_c.cpp b/src/packer_c.cpp index d4de0c64..4a0f70e5 100644 --- a/src/packer_c.cpp +++ b/src/packer_c.cpp @@ -277,7 +277,7 @@ void Packer::defineDecompressorSymbols() (res->lit_pos_bits << 8) | (res->pos_bits << 16); if (linker->bele->isBE()) // big endian - bswap32 - acc_swab32s(&properties); + properties = bswap32(properties); linker->defineSymbol("lzma_properties", properties); // len - 2 because of properties diff --git a/src/stdcxx.h b/src/stdcxx.h index 7048a86e..9d76372f 100644 --- a/src/stdcxx.h +++ b/src/stdcxx.h @@ -38,6 +38,7 @@ #include #include +#include #include /************************************************************************* diff --git a/src/util.cpp b/src/util.cpp index 4da37827..0367f06d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -39,7 +39,6 @@ #define ACC_WANT_ACCLIB_GETOPT 1 #define ACC_WANT_ACCLIB_HSREAD 1 #define ACC_WANT_ACCLIB_MISC 1 -#define ACC_WANT_ACCLIB_UA 1 #define ACC_WANT_ACCLIB_WILDARGV 1 #undef HAVE_MKDIR #include "miniacc.h"