diff --git a/CMakeLists.txt b/CMakeLists.txt index c966aec3..d3ffcb55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,13 +191,14 @@ if(NOT DEFINED HAVE_UNISTD_H) check_include_file("unistd.h" HAVE_UNISTD_H) endif() if(NOT DEFINED HAVE_UTIMENSAT) + # proper checking for utimensat() is somewhat messy check_function_exists(utimensat HAVE_UTIMENSAT_FUNCTION__) if(HAVE_UTIMENSAT_FUNCTION__) check_symbol_exists(utimensat "sys/types.h;fcntl.h;sys/stat.h" 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) - 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() if(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC OR HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) set(HAVE_UTIMENSAT 1) diff --git a/NEWS b/NEWS index 0e524dab..be8a3b54 100644 --- a/NEWS +++ b/NEWS @@ -3,12 +3,16 @@ User visible changes for UPX ================================================================== 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 Changes in 4.2.0 (26 Oct 2023): * 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) * 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+ * bug fixes - see https://github.com/upx/upx/milestone/13 diff --git a/src/check/dt_cxxlib.cpp b/src/check/dt_cxxlib.cpp index 28271c37..d11e998b 100644 --- a/src/check/dt_cxxlib.cpp +++ b/src/check/dt_cxxlib.cpp @@ -26,6 +26,9 @@ #include "../conf.h" +// various cxxlib checks +// (modern compilers will optimize away much of this code) + /************************************************************************* // compile-time checks **************************************************************************/ @@ -89,6 +92,7 @@ ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_le("abc", "abz")) **************************************************************************/ TEST_CASE("ptr_reinterpret_cast") { + // check that we don't trigger any -Wcast-align warnings using upx::ptr_reinterpret_cast; byte *an = nullptr; int *in = nullptr; @@ -127,7 +131,6 @@ TEST_CASE("noncopyable") { /************************************************************************* // TriBool checks -// (modern compilers will optimize away most of this code) **************************************************************************/ namespace { diff --git a/src/conf.h b/src/conf.h index a946292b..f8fb8f6b 100644 --- a/src/conf.h +++ b/src/conf.h @@ -190,13 +190,16 @@ typedef upx_int64_t upx_off_t; // portab **************************************************************************/ -// just in case +// some system headers may define these, so undef just in case #undef _ #undef __ #undef ___ #undef dos +#undef large #undef linux #undef small +#undef SP +#undef SS #undef tos #undef unix #if (ACC_OS_POSIX) && !defined(__unix__) diff --git a/src/pefile.cpp b/src/pefile.cpp index 31241f91..176ba812 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -1540,41 +1540,41 @@ void PeFile::processLoadConf(Reloc *rel, const Interval *iv, // 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 child; }; -struct alignas(1) PeFile::Resource::res_dir { +struct alignas(1) PeFile::Resource::res_dir final { byte _[12]; // flags, timedate, version LE16 namedentr; 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 // 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 size; byte _[8]; // codepage, reserved }; -struct PeFile::Resource::upx_rnode { +struct PeFile::Resource::upx_rnode /*not_final*/ { unsigned id; byte *name; 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; upx_rnode **children; 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; unsigned newoffset; res_data data; diff --git a/src/util/cxxlib.h b/src/util/cxxlib.h index 030bc74e..f15aced4 100644 --- a/src/util/cxxlib.h +++ b/src/util/cxxlib.h @@ -31,24 +31,6 @@ namespace upx { -/************************************************************************* -// misc -**************************************************************************/ - -// a reinterpret_cast that does not trigger -Wcast-align warnings -template -forceinline Result ptr_reinterpret_cast(From *ptr) { - static_assert(std::is_pointer_v); - static_assert(!std::is_const_v >); // enforce same constness - return (Result) (void *) ptr; -} -template -forceinline Result ptr_reinterpret_cast(const From *ptr) { - static_assert(std::is_pointer_v); - static_assert(std::is_const_v >); // required - return (Result) (const void *) ptr; -} - /************************************************************************* // type_traits **************************************************************************/ @@ -81,6 +63,20 @@ struct UnsignedSizeOf { static constexpr unsigned value = unsigned(Size); }; +// a reinterpret_cast that does not trigger -Wcast-align warnings +template +forceinline Result ptr_reinterpret_cast(From *ptr) noexcept { + static_assert(std::is_pointer_v); + static_assert(!std::is_const_v >); // enforce same constness + return reinterpret_cast(reinterpret_cast(ptr)); +} +template +forceinline Result ptr_reinterpret_cast(const From *ptr) noexcept { + static_assert(std::is_pointer_v); + static_assert(std::is_const_v >); // required + return reinterpret_cast(reinterpret_cast(ptr)); +} + class noncopyable { protected: forceinline constexpr noncopyable() noexcept {} diff --git a/src/util/xspan.h b/src/util/xspan.h index 06d53afc..9750824f 100644 --- a/src/util/xspan.h +++ b/src/util/xspan.h @@ -130,15 +130,15 @@ using XSPAN_NAMESPACE_NAME::raw_index_bytes; // overloaded for all classes // helper for implicit pointer conversions and MemBuffer overloads template -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 } template -inline R *xspan_make_helper__(R * /*dummy*/, std::nullptr_t /*first*/) noexcept { +inline R *xspan_make_helper__(std::nullptr_t /*first*/) noexcept { return nullptr; } template -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); } @@ -148,9 +148,9 @@ inline R *xspan_make_helper__(R * /*dummy*/, MemBuffer &mb) noexcept { #define XSPAN_S(type) type * // create a value -#define XSPAN_0_MAKE(type, first, ...) (xspan_make_helper__((type *) nullptr, (first))) -#define XSPAN_P_MAKE(type, first, ...) (xspan_make_helper__((type *) nullptr, (first))) -#define XSPAN_S_MAKE(type, first, ...) (xspan_make_helper__((type *) nullptr, (first))) +#define XSPAN_0_MAKE(type, first, ...) (xspan_make_helper__((first))) +#define XSPAN_P_MAKE(type, first, ...) (xspan_make_helper__((first))) +#define XSPAN_S_MAKE(type, first, ...) (xspan_make_helper__((first))) // define a variable #define XSPAN_0_VAR(type, var, first, ...) type *var = XSPAN_0_MAKE(type, (first))