mirror of
https://github.com/upx/upx.git
synced 2024-11-23 04:39:59 +00:00
all: various cleanups
This commit is contained in:
parent
38a676f6f7
commit
37b923245d
@ -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)
|
||||
|
4
NEWS
4
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
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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__)
|
||||
|
@ -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;
|
||||
|
@ -31,24 +31,6 @@
|
||||
|
||||
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
|
||||
**************************************************************************/
|
||||
@ -81,6 +63,20 @@ struct UnsignedSizeOf {
|
||||
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 {
|
||||
protected:
|
||||
forceinline constexpr noncopyable() noexcept {}
|
||||
|
@ -130,15 +130,15 @@ using XSPAN_NAMESPACE_NAME::raw_index_bytes; // overloaded for all classes
|
||||
|
||||
// helper for implicit pointer conversions and MemBuffer overloads
|
||||
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
|
||||
}
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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__<type>((first)))
|
||||
#define XSPAN_P_MAKE(type, first, ...) (xspan_make_helper__<type>((first)))
|
||||
#define XSPAN_S_MAKE(type, first, ...) (xspan_make_helper__<type>((first)))
|
||||
|
||||
// define a variable
|
||||
#define XSPAN_0_VAR(type, var, first, ...) type *var = XSPAN_0_MAKE(type, (first))
|
||||
|
Loading…
Reference in New Issue
Block a user