From f29791470f9ee1071254dbc5e716f26947fd8f2a Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sun, 10 Mar 2024 16:23:06 +0100 Subject: [PATCH] all: yet more cleanups --- .clangd | 9 +++++- .github/workflows/ci.yml | 5 +++- .gitignore | 5 ++-- src/Makefile | 2 +- src/bele.h | 8 ++--- src/check/dt_check.cpp | 13 ++++++--- src/check/dt_cxxlib.cpp | 2 +- src/compress/compress_bzip2.cpp | 2 +- src/compress/compress_zstd.cpp | 2 +- src/conf.h | 11 +++++-- src/console/s_win32.cpp | 2 +- src/msg.cpp | 2 +- src/stub/Makefile | 2 +- src/stub/src/arch/amd64/Makefile.extra | 4 +-- src/stub/src/arch/arm/v4a/Makefile.extra | 4 +-- src/stub/src/arch/arm/v4t/Makefile.extra | 4 +-- src/stub/src/arch/arm64/v8/Makefile.extra | 4 +-- src/stub/src/arch/i086/Makefile.extra | 4 +-- src/stub/src/arch/i386/Makefile.extra | 4 +-- src/stub/src/arch/m68k/m68000/Makefile.extra | 4 +-- src/stub/src/arch/m68k/m68020/Makefile.extra | 4 +-- src/stub/src/arch/mips/r3000/Makefile.extra | 4 +-- src/stub/src/arch/powerpc/32/Makefile.extra | 4 +-- src/stub/src/arch/powerpc/64/Makefile.extra | 4 +-- src/stub/src/arch/powerpc/64le/Makefile.extra | 4 +-- .../src/c/{Makevars.lzma => Makevars-lzma.mk} | 0 src/stub/src/c/lzma_d_c.c | 2 +- src/{ => util}/miniacc.h | 0 src/util/system_defs.h | 2 +- src/{headers.h => util/system_headers.h} | 29 +++++++++++++++++-- src/util/util.cpp | 11 +++---- src/work.cpp | 2 +- 32 files changed, 102 insertions(+), 57 deletions(-) rename src/stub/src/c/{Makevars.lzma => Makevars-lzma.mk} (100%) rename src/{ => util}/miniacc.h (100%) rename src/{headers.h => util/system_headers.h} (81%) diff --git a/.clangd b/.clangd index 9cbc3fd3..5e969f48 100644 --- a/.clangd +++ b/.clangd @@ -11,13 +11,20 @@ CompileFlags: Add: - -xc++ --- -# common C++ flags +# C++ flags If: PathMatch: [ src/.*\.h, src/.*\.cpp ] PathExclude: vendor/.* CompileFlags: Add: - -std=gnu++17 +--- +# common flags for all C/C++ files +If: + PathMatch: [ src/.*\.h, src/.*\.c, src/.*\.cpp ] + PathExclude: vendor/.* +CompileFlags: + Add: # see https://github.com/clangd/clangd/issues/1038 : Support deterministic relative include path - -Ivendor - -I../vendor diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1782e42b..669ecfd0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -168,11 +168,14 @@ jobs: env -C build/extra/gcc-m32/release bash "$PWD"/misc/testsuite/mimic_ctest.sh fi - name: 'Run file system test suite' + run: | + env -C build/extra/gcc/release bash "$PWD"/misc/testsuite/test_symlinks.sh + - name: 'Run file system test suite with Valgrind' run: | if command -v valgrind >/dev/null; then export upx_exe_runner="valgrind --leak-check=no --error-exitcode=1 --quiet --gen-suppressions=all" + env -C build/extra/gcc/release bash "$PWD"/misc/testsuite/test_symlinks.sh fi - env -C build/extra/gcc/release bash "$PWD"/misc/testsuite/test_symlinks.sh - name: 'Run test suite build/extra/gcc/release' run: | export upx_testsuite_SRCDIR="$(readlink -en ../deps/upx-testsuite)" diff --git a/.gitignore b/.gitignore index 760afb72..049705a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /.hg* /.vscode* -/Makevars.global* +/Makevars[.-]global* /Testing* /build* /maint* @@ -8,7 +8,7 @@ GNUmakefile* MMakefile* -Makevars.local* +Makevars[.-]local* compile_flags*.txt Tmp* tmp* @@ -16,6 +16,7 @@ tmp* *.a *.bz2 *.d +*.diff *.dll *.dylib *.exe diff --git a/src/Makefile b/src/Makefile index d1157062..6d7fb11f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -101,7 +101,7 @@ ifneq ($(wildcard /usr/bin/env),) ifeq ($(shell uname),Linux) # Markus loves clang-format, but John hates it; find a compromise -CLANG_FORMAT_EXCLUDE_FILES += miniacc.h stub/%.h +CLANG_FORMAT_EXCLUDE_FILES += stub/%.h util/miniacc.h 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 stub/tools/*/*.[ch]*)) diff --git a/src/bele.h b/src/bele.h index 680d5d2a..17143999 100644 --- a/src/bele.h +++ b/src/bele.h @@ -73,15 +73,15 @@ struct LE64; // char is explicitly allowed // byte is explicitly allowed template -static inline constexpr bool is_xe16_type = +inline constexpr bool is_xe16_type = upx::is_same_any_v; template -static inline constexpr bool is_xe24_type = upx::is_same_any_v; +inline constexpr bool is_xe24_type = upx::is_same_any_v; template -static inline constexpr bool is_xe32_type = +inline constexpr bool is_xe32_type = upx::is_same_any_v; template -static inline constexpr bool is_xe64_type = +inline constexpr bool is_xe64_type = upx::is_same_any_v; template diff --git a/src/check/dt_check.cpp b/src/check/dt_check.cpp index a5c4a9d2..49b845d5 100644 --- a/src/check/dt_check.cpp +++ b/src/check/dt_check.cpp @@ -24,8 +24,8 @@ */ -#include "../headers.h" -#include // std::isnan +#include "../util/system_headers.h" +#include // std::isinf std::isnan #include "../conf.h" /************************************************************************* @@ -352,6 +352,11 @@ static noinline void check_basic_cxx_exception_handling(void (*func)(int)) noexc // basic floating point checks to early catch toolchain/qemu/wine/etc problems // +#if defined(__clang__) && defined(__FAST_MATH__) && defined(__INTEL_LLVM_COMPILER) +// warning: comparison with NaN always evaluates to false in fast floating point modes +#pragma clang diagnostic ignored "-Wtautological-constant-compare" +#endif + static noinline float i64_f32_add_div(upx_int64_t a, upx_int64_t b) { return (a + b) / 1000000.0f; } static noinline float u64_f32_add_div(upx_uint64_t a, upx_uint64_t b) { return (a + b) / 1000000.0f; @@ -415,7 +420,7 @@ static noinline void check_basic_floating_point(void) noexcept { #define ACC_WANT_ACC_CHK_CH 1 #undef ACCCHK_ASSERT -#include "../miniacc.h" +#include "../util/miniacc.h" void upx_compiler_sanity_check(void) noexcept { const char *e = getenv("UPX_DEBUG_DOCTEST_DISABLE"); @@ -434,7 +439,7 @@ void upx_compiler_sanity_check(void) noexcept { #define ACC_WANT_ACC_CHK_CH 1 #undef ACCCHK_ASSERT #define ACCCHK_ASSERT(expr) ACC_COMPILE_TIME_ASSERT(expr) -#include "../miniacc.h" +#include "../util/miniacc.h" #undef ACCCHK_ASSERT COMPILE_TIME_ASSERT(sizeof(char) == 1) diff --git a/src/check/dt_cxxlib.cpp b/src/check/dt_cxxlib.cpp index 98ccb4d0..8f7fb27c 100644 --- a/src/check/dt_cxxlib.cpp +++ b/src/check/dt_cxxlib.cpp @@ -43,7 +43,7 @@ #endif #endif // TODO later -#include "../headers.h" +#include "../util/system_headers.h" #include #include "../conf.h" diff --git a/src/compress/compress_bzip2.cpp b/src/compress/compress_bzip2.cpp index e170a380..138246c5 100644 --- a/src/compress/compress_bzip2.cpp +++ b/src/compress/compress_bzip2.cpp @@ -24,7 +24,7 @@ */ -#include "../headers.h" +#include "../util/system_headers.h" #if WITH_BZIP2 #include #endif diff --git a/src/compress/compress_zstd.cpp b/src/compress/compress_zstd.cpp index 2de17f74..c28c6558 100644 --- a/src/compress/compress_zstd.cpp +++ b/src/compress/compress_zstd.cpp @@ -24,7 +24,7 @@ */ -#include "../headers.h" +#include "../util/system_headers.h" #if WITH_ZSTD #include #include diff --git a/src/conf.h b/src/conf.h index d84fbaa9..2d444aff 100644 --- a/src/conf.h +++ b/src/conf.h @@ -31,7 +31,7 @@ // init **************************************************************************/ -#include "headers.h" +#include "util/system_headers.h" #include "version.h" #if !defined(__has_attribute) @@ -190,9 +190,10 @@ typedef upx_int64_t upx_off_t; #define unlikely __acc_unlikely #define very_likely __acc_very_likely #define very_unlikely __acc_very_unlikely + // cosmetic: explicitly annotate some functions which may throw exceptions // note: noexcept(false) is the default for all C++ functions anyway -#define may_throw noexcept(false) +#define may_throw noexcept(false) #define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e) #define DELETED_FUNCTION = delete @@ -369,9 +370,11 @@ inline void NO_fprintf(FILE *, const char *, ...) noexcept {} #define upx_return_address() nullptr #endif -// TODO cleanup: we now require C++17, so remove all packed_struct usage +// TODO later cleanup: we now require C++17, so remove all packed_struct usage #define packed_struct(s) struct alignas(1) s +// TODO later cleanup: this was needed in the old days to catch compiler problems/bugs; +// we now require C++17, so remove this #define COMPILE_TIME_ASSERT_ALIGNOF_USING_SIZEOF__(a, b) \ { \ typedef a acc_tmp_a_t; \ @@ -395,6 +398,7 @@ inline void NO_fprintf(FILE *, const char *, ...) noexcept {} #define TABLESIZE(table) ((sizeof(table) / sizeof((table)[0]))) +// TODO later: move these to upx namespace in util/cxxlib.h template inline T ALIGN_DOWN(const T &a, const T &b) { T r; @@ -471,6 +475,7 @@ noreturn void throwAssertFailed(const char *expr, const char *file, int line, co #define assert_noexcept assert #endif +// C++ support library #include "util/cxxlib.h" using upx::is_same_any_v; using upx::noncopyable; diff --git a/src/console/s_win32.cpp b/src/console/s_win32.cpp index cb1fae19..a8045675 100644 --- a/src/console/s_win32.cpp +++ b/src/console/s_win32.cpp @@ -26,7 +26,7 @@ */ #define WANT_WINDOWS_LEAN_H 1 -#include "../headers.h" +#include "../util/system_headers.h" #if (HAVE_CONIO_H) #include #endif diff --git a/src/msg.cpp b/src/msg.cpp index bbd997e4..2e66da07 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -25,7 +25,7 @@ */ -#include "headers.h" +#include "util/system_headers.h" #include // typeid() #include "conf.h" diff --git a/src/stub/Makefile b/src/stub/Makefile index a04bc979..9a081220 100644 --- a/src/stub/Makefile +++ b/src/stub/Makefile @@ -25,7 +25,7 @@ endif ifndef top_srcdir top_srcdir := $(srcdir)/../.. endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) # update $PATH for our special stub build tools ifneq ($(wildcard $(HOME)/local/bin/bin-upx/upx-stubtools-check-version),) diff --git a/src/stub/src/arch/amd64/Makefile.extra b/src/stub/src/arch/amd64/Makefile.extra index 9eba1b0a..26be7686 100644 --- a/src/stub/src/arch/amd64/Makefile.extra +++ b/src/stub/src/arch/amd64/Makefile.extra @@ -8,11 +8,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) STUBS += lzma_d_cf.S lzma_d_cs.S lzma_d_cn.S endif diff --git a/src/stub/src/arch/arm/v4a/Makefile.extra b/src/stub/src/arch/arm/v4a/Makefile.extra index 6ce00c73..22e8082b 100644 --- a/src/stub/src/arch/arm/v4a/Makefile.extra +++ b/src/stub/src/arch/arm/v4a/Makefile.extra @@ -8,11 +8,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) STUBS += lzma_d_cf.S lzma_d_cs.S endif diff --git a/src/stub/src/arch/arm/v4t/Makefile.extra b/src/stub/src/arch/arm/v4t/Makefile.extra index b94f5f3a..d8dc630e 100644 --- a/src/stub/src/arch/arm/v4t/Makefile.extra +++ b/src/stub/src/arch/arm/v4t/Makefile.extra @@ -8,11 +8,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) STUBS += lzma_d_cf.S lzma_d_cs.S endif diff --git a/src/stub/src/arch/arm64/v8/Makefile.extra b/src/stub/src/arch/arm64/v8/Makefile.extra index 799c85ba..8ce3f7f9 100644 --- a/src/stub/src/arch/arm64/v8/Makefile.extra +++ b/src/stub/src/arch/arm64/v8/Makefile.extra @@ -8,11 +8,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) STUBS += lzma_d_cf.S lzma_d_cs.S endif diff --git a/src/stub/src/arch/i086/Makefile.extra b/src/stub/src/arch/i086/Makefile.extra index b376849d..5e1f7e9b 100644 --- a/src/stub/src/arch/i086/Makefile.extra +++ b/src/stub/src/arch/i086/Makefile.extra @@ -8,11 +8,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) ifneq ($(wildcard $(WATCOM)/binl/wcl),) STUBS += lzma_d_cf.S lzma_d_cs.S diff --git a/src/stub/src/arch/i386/Makefile.extra b/src/stub/src/arch/i386/Makefile.extra index ab9589a3..2aef9f3f 100644 --- a/src/stub/src/arch/i386/Makefile.extra +++ b/src/stub/src/arch/i386/Makefile.extra @@ -8,11 +8,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) STUBS += lzma_d_cf.S lzma_d_cs.S endif diff --git a/src/stub/src/arch/m68k/m68000/Makefile.extra b/src/stub/src/arch/m68k/m68000/Makefile.extra index 94c3bdf6..7cfc1119 100644 --- a/src/stub/src/arch/m68k/m68000/Makefile.extra +++ b/src/stub/src/arch/m68k/m68000/Makefile.extra @@ -8,11 +8,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) STUBS += lzma_d_cf.S lzma_d_cs.S endif diff --git a/src/stub/src/arch/m68k/m68020/Makefile.extra b/src/stub/src/arch/m68k/m68020/Makefile.extra index f7bd8ce3..17101cc1 100644 --- a/src/stub/src/arch/m68k/m68020/Makefile.extra +++ b/src/stub/src/arch/m68k/m68020/Makefile.extra @@ -8,11 +8,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) STUBS += lzma_d_cf.S lzma_d_cs.S endif diff --git a/src/stub/src/arch/mips/r3000/Makefile.extra b/src/stub/src/arch/mips/r3000/Makefile.extra index a5ab0cde..9deddd90 100644 --- a/src/stub/src/arch/mips/r3000/Makefile.extra +++ b/src/stub/src/arch/mips/r3000/Makefile.extra @@ -8,11 +8,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) STUBS += lzma_d_cf.S lzma_d_cs.S endif diff --git a/src/stub/src/arch/powerpc/32/Makefile.extra b/src/stub/src/arch/powerpc/32/Makefile.extra index 04f46f76..56eca56d 100644 --- a/src/stub/src/arch/powerpc/32/Makefile.extra +++ b/src/stub/src/arch/powerpc/32/Makefile.extra @@ -10,11 +10,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) STUBS += lzma_d_cf.S lzma_d_cs.S endif diff --git a/src/stub/src/arch/powerpc/64/Makefile.extra b/src/stub/src/arch/powerpc/64/Makefile.extra index 06875887..64747875 100644 --- a/src/stub/src/arch/powerpc/64/Makefile.extra +++ b/src/stub/src/arch/powerpc/64/Makefile.extra @@ -10,11 +10,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) STUBS += lzma_d_cf.S lzma_d_cs.S endif diff --git a/src/stub/src/arch/powerpc/64le/Makefile.extra b/src/stub/src/arch/powerpc/64le/Makefile.extra index e469fd5e..6d864e7b 100644 --- a/src/stub/src/arch/powerpc/64le/Makefile.extra +++ b/src/stub/src/arch/powerpc/64le/Makefile.extra @@ -10,11 +10,11 @@ __dir_list += ../../../../../.. ../../../../../../.. ../../../../../../../.. __dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3) top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND) endif -include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) +include $(wildcard $(top_srcdir)/Makevars-global.mk ./Makevars-local.mk) vpath %.c $(top_srcdir)/src/stub/src/c STUBS = -include $(top_srcdir)/src/stub/src/c/Makevars.lzma +include $(top_srcdir)/src/stub/src/c/Makevars-lzma.mk ifneq ($(UPX_LZMA_VERSION),) STUBS += lzma_d_cf.S lzma_d_cs.S endif diff --git a/src/stub/src/c/Makevars.lzma b/src/stub/src/c/Makevars-lzma.mk similarity index 100% rename from src/stub/src/c/Makevars.lzma rename to src/stub/src/c/Makevars-lzma.mk diff --git a/src/stub/src/c/lzma_d_c.c b/src/stub/src/c/lzma_d_c.c index aaceccbd..e3ef613d 100644 --- a/src/stub/src/c/lzma_d_c.c +++ b/src/stub/src/c/lzma_d_c.c @@ -31,7 +31,7 @@ #define ACC_LIBC_NAKED 1 /*#define ACC_OS_FREESTANDING 1*/ -#include "miniacc.h" +#include "util/miniacc.h" #define UPX_LZMA_COMPAT 1 diff --git a/src/miniacc.h b/src/util/miniacc.h similarity index 100% rename from src/miniacc.h rename to src/util/miniacc.h diff --git a/src/util/system_defs.h b/src/util/system_defs.h index 3eeb4f8f..2b565d30 100644 --- a/src/util/system_defs.h +++ b/src/util/system_defs.h @@ -34,8 +34,8 @@ #define __STDC_FORMAT_MACROS 1 #endif -#if defined(_WIN32) && defined(__MINGW32__) && (defined(__clang__) || defined(__GNUC__)) #if !defined(__USE_MINGW_ANSI_STDIO) +#if defined(_WIN32) && defined(__MINGW32__) && (defined(__clang__) || defined(__GNUC__)) #define __USE_MINGW_ANSI_STDIO 1 #endif #endif diff --git a/src/headers.h b/src/util/system_headers.h similarity index 81% rename from src/headers.h rename to src/util/system_headers.h index 904f179c..99420b64 100644 --- a/src/headers.h +++ b/src/util/system_headers.h @@ -1,4 +1,4 @@ -/* headers.h -- include system headers +/* system_headers.h -- include system headers This file is part of the UPX executable compressor. @@ -26,7 +26,7 @@ #pragma once -#include "util/system_defs.h" +#include "system_defs.h" #if !(__cplusplus + 0 >= 201703L) #error "C++17 is required" @@ -56,6 +56,29 @@ static_assert(sizeof(long) == 4); static_assert(sizeof(void *) == 8); #endif +// check expected defines +#if defined(__clang__) || defined(__GNUC__) +// these are pre-defined since gcc-4.6 (2011) and clang-3.2 (2012) +#if !defined(__ORDER_BIG_ENDIAN__) || (__ORDER_BIG_ENDIAN__ + 0 == 0) +#error "missing __ORDER_BIG_ENDIAN__" +#endif +#if !defined(__ORDER_LITTLE_ENDIAN__) || (__ORDER_LITTLE_ENDIAN__ + 0 == 0) +#error "missing __ORDER_LITTLE_ENDIAN__" +#endif +#if !defined(__BYTE_ORDER__) || (__BYTE_ORDER__ + 0 == 0) +#error "missing __BYTE_ORDER__" +#endif +#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__" +#endif +#if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__) +#error "unexpected __BYTE_ORDER__" +#endif +#endif + // ACC and C system headers #ifndef ACC_CFG_USE_NEW_STYLE_CASTS #define ACC_CFG_USE_NEW_STYLE_CASTS 1 @@ -146,7 +169,7 @@ static_assert(sizeof(void *) == 8); #ifdef WANT_WINDOWS_LEAN_H #if defined(_WIN32) || defined(__CYGWIN__) -#include "util/windows_lean.h" +#include "windows_lean.h" #endif #endif diff --git a/src/util/util.cpp b/src/util/util.cpp index 914f1592..0614f16b 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -25,17 +25,17 @@ */ -#include "../headers.h" +#include "system_headers.h" #include #define ACC_WANT_ACC_INCI_H 1 -#include "../miniacc.h" +#include "miniacc.h" #define ACC_WANT_ACCLIB_GETOPT 1 #define ACC_WANT_ACCLIB_HSREAD 1 #define ACC_WANT_ACCLIB_MISC 1 #define ACC_WANT_ACCLIB_VGET 1 #define ACC_WANT_ACCLIB_WILDARGV 1 #undef HAVE_MKDIR -#include "../miniacc.h" +#include "miniacc.h" #include "../conf.h" /************************************************************************* @@ -152,8 +152,9 @@ void uintptr_check_no_overlap(upx_uintptr_t a, size_t a_size, upx_uintptr_t b, s upx_uintptr_t b_end = b + mem_size(1, b_size); if very_unlikely (a_end < a || b_end < b) // wrap-around throwCantPack("ptr_check_no_overlap-overflow"); - // same as (!(a >= b_end || b >= a_end)) - // same as (!(a_end <= b || b_end <= a)) + // simple, but a little bit mind bending: + // same as (!(a >= b_end || b >= a_end)) + // same as (!(a_end <= b || b_end <= a)) if very_unlikely (a < b_end && b < a_end) throwCantPack("ptr_check_no_overlap-ab"); } diff --git a/src/work.cpp b/src/work.cpp index c1003617..ed06250f 100644 --- a/src/work.cpp +++ b/src/work.cpp @@ -31,7 +31,7 @@ // And see p_com.cpp for a simple executable format. #define WANT_WINDOWS_LEAN_H 1 // _get_osfhandle, GetFileTime, SetFileTime -#include "headers.h" +#include "util/system_headers.h" #if USE_UTIMENSAT #include #include