all: various cleanups

This commit is contained in:
Markus F.X.J. Oberhumer
2023-10-30 12:17:51 +01:00
parent 38a676f6f7
commit 37b923245d
7 changed files with 44 additions and 37 deletions
+3 -2
View File
@@ -191,13 +191,14 @@ if(NOT DEFINED HAVE_UNISTD_H)
check_include_file("unistd.h" HAVE_UNISTD_H) check_include_file("unistd.h" HAVE_UNISTD_H)
endif() endif()
if(NOT DEFINED HAVE_UTIMENSAT) if(NOT DEFINED HAVE_UTIMENSAT)
# proper checking for utimensat() is somewhat messy
check_function_exists(utimensat HAVE_UTIMENSAT_FUNCTION__) check_function_exists(utimensat HAVE_UTIMENSAT_FUNCTION__)
if(HAVE_UTIMENSAT_FUNCTION__) if(HAVE_UTIMENSAT_FUNCTION__)
check_symbol_exists(utimensat "sys/types.h;fcntl.h;sys/stat.h" HAVE_UTIMENSAT_SYMBOL__) check_symbol_exists(utimensat "sys/types.h;fcntl.h;sys/stat.h" HAVE_UTIMENSAT_SYMBOL__)
if(HAVE_UTIMENSAT_SYMBOL__) if(HAVE_UTIMENSAT_SYMBOL__)
CHECK_STRUCT_HAS_MEMBER("struct stat" "st_mtim.tv_nsec" "sys/types.h;fcntl.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) CHECK_STRUCT_HAS_MEMBER("struct stat" "st_mtim.tv_nsec" "sys/types.h;fcntl.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) # POSIX.1-2008
if(NOT HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) if(NOT HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
CHECK_STRUCT_HAS_MEMBER("struct stat" "st_mtimespec.tv_nsec" "sys/types.h;fcntl.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) CHECK_STRUCT_HAS_MEMBER("struct stat" "st_mtimespec.tv_nsec" "sys/types.h;fcntl.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) # macOS
endif() endif()
if(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC OR HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) if(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC OR HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
set(HAVE_UTIMENSAT 1) set(HAVE_UTIMENSAT 1)
+4
View File
@@ -3,12 +3,16 @@ User visible changes for UPX
================================================================== ==================================================================
Changes in 4.2.1 (XX XXX XXXX): Changes in 4.2.1 (XX XXX XXXX):
* windows: use SetFileTime to preserve sub-second timestamps
* official Windows builds: revert activeCodePage change introduced in 4.2.0
* bug fixes - see https://github.com/upx/upx/milestone/14 * bug fixes - see https://github.com/upx/upx/milestone/14
Changes in 4.2.0 (26 Oct 2023): Changes in 4.2.0 (26 Oct 2023):
* win32/pe and win64/pe: stricter relocation checks; please report regressions * win32/pe and win64/pe: stricter relocation checks; please report regressions
* unix: use utimensat to preserve sub-second file timestamps
* new option '--link' to preserve hard-links (Unix only; use with care) * new option '--link' to preserve hard-links (Unix only; use with care)
* add support for NO_COLOR env var; see https://no-color.org/ * add support for NO_COLOR env var; see https://no-color.org/
* official Windows builds: set activeCodePage to UTF-8
* disable macOS support until we fix compatibility with macOS 13+ * disable macOS support until we fix compatibility with macOS 13+
* bug fixes - see https://github.com/upx/upx/milestone/13 * bug fixes - see https://github.com/upx/upx/milestone/13
+4 -1
View File
@@ -26,6 +26,9 @@
#include "../conf.h" #include "../conf.h"
// various cxxlib checks
// (modern compilers will optimize away much of this code)
/************************************************************************* /*************************************************************************
// compile-time checks // compile-time checks
**************************************************************************/ **************************************************************************/
@@ -89,6 +92,7 @@ ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_le("abc", "abz"))
**************************************************************************/ **************************************************************************/
TEST_CASE("ptr_reinterpret_cast") { TEST_CASE("ptr_reinterpret_cast") {
// check that we don't trigger any -Wcast-align warnings
using upx::ptr_reinterpret_cast; using upx::ptr_reinterpret_cast;
byte *an = nullptr; byte *an = nullptr;
int *in = nullptr; int *in = nullptr;
@@ -127,7 +131,6 @@ TEST_CASE("noncopyable") {
/************************************************************************* /*************************************************************************
// TriBool checks // TriBool checks
// (modern compilers will optimize away most of this code)
**************************************************************************/ **************************************************************************/
namespace { namespace {
+4 -1
View File
@@ -190,13 +190,16 @@ typedef upx_int64_t upx_off_t;
// portab // portab
**************************************************************************/ **************************************************************************/
// just in case // some system headers may define these, so undef just in case
#undef _ #undef _
#undef __ #undef __
#undef ___ #undef ___
#undef dos #undef dos
#undef large
#undef linux #undef linux
#undef small #undef small
#undef SP
#undef SS
#undef tos #undef tos
#undef unix #undef unix
#if (ACC_OS_POSIX) && !defined(__unix__) #if (ACC_OS_POSIX) && !defined(__unix__)
+9 -9
View File
@@ -1540,41 +1540,41 @@ void PeFile::processLoadConf(Reloc *rel, const Interval *iv,
// resource handling // resource handling
**************************************************************************/ **************************************************************************/
struct alignas(1) PeFile::Resource::res_dir_entry { struct alignas(1) PeFile::Resource::res_dir_entry final {
LE32 tnl; // Type | Name | Language id - depending on level LE32 tnl; // Type | Name | Language id - depending on level
LE32 child; LE32 child;
}; };
struct alignas(1) PeFile::Resource::res_dir { struct alignas(1) PeFile::Resource::res_dir final {
byte _[12]; // flags, timedate, version byte _[12]; // flags, timedate, version
LE16 namedentr; LE16 namedentr;
LE16 identr; LE16 identr;
unsigned Sizeof() const { return 16 + sizeof(res_dir_entry) * (namedentr + identr); }
res_dir_entry entries[1];
// it's usually safe to assume that every res_dir contains // it's usually safe to assume that every res_dir contains
// at least one res_dir_entry - check() complains otherwise // at least one res_dir_entry - check() complains otherwise
res_dir_entry entries[1];
unsigned Sizeof() const { return 16 + mem_size(sizeof(res_dir_entry), namedentr + identr); }
}; };
struct alignas(1) PeFile::Resource::res_data { struct alignas(1) PeFile::Resource::res_data final {
LE32 offset; LE32 offset;
LE32 size; LE32 size;
byte _[8]; // codepage, reserved byte _[8]; // codepage, reserved
}; };
struct PeFile::Resource::upx_rnode { struct PeFile::Resource::upx_rnode /*not_final*/ {
unsigned id; unsigned id;
byte *name; byte *name;
upx_rnode *parent; upx_rnode *parent;
}; };
struct PeFile::Resource::upx_rbranch : public PeFile::Resource::upx_rnode { struct PeFile::Resource::upx_rbranch final : public PeFile::Resource::upx_rnode {
unsigned nc; unsigned nc;
upx_rnode **children; upx_rnode **children;
res_dir data; res_dir data;
}; };
struct PeFile::Resource::upx_rleaf : public PeFile::Resource::upx_rnode { struct PeFile::Resource::upx_rleaf final : public PeFile::Resource::upx_rnode {
upx_rleaf *next; upx_rleaf *next;
unsigned newoffset; unsigned newoffset;
res_data data; res_data data;
+14 -18
View File
@@ -31,24 +31,6 @@
namespace upx { namespace upx {
/*************************************************************************
// misc
**************************************************************************/
// a reinterpret_cast that does not trigger -Wcast-align warnings
template <class Result, class From>
forceinline Result ptr_reinterpret_cast(From *ptr) {
static_assert(std::is_pointer_v<Result>);
static_assert(!std::is_const_v<std::remove_pointer_t<Result> >); // enforce same constness
return (Result) (void *) ptr;
}
template <class Result, class From>
forceinline Result ptr_reinterpret_cast(const From *ptr) {
static_assert(std::is_pointer_v<Result>);
static_assert(std::is_const_v<std::remove_pointer_t<Result> >); // required
return (Result) (const void *) ptr;
}
/************************************************************************* /*************************************************************************
// type_traits // type_traits
**************************************************************************/ **************************************************************************/
@@ -81,6 +63,20 @@ struct UnsignedSizeOf {
static constexpr unsigned value = unsigned(Size); static constexpr unsigned value = unsigned(Size);
}; };
// a reinterpret_cast that does not trigger -Wcast-align warnings
template <class Result, class From>
forceinline Result ptr_reinterpret_cast(From *ptr) noexcept {
static_assert(std::is_pointer_v<Result>);
static_assert(!std::is_const_v<std::remove_pointer_t<Result> >); // enforce same constness
return reinterpret_cast<Result>(reinterpret_cast<void *>(ptr));
}
template <class Result, class From>
forceinline Result ptr_reinterpret_cast(const From *ptr) noexcept {
static_assert(std::is_pointer_v<Result>);
static_assert(std::is_const_v<std::remove_pointer_t<Result> >); // required
return reinterpret_cast<Result>(reinterpret_cast<const void *>(ptr));
}
class noncopyable { class noncopyable {
protected: protected:
forceinline constexpr noncopyable() noexcept {} forceinline constexpr noncopyable() noexcept {}
+6 -6
View File
@@ -130,15 +130,15 @@ using XSPAN_NAMESPACE_NAME::raw_index_bytes; // overloaded for all classes
// helper for implicit pointer conversions and MemBuffer overloads // helper for implicit pointer conversions and MemBuffer overloads
template <class R, class T> template <class R, class T>
inline R *xspan_make_helper__(R * /*dummy*/, T *first) may_throw { inline R *xspan_make_helper__(T *first) noexcept {
return first; // IMPORTANT: no cast here to detect bad usage return first; // IMPORTANT: no cast here to detect bad usage
} }
template <class R> template <class R>
inline R *xspan_make_helper__(R * /*dummy*/, std::nullptr_t /*first*/) noexcept { inline R *xspan_make_helper__(std::nullptr_t /*first*/) noexcept {
return nullptr; return nullptr;
} }
template <class R> template <class R>
inline R *xspan_make_helper__(R * /*dummy*/, MemBuffer &mb) noexcept { inline R *xspan_make_helper__(MemBuffer &mb) noexcept {
return (R *) membuffer_get_void_ptr(mb); return (R *) membuffer_get_void_ptr(mb);
} }
@@ -148,9 +148,9 @@ inline R *xspan_make_helper__(R * /*dummy*/, MemBuffer &mb) noexcept {
#define XSPAN_S(type) type * #define XSPAN_S(type) type *
// create a value // create a value
#define XSPAN_0_MAKE(type, first, ...) (xspan_make_helper__((type *) nullptr, (first))) #define XSPAN_0_MAKE(type, first, ...) (xspan_make_helper__<type>((first)))
#define XSPAN_P_MAKE(type, first, ...) (xspan_make_helper__((type *) nullptr, (first))) #define XSPAN_P_MAKE(type, first, ...) (xspan_make_helper__<type>((first)))
#define XSPAN_S_MAKE(type, first, ...) (xspan_make_helper__((type *) nullptr, (first))) #define XSPAN_S_MAKE(type, first, ...) (xspan_make_helper__<type>((first)))
// define a variable // define a variable
#define XSPAN_0_VAR(type, var, first, ...) type *var = XSPAN_0_MAKE(type, (first)) #define XSPAN_0_VAR(type, var, first, ...) type *var = XSPAN_0_MAKE(type, (first))