diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d130496..91c8fd50 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -220,7 +220,7 @@ jobs: # NOTE: macos does not have "env -C"; only with brew coreutils - { os: macos-13, gcc: gcc-12, gxx: g++-12, testsuite: true } - { os: macos-14, gcc: gcc-13, gxx: g++-13, testsuite: true } - # { os: macos-15, gcc: gcc-13, gxx: g++-13, testsuite: true } + # { os: macos-15, gcc: gcc-14, gxx: g++-14, testsuite: true } - { os: macos-15, testsuite: true } name: ${{ format('{0} {1}{2}', matrix.os, matrix.xcode_version && 'xcode-' || '', matrix.xcode_version) }} runs-on: ${{ matrix.os }} @@ -525,6 +525,7 @@ jobs: include: # only build a few selected targets => more targets are tested in the Weekly CI - { zig_target: aarch64-linux-musl, qemu: qemu-aarch64 } + - { zig_target: aarch64-linux-musl, qemu: qemu-aarch64, zig_pic: -fPIE } - { zig_target: aarch64-macos.11.0-none } - { zig_target: aarch64-windows-gnu } - { zig_target: arm-linux-musleabihf, qemu: qemu-arm } @@ -543,7 +544,9 @@ jobs: # { zig_target: mips-linux-musleabi-mips32r6, zig_flags: -march=mips32r6, qemu: qemu-mips } - { zig_target: powerpc-linux-musleabihf, qemu: qemu-ppc } - { zig_target: powerpc64-linux-musl, qemu: qemu-ppc64 } + - { zig_target: powerpc64-linux-musl, qemu: qemu-ppc64, zig_pic: -fPIE } - { zig_target: powerpc64le-linux-musl, qemu: qemu-ppc64le } + - { zig_target: powerpc64le-linux-musl, qemu: qemu-ppc64le, zig_pic: -fPIE } - { zig_target: x86_64-linux-gnu.2.3.4, qemu: qemu-x86_64 } # can use QEMU because of gcompat - { zig_target: x86_64-linux-gnu.2.17, qemu: qemu-x86_64 } # can use QEMU because of gcompat - { zig_target: x86_64-linux-musl, qemu: qemu-x86_64 } diff --git a/.gitignore b/.gitignore index d9271987..64d88162 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /.cache* +/.idea/ /.hg* /.vscode* +/.zed/ /CMakeCache* /CMakeFiles* /CTest* diff --git a/CMakeLists.txt b/CMakeLists.txt index 963ca9ee..55614ed4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,9 @@ upx_cmake_include_hook(2_init) # Disallow in-source build. Note that you will still have to manually # clean up a few files if you accidentally try an in-source build. -upx_disallow_in_source_build() +if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git") + upx_disallow_in_source_build() +endif() # global settings if(${CMAKE_VERSION} VERSION_GREATER "3.14.99" AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY) diff --git a/src/bele.h b/src/bele.h index 2529f3a1..718f9396 100644 --- a/src/bele.h +++ b/src/bele.h @@ -32,8 +32,9 @@ // NE - Native Endianness (aka Host Endianness aka CPU Endianness) // TE - Target Endianness (not used here, see various packers) -static_assert(std::is_same_v); static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); #if defined(upx_is_constant_evaluated) #define bele_constexpr constexpr @@ -411,7 +412,7 @@ inline bele_constexpr void set_le14_5(XE32 *p, unsigned v) noexcept { // get signed values **************************************************************************/ -forceinline constexpr int sign_extend(unsigned v, unsigned bits) noexcept { +forceinline constexpr int sign_extend32(unsigned v, unsigned bits) noexcept { #if (ACC_ARCH_M68K) // no barrel shifter const unsigned sign_bit = 1u << (bits - 1); return ACC_ICAST(int, (v & (sign_bit - 1)) - (v & sign_bit)); @@ -420,7 +421,7 @@ forceinline constexpr int sign_extend(unsigned v, unsigned bits) noexcept { #endif } -forceinline constexpr upx_int64_t sign_extend(upx_uint64_t v, unsigned bits) noexcept { +forceinline constexpr upx_int64_t sign_extend64(upx_uint64_t v, unsigned bits) noexcept { #if (ACC_ARCH_M68K) // no barrel shifter const upx_uint64_t sign_bit = upx_uint64_t(1) << (bits - 1); return ACC_ICAST(upx_int64_t, (v & (sign_bit - 1)) - (v & sign_bit)); @@ -432,49 +433,49 @@ forceinline constexpr upx_int64_t sign_extend(upx_uint64_t v, unsigned bits) noe REQUIRE_XE16 inline bele_constexpr int get_be16_signed(const XE16 *p) noexcept { unsigned v = get_be16(p); - return sign_extend(v, 16); + return sign_extend32(v, 16); } REQUIRE_XE24 inline bele_constexpr int get_be24_signed(const XE24 *p) noexcept { unsigned v = get_be24(p); - return sign_extend(v, 24); + return sign_extend32(v, 24); } REQUIRE_XE32 inline bele_constexpr int get_be32_signed(const XE32 *p) noexcept { unsigned v = get_be32(p); - return sign_extend(v, 32); + return sign_extend32(v, 32); } REQUIRE_XE64 inline bele_constexpr upx_int64_t get_be64_signed(const XE64 *p) noexcept { upx_uint64_t v = get_be64(p); - return sign_extend(v, 64); + return sign_extend64(v, 64); } REQUIRE_XE16 inline bele_constexpr int get_le16_signed(const XE16 *p) noexcept { unsigned v = get_le16(p); - return sign_extend(v, 16); + return sign_extend32(v, 16); } REQUIRE_XE24 inline bele_constexpr int get_le24_signed(const XE24 *p) noexcept { unsigned v = get_le24(p); - return sign_extend(v, 24); + return sign_extend32(v, 24); } REQUIRE_XE32 inline bele_constexpr int get_le32_signed(const XE32 *p) noexcept { unsigned v = get_le32(p); - return sign_extend(v, 32); + return sign_extend32(v, 32); } REQUIRE_XE64 inline bele_constexpr upx_int64_t get_le64_signed(const XE64 *p) noexcept { upx_uint64_t v = get_le64(p); - return sign_extend(v, 64); + return sign_extend64(v, 64); } /************************************************************************* diff --git a/src/check/dt_check.cpp b/src/check/dt_check.cpp index 2d8b1525..e148d997 100644 --- a/src/check/dt_check.cpp +++ b/src/check/dt_check.cpp @@ -283,18 +283,18 @@ static_assert(bswap32(bswap32(0xf4f3f2f1)) == no_bswap32(0xf4f3f2f1)); static_assert(bswap64(bswap64(0xf8f7f6f5f4f3f2f1ull)) == no_bswap64(0xf8f7f6f5f4f3f2f1ull)); #endif -static_assert(sign_extend(0u + 0, 8) == 0); -static_assert(sign_extend(0u + 1, 8) == 1); -static_assert(sign_extend(0u + 127, 8) == 127); -static_assert(sign_extend(0u + 128, 8) == -128); -static_assert(sign_extend(0u - 1, 8) == -1); -static_assert(sign_extend(0u + 256, 8) == 0); -static_assert(sign_extend(0u + 257, 8) == 1); -static_assert(sign_extend(0u + 383, 8) == 127); -static_assert(sign_extend(0u + 384, 8) == -128); -static_assert(sign_extend(0u + 511, 8) == -1); -static_assert(sign_extend(upx_uint64_t(0) + 0, 1) == 0); -static_assert(sign_extend(upx_uint64_t(0) + 1, 1) == -1); +static_assert(sign_extend32(0u + 0, 8) == 0); +static_assert(sign_extend32(0u + 1, 8) == 1); +static_assert(sign_extend32(0u + 127, 8) == 127); +static_assert(sign_extend32(0u + 128, 8) == -128); +static_assert(sign_extend32(0u - 1, 8) == -1); +static_assert(sign_extend32(0u + 256, 8) == 0); +static_assert(sign_extend32(0u + 257, 8) == 1); +static_assert(sign_extend32(0u + 383, 8) == 127); +static_assert(sign_extend32(0u + 384, 8) == -128); +static_assert(sign_extend32(0u + 511, 8) == -1); +static_assert(sign_extend64(upx_uint64_t(0) + 0, 1) == 0); +static_assert(sign_extend64(upx_uint64_t(0) + 1, 1) == -1); static_assert(CHAR_BIT == 8); #if 0 // does not work with MSVC @@ -1212,29 +1212,33 @@ void upx_compiler_sanity_check(void) noexcept { for (int i = 0; i < 256; i++) { { const unsigned u = i; - assert_noexcept(sign_extend(u, 1) == ((i & 1) ? -1 : 0)); - assert_noexcept(sign_extend(u, 2) == ((i & 2) ? -2 + (i & 1) : (i & 1))); - assert_noexcept(sign_extend(u, 3) == ((i & 4) ? -4 + (i & 3) : (i & 3))); - assert_noexcept(sign_extend(u, 4) == ((i & 8) ? -8 + (i & 7) : (i & 7))); - assert_noexcept(sign_extend(u, 5) == ((i & 16) ? -16 + (i & 15) : (i & 15))); - assert_noexcept(sign_extend(u, 6) == ((i & 32) ? -32 + (i & 31) : (i & 31))); - assert_noexcept(sign_extend(u, 7) == ((i & 64) ? -64 + (i & 63) : (i & 63))); - assert_noexcept(sign_extend(u, 8) == ((i & 128) ? -128 + (i & 127) : (i & 127))); - assert_noexcept(sign_extend(u, 32) == i); - assert_noexcept(sign_extend(0u - u, 32) == -i); + assert_noexcept(sign_extend32(u, 1) == ((i & 1) ? -1 : 0)); + assert_noexcept(sign_extend32(u, 2) == ((i & 2) ? -2 + (i & 1) : (i & 1))); + assert_noexcept(sign_extend32(u, 3) == ((i & 4) ? -4 + (i & 3) : (i & 3))); + assert_noexcept(sign_extend32(u, 4) == ((i & 8) ? -8 + (i & 7) : (i & 7))); + assert_noexcept(sign_extend32(u, 5) == ((i & 16) ? -16 + (i & 15) : (i & 15))); + assert_noexcept(sign_extend32(u, 6) == ((i & 32) ? -32 + (i & 31) : (i & 31))); + assert_noexcept(sign_extend32(u, 7) == ((i & 64) ? -64 + (i & 63) : (i & 63))); + assert_noexcept(sign_extend32(u, 8) == ((i & 128) ? -128 + (i & 127) : (i & 127))); + assert_noexcept(sign_extend32(u, 9) == i); + assert_noexcept(sign_extend32(u, 32) == i); + assert_noexcept(sign_extend32(0u - u, 32) == -i); } { const upx_uint64_t u = i; - assert_noexcept(sign_extend(u, 1) == ((i & 1) ? -1 : 0)); - assert_noexcept(sign_extend(u, 2) == ((i & 2) ? -2 + (i & 1) : (i & 1))); - assert_noexcept(sign_extend(u, 3) == ((i & 4) ? -4 + (i & 3) : (i & 3))); - assert_noexcept(sign_extend(u, 4) == ((i & 8) ? -8 + (i & 7) : (i & 7))); - assert_noexcept(sign_extend(u, 5) == ((i & 16) ? -16 + (i & 15) : (i & 15))); - assert_noexcept(sign_extend(u, 6) == ((i & 32) ? -32 + (i & 31) : (i & 31))); - assert_noexcept(sign_extend(u, 7) == ((i & 64) ? -64 + (i & 63) : (i & 63))); - assert_noexcept(sign_extend(u, 8) == ((i & 128) ? -128 + (i & 127) : (i & 127))); - assert_noexcept(sign_extend(u, 64) == i); - assert_noexcept(sign_extend(upx_uint64_t(0) - u, 64) == -i); + assert_noexcept(sign_extend64(u, 1) == ((i & 1) ? -1 : 0)); + assert_noexcept(sign_extend64(u, 2) == ((i & 2) ? -2 + (i & 1) : (i & 1))); + assert_noexcept(sign_extend64(u, 3) == ((i & 4) ? -4 + (i & 3) : (i & 3))); + assert_noexcept(sign_extend64(u, 4) == ((i & 8) ? -8 + (i & 7) : (i & 7))); + assert_noexcept(sign_extend64(u, 5) == ((i & 16) ? -16 + (i & 15) : (i & 15))); + assert_noexcept(sign_extend64(u, 6) == ((i & 32) ? -32 + (i & 31) : (i & 31))); + assert_noexcept(sign_extend64(u, 7) == ((i & 64) ? -64 + (i & 63) : (i & 63))); + assert_noexcept(sign_extend64(u, 8) == ((i & 128) ? -128 + (i & 127) : (i & 127))); + assert_noexcept(sign_extend64(u, 9) == i); + assert_noexcept(sign_extend64(u, 32) == i); + assert_noexcept(sign_extend64(upx_uint64_t(0) - u, 32) == -i); + assert_noexcept(sign_extend64(u, 64) == i); + assert_noexcept(sign_extend64(upx_uint64_t(0) - u, 64) == -i); } } } diff --git a/src/util/system_check_predefs.h b/src/util/system_check_predefs.h index ef688fc4..6773339b 100644 --- a/src/util/system_check_predefs.h +++ b/src/util/system_check_predefs.h @@ -115,8 +115,8 @@ #if !defined(__ORDER_BIG_ENDIAN__) || (__ORDER_BIG_ENDIAN__ + 0 != 4321) #error "unexpected __ORDER_BIG_ENDIAN__" #endif -#if !defined(__ORDER_BIG_ENDIAN__) || (__ORDER_LITTLE_ENDIAN__ + 0 != 1234) -#error "unexpected __ORDER_BIG_ENDIAN__" +#if !defined(__ORDER_LITTLE_ENDIAN__) || (__ORDER_LITTLE_ENDIAN__ + 0 != 1234) +#error "unexpected __ORDER_LITTLE_ENDIAN__" #endif #if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__) #error "unexpected __BYTE_ORDER__"