all: and yet more cleanups; NFCI
This commit is contained in:
parent
7e839e6962
commit
a27a9e6000
@ -85,6 +85,7 @@ upx_cache_bool_vars(OFF
|
|||||||
UPX_CONFIG_DISABLE_C_STANDARD UPX_CONFIG_DISABLE_CXX_STANDARD
|
UPX_CONFIG_DISABLE_C_STANDARD UPX_CONFIG_DISABLE_CXX_STANDARD
|
||||||
UPX_CONFIG_EXPECT_THREADS UPX_CONFIG_REQUIRE_THREADS
|
UPX_CONFIG_EXPECT_THREADS UPX_CONFIG_REQUIRE_THREADS
|
||||||
)
|
)
|
||||||
|
upx_print_env_var(CC CXX)
|
||||||
|
|
||||||
# determine Git revision
|
# determine Git revision
|
||||||
set(GITREV_SHORT "")
|
set(GITREV_SHORT "")
|
||||||
@ -502,6 +503,7 @@ endif()
|
|||||||
upx_print_var(CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_VERSION CMAKE_HOST_SYSTEM_PROCESSOR CMAKE_APPLE_SILICON_PROCESSOR)
|
upx_print_var(CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_VERSION CMAKE_HOST_SYSTEM_PROCESSOR CMAKE_APPLE_SILICON_PROCESSOR)
|
||||||
upx_print_var(CMAKE_SYSTEM_NAME CMAKE_SYSTEM_VERSION CMAKE_SYSTEM_PROCESSOR CMAKE_CROSSCOMPILING CMAKE_CROSSCOMPILING_EMULATOR)
|
upx_print_var(CMAKE_SYSTEM_NAME CMAKE_SYSTEM_VERSION CMAKE_SYSTEM_PROCESSOR CMAKE_CROSSCOMPILING CMAKE_CROSSCOMPILING_EMULATOR)
|
||||||
upx_print_var(CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT)
|
upx_print_var(CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT)
|
||||||
|
upx_print_var(CMAKE_C_COMPILER CMAKE_CXX_COMPILER CMAKE_AR CMAKE_RANLIB)
|
||||||
upx_print_var(CMAKE_C_COMPILER_ID CMAKE_C_COMPILER_VERSION CMAKE_C_COMPILER_FRONTEND_VARIANT CMAKE_C_COMPILER_ARCHITECTURE_ID CMAKE_C_PLATFORM_ID CMAKE_C_COMPILER_ABI)
|
upx_print_var(CMAKE_C_COMPILER_ID CMAKE_C_COMPILER_VERSION CMAKE_C_COMPILER_FRONTEND_VARIANT CMAKE_C_COMPILER_ARCHITECTURE_ID CMAKE_C_PLATFORM_ID CMAKE_C_COMPILER_ABI)
|
||||||
upx_print_var(CMAKE_CXX_COMPILER_ID CMAKE_CXX_COMPILER_VERSION CMAKE_CXX_COMPILER_FRONTEND_VARIANT CMAKE_CXX_COMPILER_ARCHITECTURE_ID CMAKE_CXX_PLATFORM_ID CMAKE_CXX_COMPILER_ABI)
|
upx_print_var(CMAKE_CXX_COMPILER_ID CMAKE_CXX_COMPILER_VERSION CMAKE_CXX_COMPILER_FRONTEND_VARIANT CMAKE_CXX_COMPILER_ARCHITECTURE_ID CMAKE_CXX_PLATFORM_ID CMAKE_CXX_COMPILER_ABI)
|
||||||
upx_print_var(CMAKE_INTERPROCEDURAL_OPTIMIZATION CMAKE_POSITION_INDEPENDENT_CODE CMAKE_TRY_COMPILE_CONFIGURATION)
|
upx_print_var(CMAKE_INTERPROCEDURAL_OPTIMIZATION CMAKE_POSITION_INDEPENDENT_CODE CMAKE_TRY_COMPILE_CONFIGURATION)
|
||||||
|
|||||||
2
Makefile
2
Makefile
@ -49,7 +49,7 @@ build/release: PHONY
|
|||||||
debug: build/debug PHONY
|
debug: build/debug PHONY
|
||||||
release: build/release PHONY
|
release: build/release PHONY
|
||||||
all build/all: build/debug build/release PHONY
|
all build/all: build/debug build/release PHONY
|
||||||
build/%/all: $$(dir $$@)debug $$(dir $$@)release PHONY;
|
build/%/all: $$(dir $$@)debug $$(dir $$@)release PHONY ;
|
||||||
|
|
||||||
#
|
#
|
||||||
# END of Makefile
|
# END of Makefile
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/
|
# for clang-tidy from https://clang.llvm.org/extra/clang-tidy/
|
||||||
---
|
---
|
||||||
Checks: >
|
Checks: >
|
||||||
-*,
|
-*,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/
|
# for clang-tidy from https://clang.llvm.org/extra/clang-tidy/
|
||||||
---
|
---
|
||||||
Checks: >
|
Checks: >
|
||||||
-*,
|
-*,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/
|
# for clang-tidy from https://clang.llvm.org/extra/clang-tidy/
|
||||||
---
|
---
|
||||||
Checks: >
|
Checks: >
|
||||||
-*,
|
-*,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/
|
# for clang-tidy from https://clang.llvm.org/extra/clang-tidy/
|
||||||
---
|
---
|
||||||
Checks: >
|
Checks: >
|
||||||
-*,
|
-*,
|
||||||
|
|||||||
@ -72,6 +72,16 @@ function(upx_print_var) # ARGV
|
|||||||
endforeach()
|
endforeach()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(upx_print_env_var) # ARGV
|
||||||
|
foreach(var_name ${ARGV})
|
||||||
|
if(DEFINED ENV{${var_name}})
|
||||||
|
if(NOT ",$ENV{${var_name}}," STREQUAL ",,")
|
||||||
|
message(STATUS "ENV{${var_name}} = $ENV{${var_name}}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
function(upx_print_have_symbol) # ARGV; needs include(CheckSymbolExists)
|
function(upx_print_have_symbol) # ARGV; needs include(CheckSymbolExists)
|
||||||
foreach(symbol ${ARGV})
|
foreach(symbol ${ARGV})
|
||||||
set(cache_var_name "HAVE_symbol_${symbol}")
|
set(cache_var_name "HAVE_symbol_${symbol}")
|
||||||
|
|||||||
@ -260,6 +260,9 @@ build/$(UPX_XTARGET)/%: export CXX := $(CXX)
|
|||||||
xtarget/all: xtarget/debug xtarget/release PHONY
|
xtarget/all: xtarget/debug xtarget/release PHONY
|
||||||
xtarget/debug: build/$(UPX_XTARGET)/debug PHONY
|
xtarget/debug: build/$(UPX_XTARGET)/debug PHONY
|
||||||
xtarget/release: build/$(UPX_XTARGET)/release PHONY
|
xtarget/release: build/$(UPX_XTARGET)/release PHONY
|
||||||
|
xtarget/all+test: xtarget/debug+test xtarget/release+test PHONY
|
||||||
|
xtarget/debug+test: build/$(UPX_XTARGET)/debug+test PHONY
|
||||||
|
xtarget/release+test: build/$(UPX_XTARGET)/release+test PHONY
|
||||||
# set new default
|
# set new default
|
||||||
.DEFAULT_GOAL := build/$(UPX_XTARGET)/release
|
.DEFAULT_GOAL := build/$(UPX_XTARGET)/release
|
||||||
|
|
||||||
@ -269,14 +272,16 @@ endif
|
|||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
# assemble cmake config flags; useful for CI jobs
|
# assemble cmake config flags; useful for CI jobs
|
||||||
|
#
|
||||||
|
# info: by default CMake only honors the CC and CXX environment variables; make
|
||||||
|
# it easy to set other variables like CMAKE_AR or CMAKE_RANLIB
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
|
|
||||||
ifneq ($(origin UPX_CMAKE_CONFIG_FLAGS),command line) # GNU make bug work-around
|
ifneq ($(origin UPX_CMAKE_CONFIG_FLAGS),command line) # GNU make bug work-around
|
||||||
# GNU make bug, see https://savannah.gnu.org/bugs/index.php?64822
|
# GNU make bug, see https://savannah.gnu.org/bugs/index.php?64822
|
||||||
# and commit https://git.savannah.gnu.org/cgit/make.git/commit/?id=07187db947ba25e6c59b55f10660a04f8e9c5229
|
# and commit https://git.savannah.gnu.org/cgit/make.git/commit/?id=07187db947ba25e6c59b55f10660a04f8e9c5229
|
||||||
|
|
||||||
# info: by default CMake only honors the CC and CXX environment variables; make
|
$(call check_undefined,__add_cmake_config)
|
||||||
# it easy to set other variables like CMAKE_AR or CMAKE_RANLIB
|
|
||||||
__add_cmake_config = $(and $($1),-D$1="$($1)")
|
__add_cmake_config = $(and $($1),-D$1="$($1)")
|
||||||
# pass common CMake settings from environment/make to cmake
|
# pass common CMake settings from environment/make to cmake
|
||||||
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_VERBOSE_MAKEFILE)
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_VERBOSE_MAKEFILE)
|
||||||
|
|||||||
@ -33,7 +33,7 @@ debug+test release+test all+test: PHONY; $(MAKE) -C $(top_srcd
|
|||||||
|
|
||||||
test:: build/all+test PHONY
|
test:: build/all+test PHONY
|
||||||
|
|
||||||
# OLD names [deprecated]
|
# OLD target names [deprecated]
|
||||||
$(top_srcdir)/build/debug: build/debug PHONY
|
$(top_srcdir)/build/debug: build/debug PHONY
|
||||||
$(top_srcdir)/build/release: build/release PHONY
|
$(top_srcdir)/build/release: build/release PHONY
|
||||||
|
|
||||||
@ -42,8 +42,7 @@ $(top_srcdir)/build/release: build/release PHONY
|
|||||||
# git clone https://github.com/upx/upx-testsuite.git
|
# git clone https://github.com/upx/upx-testsuite.git
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
|
|
||||||
# search for the UPX testsuite
|
# search for the UPX testsuite; you can override by setting "upx_testsuite_SRCDIR"
|
||||||
# you also can override upx_testsuite_SRCDIR
|
|
||||||
ifndef upx_testsuite_SRCDIR
|
ifndef upx_testsuite_SRCDIR
|
||||||
# search standard locations below $(top_srcdir)
|
# search standard locations below $(top_srcdir)
|
||||||
ifneq ($(wildcard $(top_srcdir)/../upx--upx-testsuite.git/files/packed/.),)
|
ifneq ($(wildcard $(top_srcdir)/../upx--upx-testsuite.git/files/packed/.),)
|
||||||
@ -61,7 +60,7 @@ endif
|
|||||||
ifneq ($(wildcard $(upx_testsuite_SRCDIR)/files/packed/.),)
|
ifneq ($(wildcard $(upx_testsuite_SRCDIR)/files/packed/.),)
|
||||||
ifneq ($(wildcard $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh),)
|
ifneq ($(wildcard $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh),)
|
||||||
run-testsuite: run-testsuite-release PHONY
|
run-testsuite: run-testsuite-release PHONY
|
||||||
run-testsuite-%: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR)
|
run-testsuite-%: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR)
|
||||||
run-testsuite-debug: export upx_testsuite_BUILDDIR := ./tmp-upx-testsuite-debug
|
run-testsuite-debug: export upx_testsuite_BUILDDIR := ./tmp-upx-testsuite-debug
|
||||||
run-testsuite-debug: export upx_exe := $(top_srcdir)/build/debug/upx
|
run-testsuite-debug: export upx_exe := $(top_srcdir)/build/debug/upx
|
||||||
run-testsuite-debug: build/debug PHONY
|
run-testsuite-debug: build/debug PHONY
|
||||||
@ -101,7 +100,7 @@ CLANG_FORMAT_EXCLUDE_FILES += p_lx_% p_mach% p_unix% p_vmlin%
|
|||||||
CLANG_FORMAT_FILES := $(sort $(wildcard *.[ch]* ../maint/src/*.[ch]* */*.[ch]*))
|
CLANG_FORMAT_FILES := $(sort $(wildcard *.[ch]* ../maint/src/*.[ch]* */*.[ch]*))
|
||||||
CLANG_FORMAT_FILES += $(sort $(wildcard stub/tools/*/*.[ch]*))
|
CLANG_FORMAT_FILES += $(sort $(wildcard stub/tools/*/*.[ch]*))
|
||||||
CLANG_FORMAT_FILES += $(sort $(wildcard ../misc/cmake/try_compile/*.[ch]*))
|
CLANG_FORMAT_FILES += $(sort $(wildcard ../misc/cmake/try_compile/*.[ch]*))
|
||||||
CLANG_FORMAT_FILES := $(filter-out $(CLANG_FORMAT_EXCLUDE_FILES),$(CLANG_FORMAT_FILES))
|
CLANG_FORMAT_FILES := $(sort $(filter-out $(CLANG_FORMAT_EXCLUDE_FILES),$(CLANG_FORMAT_FILES)))
|
||||||
clang-format: $(CLANG_FORMAT_FILES) PHONY
|
clang-format: $(CLANG_FORMAT_FILES) PHONY
|
||||||
@echo "running upx-clang-format"
|
@echo "running upx-clang-format"
|
||||||
@bash $(top_srcdir)/misc/scripts/upx-clang-format.sh -i $(CLANG_FORMAT_FILES)
|
@bash $(top_srcdir)/misc/scripts/upx-clang-format.sh -i $(CLANG_FORMAT_FILES)
|
||||||
|
|||||||
@ -47,8 +47,9 @@
|
|||||||
// try to detect XX16 vs XX32 vs XX64 size mismatches
|
// try to detect XX16 vs XX32 vs XX64 size mismatches
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#if 0 // permissive version using "void *"
|
#if !(DEBUG)
|
||||||
|
|
||||||
|
// permissive version using "void *"
|
||||||
#define REQUIRE_XE16 /*empty*/
|
#define REQUIRE_XE16 /*empty*/
|
||||||
#define REQUIRE_XE24 /*empty*/
|
#define REQUIRE_XE24 /*empty*/
|
||||||
#define REQUIRE_XE32 /*empty*/
|
#define REQUIRE_XE32 /*empty*/
|
||||||
@ -748,6 +749,7 @@ T *operator+(const LE64 &v, T *ptr) noexcept DELETED_FUNCTION;
|
|||||||
// global overloads
|
// global overloads
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// TODO later: move these to upx namespace in util/cxxlib.h; see conf.h
|
||||||
inline unsigned ALIGN_DOWN(unsigned a, const BE32 &b) { return ALIGN_DOWN(a, unsigned(b)); }
|
inline unsigned ALIGN_DOWN(unsigned a, const BE32 &b) { return ALIGN_DOWN(a, unsigned(b)); }
|
||||||
inline unsigned ALIGN_DOWN(const BE32 &a, unsigned b) { return ALIGN_DOWN(unsigned(a), b); }
|
inline unsigned ALIGN_DOWN(const BE32 &a, unsigned b) { return ALIGN_DOWN(unsigned(a), b); }
|
||||||
inline unsigned ALIGN_UP(unsigned a, const BE32 &b) { return ALIGN_UP(a, unsigned(b)); }
|
inline unsigned ALIGN_UP(unsigned a, const BE32 &b) { return ALIGN_UP(a, unsigned(b)); }
|
||||||
@ -758,7 +760,7 @@ inline unsigned ALIGN_DOWN(const LE32 &a, unsigned b) { return ALIGN_DOWN(unsign
|
|||||||
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); }
|
||||||
|
|
||||||
// TODO: introduce upx::umax() and upx::umin()
|
// TODO later: introduce upx::umax() and upx::umin()
|
||||||
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)); }
|
||||||
|
|||||||
@ -741,6 +741,12 @@ TEST_CASE("libc snprintf") {
|
|||||||
CHECK_EQ(strcmp(buf, "-6.0.0.0.0.0.0.0.6.ffffffffffffffff"), 0);
|
CHECK_EQ(strcmp(buf, "-6.0.0.0.0.0.0.0.6.ffffffffffffffff"), 0);
|
||||||
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%#jx", -7, 0, 0, 0, 0, 0, 0, 0, 7, um);
|
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%#jx", -7, 0, 0, 0, 0, 0, 0, 0, 7, um);
|
||||||
CHECK_EQ(strcmp(buf, "-7.0.0.0.0.0.0.0.7.0xffffffffffffffff"), 0);
|
CHECK_EQ(strcmp(buf, "-7.0.0.0.0.0.0.0.7.0xffffffffffffffff"), 0);
|
||||||
|
snprintf(buf, sizeof(buf), "%#x %#lx %#llx", 17u, 18ul, 19ull);
|
||||||
|
CHECK_EQ(strcmp(buf, "0x11 0x12 0x13"), 0);
|
||||||
|
snprintf(buf, sizeof(buf), "%#X %#lX %#llX", 20u, 21ul, 22ull);
|
||||||
|
CHECK_EQ(strcmp(buf, "0X14 0X15 0X16"), 0);
|
||||||
|
snprintf(buf, sizeof(buf), "%#06x %#06lx %#06llx", 23u, 24ul, 25ull);
|
||||||
|
CHECK_EQ(strcmp(buf, "0x0017 0x0018 0x0019"), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|||||||
@ -70,7 +70,7 @@ ACC_COMPILE_TIME_ASSERT_HEADER((char) (-1) == 255)
|
|||||||
#pragma GCC diagnostic error "-Wsuggest-override"
|
#pragma GCC diagnostic error "-Wsuggest-override"
|
||||||
#endif
|
#endif
|
||||||
#if (ACC_CC_CLANG >= 0x080000)
|
#if (ACC_CC_CLANG >= 0x080000)
|
||||||
// don't enable before clang-8 because of stddef.h issues
|
// don't enable before clang-8 because of <stddef.h> issues
|
||||||
#pragma clang diagnostic error "-Wzero-as-null-pointer-constant"
|
#pragma clang diagnostic error "-Wzero-as-null-pointer-constant"
|
||||||
#elif (ACC_CC_GNUC >= 0x040700) && defined(__GLIBC__)
|
#elif (ACC_CC_GNUC >= 0x040700) && defined(__GLIBC__)
|
||||||
// Some non-GLIBC toolchains do not use 'nullptr' everywhere when C++:
|
// Some non-GLIBC toolchains do not use 'nullptr' everywhere when C++:
|
||||||
@ -154,6 +154,7 @@ typedef unsigned char uchar;
|
|||||||
// UPX convention: use "charptr" when dealing with abstract pointer arithmetics
|
// UPX convention: use "charptr" when dealing with abstract pointer arithmetics
|
||||||
#define charptr upx_charptr_unit_type *
|
#define charptr upx_charptr_unit_type *
|
||||||
// upx_charptr_unit_type is some opaque type with sizeof(type) == 1
|
// upx_charptr_unit_type is some opaque type with sizeof(type) == 1
|
||||||
|
//// typedef char upx_charptr_unit_type; // also works
|
||||||
struct alignas(1) upx_charptr_unit_type final { char hidden__; };
|
struct alignas(1) upx_charptr_unit_type final { char hidden__; };
|
||||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(upx_charptr_unit_type) == 1)
|
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(upx_charptr_unit_type) == 1)
|
||||||
|
|
||||||
@ -399,7 +400,7 @@ inline void NO_fprintf(FILE *, const char *, ...) noexcept {}
|
|||||||
|
|
||||||
#define TABLESIZE(table) ((sizeof(table) / sizeof((table)[0])))
|
#define TABLESIZE(table) ((sizeof(table) / sizeof((table)[0])))
|
||||||
|
|
||||||
// TODO later: move these to upx namespace in util/cxxlib.h
|
// TODO later: move these to upx namespace in util/cxxlib.h; also see bele.h
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T ALIGN_DOWN(const T &a, const T &b) {
|
inline T ALIGN_DOWN(const T &a, const T &b) {
|
||||||
T r;
|
T r;
|
||||||
@ -594,8 +595,8 @@ using upx::tribool;
|
|||||||
// #define M_CL1B_LE16 13
|
// #define M_CL1B_LE16 13
|
||||||
#define M_LZMA 14
|
#define M_LZMA 14
|
||||||
#define M_DEFLATE 15 // zlib
|
#define M_DEFLATE 15 // zlib
|
||||||
#define M_ZSTD 16
|
#define M_ZSTD 16 // NOT YET USED
|
||||||
#define M_BZIP2 17
|
#define M_BZIP2 17 // NOT YET USED
|
||||||
// compression methods internal usage
|
// compression methods internal usage
|
||||||
#define M_ALL (-1)
|
#define M_ALL (-1)
|
||||||
#define M_END (-2)
|
#define M_END (-2)
|
||||||
|
|||||||
@ -245,7 +245,7 @@ protected:
|
|||||||
unsigned image_size, int bits, bool bswap);
|
unsigned image_size, int bits, bool bswap);
|
||||||
|
|
||||||
// TE - Target Endianness abstraction
|
// TE - Target Endianness abstraction
|
||||||
#if 0
|
#if !(DEBUG)
|
||||||
// permissive version using "void *"
|
// permissive version using "void *"
|
||||||
inline unsigned get_te16(const void *p) const noexcept { return bele->get16(p); }
|
inline unsigned get_te16(const void *p) const noexcept { return bele->get16(p); }
|
||||||
inline unsigned get_te32(const void *p) const noexcept { return bele->get32(p); }
|
inline unsigned get_te32(const void *p) const noexcept { return bele->get32(p); }
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// sort and delta-compress relocations with optional bswap within image
|
// sort and delta-compress relocations with optional bswap within image
|
||||||
// returns number of bytes written to 'out'
|
// returns number of **bytes** written to 'out'
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
/*static*/
|
/*static*/
|
||||||
@ -102,7 +102,7 @@ unsigned Packer::optimizeReloc(unsigned relocnum, SPAN_P(byte) relocs, SPAN_S(by
|
|||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// delta-decompress relocations
|
// delta-decompress relocations
|
||||||
// advances 'in'
|
// advances 'in'
|
||||||
// allocates 'out' and returns number of relocs written to 'out'
|
// allocates 'out' and returns number of **relocs** written to 'out'
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
/*static*/
|
/*static*/
|
||||||
@ -132,7 +132,7 @@ unsigned Packer::unoptimizeReloc(SPAN_S(const byte) & in, MemBuffer &out, SPAN_P
|
|||||||
upx_adler32(image, image_size));
|
upx_adler32(image, image_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
out.alloc(4 * (relocnum + 1)); // one extra entry
|
out.alloc(mem_size(4, relocnum + 1)); // one extra entry
|
||||||
SPAN_S_VAR(LE32, relocs, out);
|
SPAN_S_VAR(LE32, relocs, out);
|
||||||
|
|
||||||
fix = in;
|
fix = in;
|
||||||
|
|||||||
@ -298,7 +298,7 @@ static constexpr size_t RELOC_INPLACE_OFFSET = 64 * 1024;
|
|||||||
static constexpr size_t RELOC_ENTRY_SIZE = 5; // encoded size in bytes; actual encoding is private
|
static constexpr size_t RELOC_ENTRY_SIZE = 5; // encoded size in bytes; actual encoding is private
|
||||||
static void reloc_entry_encode(SPAN_P(byte) buf, unsigned pos, unsigned reloc_type) {
|
static void reloc_entry_encode(SPAN_P(byte) buf, unsigned pos, unsigned reloc_type) {
|
||||||
if (reloc_type == 0 || reloc_type >= 16)
|
if (reloc_type == 0 || reloc_type >= 16)
|
||||||
throwCantPack("bad reloc_type %u %u", pos, reloc_type);
|
throwCantPack("bad reloc_type %#x %u", pos, reloc_type);
|
||||||
set_ne32(buf, pos);
|
set_ne32(buf, pos);
|
||||||
buf[4] = (upx_uint8_t) reloc_type;
|
buf[4] = (upx_uint8_t) reloc_type;
|
||||||
}
|
}
|
||||||
@ -383,7 +383,7 @@ bool PeFile::Reloc::readFromRelocationBlock(byte *next_rb) { // set rb
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeFile::Reloc::next(unsigned &result_pos, unsigned &result_type) {
|
bool PeFile::Reloc::next(unsigned &result_pos, unsigned &result_reloc_type) {
|
||||||
assert(!start_did_alloc);
|
assert(!start_did_alloc);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// search current block
|
// search current block
|
||||||
@ -391,9 +391,9 @@ bool PeFile::Reloc::next(unsigned &result_pos, unsigned &result_type) {
|
|||||||
rb.count -= 1;
|
rb.count -= 1;
|
||||||
const unsigned value = *rb.rel1++;
|
const unsigned value = *rb.rel1++;
|
||||||
result_pos = rb.rel->virtual_address + (value & 0xfff);
|
result_pos = rb.rel->virtual_address + (value & 0xfff);
|
||||||
result_type = (value >> 12) & 0xf;
|
result_reloc_type = (value >> 12) & 0xf;
|
||||||
NO_printf("%x %d\n", result_pos, result_type);
|
NO_printf("Reloc::next %#x %d\n", result_pos, result_reloc_type);
|
||||||
if (result_type != IMAGE_REL_BASED_IGNORE)
|
if (result_reloc_type != IMAGE_REL_BASED_IGNORE)
|
||||||
return true; // success
|
return true; // success
|
||||||
}
|
}
|
||||||
// advance to next block
|
// advance to next block
|
||||||
@ -407,9 +407,10 @@ bool PeFile::Reloc::next(unsigned &result_pos, unsigned &result_type) {
|
|||||||
|
|
||||||
void PeFile::Reloc::add_reloc(unsigned pos, unsigned reloc_type) {
|
void PeFile::Reloc::add_reloc(unsigned pos, unsigned reloc_type) {
|
||||||
assert(start_did_alloc);
|
assert(start_did_alloc);
|
||||||
|
// assert(reloc_type != IMAGE_REL_BASED_IGNORE);
|
||||||
if (reloc_type == IMAGE_REL_BASED_IGNORE)
|
if (reloc_type == IMAGE_REL_BASED_IGNORE)
|
||||||
return;
|
return;
|
||||||
auto entry_ptr = start_buf + (RELOC_INPLACE_OFFSET + RELOC_ENTRY_SIZE * counts[0]);
|
auto entry_ptr = start_buf + mem_size(RELOC_ENTRY_SIZE, counts[0], RELOC_INPLACE_OFFSET);
|
||||||
reloc_entry_encode(entry_ptr, pos, reloc_type);
|
reloc_entry_encode(entry_ptr, pos, reloc_type);
|
||||||
counts[0] += 1;
|
counts[0] += 1;
|
||||||
}
|
}
|
||||||
@ -436,7 +437,7 @@ void PeFile::Reloc::finish(byte *(&result_ptr), unsigned &result_size) {
|
|||||||
unsigned prev_pos = 0;
|
unsigned prev_pos = 0;
|
||||||
unsigned current_page = 0;
|
unsigned current_page = 0;
|
||||||
for (unsigned ic = 0; ic < counts[0]; ic++) {
|
for (unsigned ic = 0; ic < counts[0]; ic++) {
|
||||||
const auto entry_ptr = start_buf + (RELOC_INPLACE_OFFSET + RELOC_ENTRY_SIZE * ic);
|
const auto entry_ptr = start_buf + mem_size(RELOC_ENTRY_SIZE, ic, RELOC_INPLACE_OFFSET);
|
||||||
unsigned pos, reloc_type;
|
unsigned pos, reloc_type;
|
||||||
reloc_entry_decode(entry_ptr, &pos, &reloc_type);
|
reloc_entry_decode(entry_ptr, &pos, &reloc_type);
|
||||||
if (ic > 0 && pos == prev_pos)
|
if (ic > 0 && pos == prev_pos)
|
||||||
@ -457,7 +458,7 @@ void PeFile::Reloc::finish(byte *(&result_ptr), unsigned &result_size) {
|
|||||||
// info: if this is indeed a valid file we must increase RELOC_INPLACE_OFFSET
|
// info: if this is indeed a valid file we must increase RELOC_INPLACE_OFFSET
|
||||||
throwCantPack("too many inplace relocs");
|
throwCantPack("too many inplace relocs");
|
||||||
}
|
}
|
||||||
// write IMAGE_BASE_RELOCATION relocation
|
// write LE16 IMAGE_BASE_RELOCATION relocation
|
||||||
*rb.rel1++ = (reloc_type << 12) | (pos & 0xfff);
|
*rb.rel1++ = (reloc_type << 12) | (pos & 0xfff);
|
||||||
rb.rel->size_of_block += 2;
|
rb.rel->size_of_block += 2;
|
||||||
}
|
}
|
||||||
@ -469,7 +470,7 @@ void PeFile::Reloc::finish(byte *(&result_ptr), unsigned &result_size) {
|
|||||||
assert(start_did_alloc);
|
assert(start_did_alloc);
|
||||||
result_ptr = start;
|
result_ptr = start;
|
||||||
start_did_alloc = false;
|
start_did_alloc = false;
|
||||||
#if 1 // safety, as we are really finished
|
#if DEBUG || 1 // safety, as we are really finished
|
||||||
ptr_invalidate_and_poison(start);
|
ptr_invalidate_and_poison(start);
|
||||||
start_size_in_bytes = 0;
|
start_size_in_bytes = 0;
|
||||||
SPAN_INVALIDATE(start_buf);
|
SPAN_INVALIDATE(start_buf);
|
||||||
@ -489,10 +490,9 @@ void PeFile32::processRelocs() // pass1
|
|||||||
const unsigned *const counts = rel.getcounts();
|
const unsigned *const counts = rel.getcounts();
|
||||||
unsigned relocnum = 0;
|
unsigned relocnum = 0;
|
||||||
|
|
||||||
unsigned ic;
|
for (unsigned ic = 1; ic < 16; ic++)
|
||||||
for (ic = 1; ic < 16; ic++)
|
|
||||||
relocnum += counts[ic];
|
relocnum += counts[ic];
|
||||||
for (ic = 0; ic < 16; ic++)
|
for (unsigned ic = 0; ic < 16; ic++)
|
||||||
NO_printf("reloc counts[%u] %u\n", ic, counts[ic]);
|
NO_printf("reloc counts[%u] %u\n", ic, counts[ic]);
|
||||||
|
|
||||||
if (opt->win32_pe.strip_relocs || relocnum == 0) {
|
if (opt->win32_pe.strip_relocs || relocnum == 0) {
|
||||||
@ -507,13 +507,13 @@ void PeFile32::processRelocs() // pass1
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ic = IMAGE_REL_BASED_HIGHADJ; ic < 16; ic++)
|
for (unsigned ic = IMAGE_REL_BASED_HIGHADJ; ic < 16; ic++)
|
||||||
if (counts[ic])
|
if (counts[ic])
|
||||||
infoWarning("skipping unsupported relocation type %d (%d)", ic, counts[ic]);
|
infoWarning("skipping unsupported relocation type %d (%d)", ic, counts[ic]);
|
||||||
|
|
||||||
LE32 *fix[4];
|
LE32 *fix[4];
|
||||||
upx::ArrayDeleter<LE32 **> fixdel{fix, 0}; // don't leak memory
|
upx::ArrayDeleter<LE32 **> fixdel{fix, 0}; // don't leak memory
|
||||||
for (ic = 0; ic <= IMAGE_REL_BASED_HIGHLOW; ic++) {
|
for (unsigned ic = 0; ic <= IMAGE_REL_BASED_HIGHLOW; ic++) {
|
||||||
fix[ic] = New(LE32, counts[ic]);
|
fix[ic] = New(LE32, counts[ic]);
|
||||||
fixdel.count += 1;
|
fixdel.count += 1;
|
||||||
}
|
}
|
||||||
@ -533,7 +533,7 @@ void PeFile32::processRelocs() // pass1
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove duplicated records
|
// remove duplicated records
|
||||||
for (ic = 1; ic <= IMAGE_REL_BASED_HIGHLOW; ic++) {
|
for (unsigned ic = 1; ic <= IMAGE_REL_BASED_HIGHLOW; ic++) {
|
||||||
upx_qsort(fix[ic], xcounts[ic], 4, le32_compare);
|
upx_qsort(fix[ic], xcounts[ic], 4, le32_compare);
|
||||||
unsigned prev = ~0u;
|
unsigned prev = ~0u;
|
||||||
unsigned jc = 0;
|
unsigned jc = 0;
|
||||||
@ -546,7 +546,7 @@ void PeFile32::processRelocs() // pass1
|
|||||||
}
|
}
|
||||||
|
|
||||||
// preprocess "type 3" relocation records
|
// preprocess "type 3" relocation records
|
||||||
for (ic = 0; ic < xcounts[IMAGE_REL_BASED_HIGHLOW]; ic++) {
|
for (unsigned ic = 0; ic < xcounts[IMAGE_REL_BASED_HIGHLOW]; ic++) {
|
||||||
pos = fix[3][ic] + rvamin;
|
pos = fix[3][ic] + rvamin;
|
||||||
unsigned w = get_le32(ibuf.subref("bad reloc type 3 %#x", pos, sizeof(LE32)));
|
unsigned w = get_le32(ibuf.subref("bad reloc type 3 %#x", pos, sizeof(LE32)));
|
||||||
set_le32(ibuf + pos, w - ih.imagebase - rvamin);
|
set_le32(ibuf + pos, w - ih.imagebase - rvamin);
|
||||||
@ -567,7 +567,7 @@ void PeFile32::processRelocs() // pass1
|
|||||||
throwCantUnpack("Invalid relocs");
|
throwCantUnpack("Invalid relocs");
|
||||||
|
|
||||||
// append relocs type "LOW" then "HIGH"
|
// append relocs type "LOW" then "HIGH"
|
||||||
for (ic = IMAGE_REL_BASED_LOW; ic >= IMAGE_REL_BASED_HIGH; ic--) {
|
for (unsigned ic = IMAGE_REL_BASED_LOW; ic >= IMAGE_REL_BASED_HIGH; ic--) {
|
||||||
memcpy(orelocs + sorelocs, fix[ic], 4 * xcounts[ic]);
|
memcpy(orelocs + sorelocs, fix[ic], 4 * xcounts[ic]);
|
||||||
sorelocs += 4 * xcounts[ic];
|
sorelocs += 4 * xcounts[ic];
|
||||||
set_le32(orelocs + sorelocs, 0);
|
set_le32(orelocs + sorelocs, 0);
|
||||||
@ -592,10 +592,9 @@ void PeFile64::processRelocs() // pass1
|
|||||||
const unsigned *const counts = rel.getcounts();
|
const unsigned *const counts = rel.getcounts();
|
||||||
unsigned relocnum = 0;
|
unsigned relocnum = 0;
|
||||||
|
|
||||||
unsigned ic;
|
for (unsigned ic = 1; ic < 16; ic++)
|
||||||
for (ic = 1; ic < 16; ic++)
|
|
||||||
relocnum += counts[ic];
|
relocnum += counts[ic];
|
||||||
for (ic = 0; ic < 16; ic++)
|
for (unsigned ic = 0; ic < 16; ic++)
|
||||||
NO_printf("reloc counts[%u] %u\n", ic, counts[ic]);
|
NO_printf("reloc counts[%u] %u\n", ic, counts[ic]);
|
||||||
|
|
||||||
if (opt->win32_pe.strip_relocs || relocnum == 0) {
|
if (opt->win32_pe.strip_relocs || relocnum == 0) {
|
||||||
@ -610,13 +609,13 @@ void PeFile64::processRelocs() // pass1
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ic = 0; ic < 16; ic++)
|
for (unsigned ic = 0; ic < 16; ic++)
|
||||||
if (ic != IMAGE_REL_BASED_DIR64 && counts[ic])
|
if (ic != IMAGE_REL_BASED_DIR64 && counts[ic])
|
||||||
infoWarning("skipping unsupported relocation type %d (%d)", ic, counts[ic]);
|
infoWarning("skipping unsupported relocation type %d (%d)", ic, counts[ic]);
|
||||||
|
|
||||||
LE32 *fix[16];
|
LE32 *fix[16];
|
||||||
upx::ArrayDeleter<LE32 **> fixdel{fix, 0}; // don't leak memory
|
upx::ArrayDeleter<LE32 **> fixdel{fix, 0}; // don't leak memory
|
||||||
for (ic = 0; ic < 16; ic++) {
|
for (unsigned ic = 0; ic < 16; ic++) {
|
||||||
fix[ic] = New(LE32, counts[ic]);
|
fix[ic] = New(LE32, counts[ic]);
|
||||||
fixdel.count += 1;
|
fixdel.count += 1;
|
||||||
}
|
}
|
||||||
@ -636,7 +635,7 @@ void PeFile64::processRelocs() // pass1
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove duplicated records
|
// remove duplicated records
|
||||||
for (ic = 1; ic < 16; ic++) {
|
for (unsigned ic = 1; ic < 16; ic++) {
|
||||||
upx_qsort(fix[ic], xcounts[ic], 4, le32_compare);
|
upx_qsort(fix[ic], xcounts[ic], 4, le32_compare);
|
||||||
unsigned prev = ~0u;
|
unsigned prev = ~0u;
|
||||||
unsigned jc = 0;
|
unsigned jc = 0;
|
||||||
@ -649,7 +648,7 @@ void PeFile64::processRelocs() // pass1
|
|||||||
}
|
}
|
||||||
|
|
||||||
// preprocess "type 10" relocation records
|
// preprocess "type 10" relocation records
|
||||||
for (ic = 0; ic < xcounts[IMAGE_REL_BASED_DIR64]; ic++) {
|
for (unsigned ic = 0; ic < xcounts[IMAGE_REL_BASED_DIR64]; ic++) {
|
||||||
pos = fix[IMAGE_REL_BASED_DIR64][ic] + rvamin;
|
pos = fix[IMAGE_REL_BASED_DIR64][ic] + rvamin;
|
||||||
upx_uint64_t w = get_le64(ibuf.subref("bad reloc 10 %#x", pos, sizeof(LE64)));
|
upx_uint64_t w = get_le64(ibuf.subref("bad reloc 10 %#x", pos, sizeof(LE64)));
|
||||||
set_le64(ibuf + pos, w - ih.imagebase - rvamin);
|
set_le64(ibuf + pos, w - ih.imagebase - rvamin);
|
||||||
|
|||||||
@ -426,10 +426,10 @@ protected:
|
|||||||
explicit Reloc(unsigned relocnum);
|
explicit Reloc(unsigned relocnum);
|
||||||
~Reloc() noexcept;
|
~Reloc() noexcept;
|
||||||
//
|
//
|
||||||
bool next(unsigned &result_pos, unsigned &result_type);
|
bool next(unsigned &result_pos, unsigned &result_reloc_type);
|
||||||
const unsigned *getcounts() const { return counts; }
|
const unsigned *getcounts() const { return counts; }
|
||||||
//
|
//
|
||||||
void add_reloc(unsigned pos, unsigned type);
|
void add_reloc(unsigned pos, unsigned reloc_type);
|
||||||
void finish(byte *(&result_ptr), unsigned &result_size); // => transfer ownership
|
void finish(byte *(&result_ptr), unsigned &result_size); // => transfer ownership
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user