1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

all: yet more cleanups

This commit is contained in:
Markus F.X.J. Oberhumer 2024-03-10 16:23:06 +01:00
parent 52d9b53b74
commit f29791470f
32 changed files with 102 additions and 57 deletions

View File

@ -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

View File

@ -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)"

5
.gitignore vendored
View File

@ -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

View File

@ -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]*))

View File

@ -73,15 +73,15 @@ struct LE64;
// char is explicitly allowed
// byte is explicitly allowed
template <class T>
static inline constexpr bool is_xe16_type =
inline constexpr bool is_xe16_type =
upx::is_same_any_v<T, void, char, byte, upx_int16_t, upx_uint16_t, BE16, LE16>;
template <class T>
static inline constexpr bool is_xe24_type = upx::is_same_any_v<T, void, char, byte>;
inline constexpr bool is_xe24_type = upx::is_same_any_v<T, void, char, byte>;
template <class T>
static inline constexpr bool is_xe32_type =
inline constexpr bool is_xe32_type =
upx::is_same_any_v<T, void, char, byte, upx_int32_t, upx_uint32_t, BE32, LE32>;
template <class T>
static inline constexpr bool is_xe64_type =
inline constexpr bool is_xe64_type =
upx::is_same_any_v<T, void, char, byte, upx_int64_t, upx_uint64_t, BE64, LE64>;
template <class T>

View File

@ -24,8 +24,8 @@
<markus@oberhumer.com>
*/
#include "../headers.h"
#include <cmath> // std::isnan
#include "../util/system_headers.h"
#include <cmath> // 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)

View File

@ -43,7 +43,7 @@
#endif
#endif // TODO later
#include "../headers.h"
#include "../util/system_headers.h"
#include <vector>
#include "../conf.h"

View File

@ -24,7 +24,7 @@
<markus@oberhumer.com>
*/
#include "../headers.h"
#include "../util/system_headers.h"
#if WITH_BZIP2
#include <bzip2/bzlib.h>
#endif

View File

@ -24,7 +24,7 @@
<markus@oberhumer.com>
*/
#include "../headers.h"
#include "../util/system_headers.h"
#if WITH_ZSTD
#include <zstd/lib/zstd.h>
#include <zstd/lib/zstd_errors.h>

View File

@ -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 <class T>
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;

View File

@ -26,7 +26,7 @@
*/
#define WANT_WINDOWS_LEAN_H 1
#include "../headers.h"
#include "../util/system_headers.h"
#if (HAVE_CONIO_H)
#include <conio.h>
#endif

View File

@ -25,7 +25,7 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#include "headers.h"
#include "util/system_headers.h"
#include <typeinfo> // typeid()
#include "conf.h"

View File

@ -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),)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -25,17 +25,17 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#include "../headers.h"
#include "system_headers.h"
#include <algorithm>
#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");
}

View File

@ -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 <sys/types.h>
#include <fcntl.h>