diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c920f9c..75b461f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,7 +68,9 @@ jobs: matrix: include: - { os: ubuntu-22.04, use_m32: true } - - { os: ubuntu-20.04, use_m32: false } # use_m32 also works here, but save some CI time + - { os: ubuntu-20.04, use_m32: true } # use_m32 also works here, but save some CI time + env: + UPX_CONFIG_EXPECT_THREADS: 'ON' steps: - name: 'Install extra 32-bit and Windows packages' if: ${{ matrix.use_m32 }} @@ -76,6 +78,10 @@ jobs: sudo dpkg --add-architecture i386 sudo apt-get update sudo apt-get install -y g++-multilib g++-mingw-w64-i686 g++-mingw-w64-x86-64 + # make sure that we use posix-threads (pthreads) and NOT win32-threads + for f in i686-w64-mingw32-g++ i686-w64-mingw32-gcc x86_64-w64-mingw32-g++ x86_64-w64-mingw32-gcc; do + if test -f /usr/bin/$f-posix; then sudo update-alternatives --set $f /usr/bin/$f-posix; fi + done - name: 'Check out code' uses: actions/checkout@v4 with: { submodules: true } diff --git a/.github/workflows/weekly-ci-cc-llvm-mingw.yml b/.github/workflows/weekly-ci-cc-llvm-mingw.yml index e4f5ecc5..a850f8b0 100644 --- a/.github/workflows/weekly-ci-cc-llvm-mingw.yml +++ b/.github/workflows/weekly-ci-cc-llvm-mingw.yml @@ -68,14 +68,14 @@ jobs: run: | export CC="i686-w64-mingw32-clang -static" CXX="i686-w64-mingw32-clang++ -static" CC="$CC -D_WIN32_WINNT=0x0400"; CXX="$CXX -D_WIN32_WINNT=0x0400" - export CMAKE_SYSTEM_NAME=Windows # CMAKE_CROSSCOMPILING_EMULATOR=wine + export CMAKE_SYSTEM_NAME=Windows CMAKE_CROSSCOMPILING_EMULATOR=wine make UPX_XTARGET=i686-w64-mingw32-clang xtarget/debug xtarget/release - name: 'Build clang x86_64' if: success() || failure() # run this step even if the previous step failed run: | export CC="x86_64-w64-mingw32-clang -static" CXX="x86_64-w64-mingw32-clang++ -static" CC="$CC -D_WIN32_WINNT=0x0400"; CXX="$CXX -D_WIN32_WINNT=0x0400" - export CMAKE_SYSTEM_NAME=Windows # CMAKE_CROSSCOMPILING_EMULATOR=wine64 + export CMAKE_SYSTEM_NAME=Windows CMAKE_CROSSCOMPILING_EMULATOR=wine64 make UPX_XTARGET=x86_64-w64-mingw32-clang xtarget/debug xtarget/release - name: 'Make artifact' run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 050e7f4f..1ed26ecb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,15 @@ function(print_var) endif() endforeach() endfunction() +function(print_have_symbol) + foreach(symbol ${ARGV}) + set(var_name "HAVE_symbol_${symbol}") + check_symbol_exists(${symbol} "stddef.h" ${var_name}) + if(${var_name}) + message(STATUS "HAVE ${symbol}") + endif() + endforeach() +endfunction() # useful for CI jobs: allow settings via environment and cache result function(upx_cache_bool_vars) @@ -403,6 +412,20 @@ function(upx_add_glob_files) set(${var_name} "${result}" PARENT_SCOPE) # return value endfunction() +# examine MinGW/Cygwin compiler configuration +if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git") +if(WIN32 OR MINGW OR CYGWIN) +if(CMAKE_C_COMPILER_ID MATCHES "(Clang|GNU)") + # runtime library: msvcrt vs ucrt vs cygwin + print_have_symbol(__CRTDLL__ __CYGWIN__ __CYGWIN32__ __MINGW32__ __MINGW64_VERSION_MAJOR __MSVCRT__ _UCRT) + # exception handing: SJLJ (setjmp/longjmp) vs DWARF vs SEH + print_have_symbol(__GCC_HAVE_DWARF2_CFI_ASM __SEH__ __USING_SJLJ_EXCEPTIONS__) + # threads: win32 vs posix/pthread/winpthreads vs mcfgthread + print_have_symbol(_REENTRANT __USING_MCFGTHREAD__) +endif() +endif() +endif() + upx_cmake_include_hook(3_common_compilation_flags_end) #*********************************************************************** @@ -419,7 +442,7 @@ upx_cmake_include_hook(4_targets_begin) if(NOT UPX_CONFIG_DISABLE_THREADS) find_package(Threads) endif() -# make sure that threads are indeed fully supported +# make sure that threads are indeed fully supported in C++ if(Threads_FOUND) foreach(f std_lock_guard.cpp) set(CMAKE_TRY_COMPILE_TARGET_TYPE "EXECUTABLE") @@ -427,6 +450,7 @@ if(Threads_FOUND) "${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake/try_compile/${f}" OUTPUT_VARIABLE output) if(NOT result) + # failed; under MinGW be sure the use the posix-threads and NOT the win32-threads version #message(STATUS "${output}") # debug output from try_compile set(Threads_FOUND OFF) break() diff --git a/misc/make/Makefile-extra.mk b/misc/make/Makefile-extra.mk index 720bae22..6a489589 100644 --- a/misc/make/Makefile-extra.mk +++ b/misc/make/Makefile-extra.mk @@ -6,6 +6,10 @@ ifeq ($(UPX_MAKEFILE_EXTRA_MK_INCLUDED),) UPX_MAKEFILE_EXTRA_MK_INCLUDED := 1 +override check_defined = $(foreach 1,$1,$(if $(filter undefined,$(origin $1)),$(error ERROR: variable '$1' is not defined),)) +override check_undefined = $(foreach 1,$1,$(if $(filter undefined,$(origin $1)),,$(error ERROR: variable '$1' is already defined))) +$(call check_undefined,run_config_and_build) + #*********************************************************************** # extra builds: some pre-defined build configurations #*********************************************************************** @@ -223,7 +227,7 @@ xtarget/all: xtarget/debug xtarget/release xtarget/debug: build/xtarget/$(UPX_XTARGET)/debug xtarget/release: build/xtarget/$(UPX_XTARGET)/release # set new default -.DEFAULT_GOAL = build/xtarget/$(UPX_XTARGET)/release +.DEFAULT_GOAL = build/xtarget/$(UPX_XTARGET)/release endif endif @@ -265,7 +269,7 @@ endif # bug work-around SUBMODULES = doctest lzma-sdk ucl valgrind zlib -dummy := $(foreach m,$(SUBMODULES),$(if $(wildcard vendor/$m/[CL]*),$m,\ - $(error ERROR: missing git submodule '$m'; run 'git submodule update --init'))) +$(foreach 1,$(SUBMODULES),$(if $(wildcard vendor/$1/[CL]*),,\ + $(error ERROR: missing git submodule '$1'; run 'git submodule update --init'))) endif # UPX_MAKEFILE_EXTRA_MK_INCLUDED diff --git a/misc/podman/cross-compile-upx-ubuntu/10-create-image.sh b/misc/podman/cross-compile-upx-ubuntu/10-create-image.sh index 058d8739..bab7c5fb 100755 --- a/misc/podman/cross-compile-upx-ubuntu/10-create-image.sh +++ b/misc/podman/cross-compile-upx-ubuntu/10-create-image.sh @@ -9,7 +9,7 @@ argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")" # NOTE: this image is based on rebuild-stubs/upx-stubtools-20221212-v6, # so you have to create that image first # WARNING: we install many packages, so the resulting image needs A LOT of disk space! -image=upx-cross-compile-ubuntu2204-20230721-v1 +image=upx-cross-compile-ubuntu2204-20230721-v2 [[ $1 == --print-image ]] && echo "$image" && exit 0 podman build -t "$image" -f "$argv0dir/Dockerfile" "$argv0dir" diff --git a/misc/podman/cross-compile-upx-ubuntu/Dockerfile b/misc/podman/cross-compile-upx-ubuntu/Dockerfile index 24eafa64..e97374d4 100644 --- a/misc/podman/cross-compile-upx-ubuntu/Dockerfile +++ b/misc/podman/cross-compile-upx-ubuntu/Dockerfile @@ -2,7 +2,7 @@ # so you have to create that image first # WARNING: we install many packages, so the resulting image needs A LOT of disk space! FROM localhost/upx-stubtools-20221212-v6 -ENV UPX_CONTAINER_IMAGE_NAME=upx-cross-compile-ubuntu2204-20230721-v1 +ENV UPX_CONTAINER_IMAGE_NAME=upx-cross-compile-ubuntu2204-20230721-v2 ARG DEBIAN_FRONTEND=noninteractive USER root @@ -34,6 +34,8 @@ RUN apt-get update && apt-get upgrade -y \ # Windows cross compilers g++-mingw-w64-i686 \ g++-mingw-w64-x86-64 \ + # make sure that we use posix-threads (pthreads) and NOT win32-threads + && for f in i686-w64-mingw32-g++ i686-w64-mingw32-gcc x86_64-w64-mingw32-g++ x86_64-w64-mingw32-gcc; do update-alternatives --set $f /usr/bin/$f-posix; done \ && true RUN apt-get install -y \ # clang-14 and tools diff --git a/misc/podman/cross-compile-upx-ubuntu/packages.txt b/misc/podman/cross-compile-upx-ubuntu/packages.txt index 039c73c4..6ed4f539 100644 --- a/misc/podman/cross-compile-upx-ubuntu/packages.txt +++ b/misc/podman/cross-compile-upx-ubuntu/packages.txt @@ -7,7 +7,7 @@ ii adduser 3.118ubuntu5 ii adwaita-icon-theme 41.0-1ubuntu1 all default icon theme of GNOME (small subset) ii alsa-topology-conf 1.2.5.1-2 all ALSA topology configuration files ii alsa-ucm-conf 1.2.6.3-1ubuntu1.8 all ALSA Use Case Manager configuration files -ii apt 2.4.10 amd64 commandline package manager +ii apt 2.4.11 amd64 commandline package manager ii aria2 1.36.0-1 amd64 High speed download utility ii at-spi2-core 2.44.0-3 amd64 Assistive Technology Service Provider Interface (dbus core) ii base-files 12ubuntu4.4 amd64 Debian base system miscellaneous files @@ -297,7 +297,7 @@ ii libacl1:amd64 2.3.1-1 ii libaio1:amd64 0.3.112-13build1 amd64 Linux kernel AIO access library - shared library ii libapparmor1:amd64 3.0.4-2ubuntu2.2 amd64 changehat AppArmor library ii libapparmor1:i386 3.0.4-2ubuntu2.2 i386 changehat AppArmor library -ii libapt-pkg6.0:amd64 2.4.10 amd64 package management runtime library +ii libapt-pkg6.0:amd64 2.4.11 amd64 package management runtime library ii libarchive13:amd64 3.6.0-1ubuntu1 amd64 Multi-format archive and compression library (shared library) ii libargon2-1:amd64 0~20171227-0.3 amd64 memory-hard hashing function - runtime library ii libaria2-0:amd64 1.36.0-1 amd64 C++ library interface to aria2 @@ -792,7 +792,7 @@ ii libpmemobj1:amd64 1.11.1-3build1 ii libpng16-16:amd64 1.6.37-3build5 amd64 PNG library - runtime (version 1.6) ii libpng16-16:i386 1.6.37-3build5 i386 PNG library - runtime (version 1.6) ii libpopt0:amd64 1.18-3build1 amd64 lib for parsing cmdline parameters -ii libprocps8:amd64 2:3.3.17-6ubuntu2 amd64 library for accessing process information from /proc +ii libprocps8:amd64 2:3.3.17-6ubuntu2.1 amd64 library for accessing process information from /proc ii libproxy1v5:amd64 0.4.17-2 amd64 automatic proxy configuration management library (shared) ii libproxy1v5:i386 0.4.17-2 i386 automatic proxy configuration management library (shared) ii libpsl5:amd64 0.21.0-1.2build2 amd64 Library for Public Suffix List (shared libraries) @@ -1138,12 +1138,13 @@ ii parallel 20210822+ds-2 ii passwd 1:4.8.1-2ubuntu2.1 amd64 change and administer password and group data ii patch 2.7.6-7build2 amd64 Apply a diff file to an original ii patchelf 0.14.3-1 amd64 modify properties of ELF executables +ii patchutils 0.4.2-1build2 amd64 Utilities to work with patches ii pax-utils 1.2.9-1 amd64 Security-focused ELF files checking tool ii paxctl 0.9-1build1 amd64 new PaX control program for using the PT_PAX_FLAGS marking ii perl 5.34.0-3ubuntu1.2 amd64 Larry Wall's Practical Extraction and Report Language ii perl-base 5.34.0-3ubuntu1.2 amd64 minimal Perl system ii perl-modules-5.34 5.34.0-3ubuntu1.2 all Core Perl modules -ii procps 2:3.3.17-6ubuntu2 amd64 /proc file system utilities +ii procps 2:3.3.17-6ubuntu2.1 amd64 /proc file system utilities ii publicsuffix 20211207.1025-1 all accurate, machine-readable list of domain name suffixes ii python2-minimal 2.7.18-3 amd64 minimal subset of the Python2 language ii python2.7-minimal 2.7.18-13ubuntu1.1 amd64 Minimal subset of the Python language (version 2.7) @@ -1230,7 +1231,7 @@ ii zstd 1.4.8+dfsg-3build1 ||/ Name Version Architecture Description Packages sorted by Installed-Size: - 8373937 ===== TOTAL (1224 packages) + 8374158 ===== TOTAL (1225 packages) 545062 libwine amd64 474522 libwine i386 270995 llvm-14-dev amd64 @@ -1485,8 +1486,8 @@ Packages sorted by Installed-Size: 4249 ncurses-term all 4236 xkb-data all 4204 llvm-14-linker-tools amd64 - 4156 apt amd64 4147 ripgrep amd64 + 4141 apt amd64 4082 libglib2.0-0 amd64 4024 python3-pygments all 3930 vim amd64 @@ -1503,7 +1504,7 @@ Packages sorted by Installed-Size: 3333 libxml2-dev amd64 3261 liblsan0-ppc64-cross all 3247 libstdc++6-ppc64-cross all - 3181 libapt-pkg6.0 amd64 + 3198 libapt-pkg6.0 amd64 3147 libvpx7 i386 3139 libhwasan0-arm64-cross all 3135 liblsan0-ppc64el-cross all @@ -1973,6 +1974,7 @@ Packages sorted by Installed-Size: 221 libxcb1 i386 221 bfs amd64 220 libidn2-0 amd64 + 219 patchutils amd64 219 libtirpc3 amd64 219 librhash0 amd64 217 libasound2-data all diff --git a/misc/podman/rebuild-stubs/Dockerfile b/misc/podman/rebuild-stubs/Dockerfile index 169e758d..ca7b3878 100644 --- a/misc/podman/rebuild-stubs/Dockerfile +++ b/misc/podman/rebuild-stubs/Dockerfile @@ -15,7 +15,7 @@ RUN dpkg --add-architecture i386 \ # the full UPX binary inside the container via CMake: 7zip bfs busybox bzip2 cabextract ccache chrpath cmake cpio curl elfutils fd-find file fzf \ g++ gawk gdb gojq ht htop hyperfine jq libzstd-dev lsb-release lz4 lzip lzop \ - mksh moreutils ninja-build p7zip parallel patch patchelf pax-utils paxctl \ + mksh moreutils ninja-build p7zip parallel patch patchelf patchutils pax-utils paxctl \ python3 python3-pyasn1 python3-pycryptodome python3-zstd \ re2c ripgrep rsync screen universal-ctags unzip vim yash zip zlib1g-dev zsh zstd \ # extra packages for compiling with "gcc -m32" and and "gcc -mx32": diff --git a/misc/podman/rebuild-stubs/packages.txt b/misc/podman/rebuild-stubs/packages.txt index 95ef39c6..22d3b0f1 100644 --- a/misc/podman/rebuild-stubs/packages.txt +++ b/misc/podman/rebuild-stubs/packages.txt @@ -3,7 +3,7 @@ Packages: Desired=Unknown/Install/Remove/Purge/Hold ii 7zip 21.07+dfsg-4 amd64 7-Zip file archiver with a high compression ratio ii adduser 3.118ubuntu5 all add and remove users and groups -ii apt 2.4.10 amd64 commandline package manager +ii apt 2.4.11 amd64 commandline package manager ii aria2 1.36.0-1 amd64 High speed download utility ii base-files 12ubuntu4.4 amd64 Debian base system miscellaneous files ii base-passwd 3.5.52build1 amd64 Debian base system master password and group files @@ -78,7 +78,7 @@ ii lib32stdc++-11-dev 11.4.0-1ubuntu1~22.04 amd64 ii lib32stdc++6 12.3.0-1ubuntu1~22.04 amd64 GNU Standard C++ Library v3 (32 bit Version) ii lib32ubsan1 12.3.0-1ubuntu1~22.04 amd64 UBSan -- undefined behaviour sanitizer (32bit) ii libacl1:amd64 2.3.1-1 amd64 access control list - shared library -ii libapt-pkg6.0:amd64 2.4.10 amd64 package management runtime library +ii libapt-pkg6.0:amd64 2.4.11 amd64 package management runtime library ii libarchive13:amd64 3.6.0-1ubuntu1 amd64 Multi-format archive and compression library (shared library) ii libaria2-0:amd64 1.36.0-1 amd64 C++ library interface to aria2 ii libasan6:amd64 11.4.0-1ubuntu1~22.04 amd64 AddressSanitizer -- a fast memory error detector @@ -186,7 +186,7 @@ ii libpcre2-8-0:amd64 10.39-3ubuntu0.1 amd64 ii libpcre3:amd64 2:8.39-13ubuntu0.22.04.1 amd64 Old Perl 5 Compatible Regular Expression Library - runtime files ii libperl5.34:amd64 5.34.0-3ubuntu1.2 amd64 shared Perl library ii libpopt0:amd64 1.18-3build1 amd64 lib for parsing cmdline parameters -ii libprocps8:amd64 2:3.3.17-6ubuntu2 amd64 library for accessing process information from /proc +ii libprocps8:amd64 2:3.3.17-6ubuntu2.1 amd64 library for accessing process information from /proc ii libpsl5:amd64 0.21.0-1.2build2 amd64 Library for Public Suffix List (shared libraries) ii libpython2.7-minimal:amd64 2.7.18-13ubuntu1.1 amd64 Minimal subset of the Python language (version 2.7) ii libpython3-stdlib:amd64 3.10.6-1~22.04 amd64 interactive high-level object-oriented language (default python3 version) @@ -278,12 +278,13 @@ ii parallel 20210822+ds-2 all ii passwd 1:4.8.1-2ubuntu2.1 amd64 change and administer password and group data ii patch 2.7.6-7build2 amd64 Apply a diff file to an original ii patchelf 0.14.3-1 amd64 modify properties of ELF executables +ii patchutils 0.4.2-1build2 amd64 Utilities to work with patches ii pax-utils 1.2.9-1 amd64 Security-focused ELF files checking tool ii paxctl 0.9-1build1 amd64 new PaX control program for using the PT_PAX_FLAGS marking ii perl 5.34.0-3ubuntu1.2 amd64 Larry Wall's Practical Extraction and Report Language ii perl-base 5.34.0-3ubuntu1.2 amd64 minimal Perl system ii perl-modules-5.34 5.34.0-3ubuntu1.2 all Core Perl modules -ii procps 2:3.3.17-6ubuntu2 amd64 /proc file system utilities +ii procps 2:3.3.17-6ubuntu2.1 amd64 /proc file system utilities ii python2-minimal 2.7.18-3 amd64 minimal subset of the Python2 language ii python2.7-minimal 2.7.18-13ubuntu1.1 amd64 Minimal subset of the Python language (version 2.7) ii python3 3.10.6-1~22.04 amd64 interactive high-level object-oriented language (default python3 version) @@ -330,7 +331,7 @@ ii zstd 1.4.8+dfsg-3build1 amd64 ||/ Name Version Architecture Description Packages sorted by Installed-Size: - 754091 ===== TOTAL (324 packages) + 754312 ===== TOTAL (325 packages) 52747 gcc-11 amd64 34444 libicu70 amd64 32782 vim-runtime all @@ -372,8 +373,8 @@ Packages sorted by Installed-Size: 5768 libpython3.10 amd64 5103 libpython3.10-minimal amd64 4249 ncurses-term all - 4156 apt amd64 4147 ripgrep amd64 + 4141 apt amd64 4082 libglib2.0-0 amd64 3930 vim amd64 3643 python2.7-minimal amd64 @@ -383,7 +384,7 @@ Packages sorted by Installed-Size: 3405 libmpfr6 amd64 3399 util-linux amd64 3347 libaria2-0 amd64 - 3181 libapt-pkg6.0 amd64 + 3198 libapt-pkg6.0 amd64 3013 libboost-regex1.74.0 amd64 2961 liblsan0 amd64 2943 parallel all @@ -542,6 +543,7 @@ Packages sorted by Installed-Size: 225 libcrypt1 amd64 221 bfs amd64 220 libidn2-0 amd64 + 219 patchutils amd64 219 libtirpc3 amd64 219 librhash0 amd64 214 dash amd64 diff --git a/src/Makefile b/src/Makefile index a99ad64c..c036b5de 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,8 +20,8 @@ endif # NOTE that top-level Makefile .DEFAULT_GOAL is build/release .DEFAULT_GOAL = build/debug -build/debug: $(top_srcdir)/build/debug/upx -build/release: $(top_srcdir)/build/release/upx +build/debug: $(top_srcdir)/build/debug +build/release: $(top_srcdir)/build/release .NOTPARALLEL: # because the actual builds use "cmake --parallel" .PHONY: PHONY @@ -33,14 +33,15 @@ debug: build/debug release: build/release all build/all: build/debug build/release -$(top_srcdir)/build/debug/upx: PHONY +$(top_srcdir)/build/debug: PHONY $(MAKE) -C $(top_srcdir) build/debug -$(top_srcdir)/build/release/upx: PHONY +$(top_srcdir)/build/release: PHONY $(MAKE) -C $(top_srcdir) build/release # convenience +CTEST = ctest test: $(top_srcdir)/$(.DEFAULT_GOAL) - cd $(top_srcdir)/$(.DEFAULT_GOAL) && ctest + cd $(top_srcdir)/$(.DEFAULT_GOAL) && $(CTEST) # # "make run-testsuite" @@ -69,10 +70,10 @@ run-testsuite: run-testsuite-release run-testsuite-%: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR) run-testsuite-%: export upx_testsuite_BUILDDIR := ./tmp-upx-testsuite run-testsuite-debug: export upx_exe := $(top_srcdir)/build/debug/upx -run-testsuite-debug: PHONY $(top_srcdir)/build/debug/upx +run-testsuite-debug: PHONY $(top_srcdir)/build/debug time -p bash $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh run-testsuite-release: export upx_exe := $(top_srcdir)/build/release/upx -run-testsuite-release: PHONY $(top_srcdir)/build/release/upx +run-testsuite-release: PHONY $(top_srcdir)/build/release time -p bash $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh endif endif diff --git a/src/check/dt_check.cpp b/src/check/dt_check.cpp index 575e4aff..b5671ce5 100644 --- a/src/check/dt_check.cpp +++ b/src/check/dt_check.cpp @@ -617,13 +617,13 @@ TEST_CASE("libc snprintf") { intmax_t im = ll; uintmax_t um = llu; snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%jd", -4, 0, 0, 0, 0, 0, 0, 0, 4, im); - WARN_EQ(strcmp(buf, "-4.0.0.0.0.0.0.0.4.-1"), 0); + CHECK_EQ(strcmp(buf, "-4.0.0.0.0.0.0.0.4.-1"), 0); snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%ju", -5, 0, 0, 0, 0, 0, 0, 0, 5, um); - WARN_EQ(strcmp(buf, "-5.0.0.0.0.0.0.0.5.18446744073709551615"), 0); + CHECK_EQ(strcmp(buf, "-5.0.0.0.0.0.0.0.5.18446744073709551615"), 0); snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%jx", -6, 0, 0, 0, 0, 0, 0, 0, 6, um); - WARN_EQ(strcmp(buf, "-6.0.0.0.0.0.0.0.6.ffffffffffffffff"), 0); + CHECK_EQ(strcmp(buf, "-6.0.0.0.0.0.0.0.6.ffffffffffffffff"), 0); snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%#jx", -7, 0, 0, 0, 0, 0, 0, 0, 7, um); - WARN_EQ(strcmp(buf, "-7.0.0.0.0.0.0.0.7.0xffffffffffffffff"), 0); + CHECK_EQ(strcmp(buf, "-7.0.0.0.0.0.0.0.7.0xffffffffffffffff"), 0); } #if 0 diff --git a/src/conf.h b/src/conf.h index 5f3594ab..30d99ad0 100644 --- a/src/conf.h +++ b/src/conf.h @@ -322,6 +322,7 @@ typedef upx_int64_t upx_off_t; #define VALGRIND_MAKE_MEM_UNDEFINED(addr, len) 0 #endif +// TODO later: check __MINGW_PRINTF_FORMAT #if defined(_WIN32) && defined(__MINGW32__) && defined(__GNUC__) && !defined(__clang__) #define attribute_format(a, b) __attribute__((__format__(__gnu_printf__, a, b))) #elif (ACC_CC_CLANG || ACC_CC_GNUC) diff --git a/src/headers.h b/src/headers.h index 3e0973ae..a837ce67 100644 --- a/src/headers.h +++ b/src/headers.h @@ -57,9 +57,9 @@ static_assert(sizeof(void *) == 8); #if !defined(_FILE_OFFSET_BITS) #define _FILE_OFFSET_BITS 64 #endif -#if defined(_WIN32) && defined(__MINGW32__) && defined(__GNUC__) -#if !defined(_USE_MINGW_ANSI_STDIO) -#define _USE_MINGW_ANSI_STDIO 1 +#if defined(_WIN32) && defined(__MINGW32__) && (defined(__clang__) || defined(__GNUC__)) +#if !defined(__USE_MINGW_ANSI_STDIO) +#define __USE_MINGW_ANSI_STDIO 1 #endif #endif #if defined(_WIN32) diff --git a/src/help.cpp b/src/help.cpp index 6d0b6e5c..8fd673a4 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -518,8 +518,8 @@ void show_sysinfo(const char *options_var) { #if defined(__MSVCRT_VERSION__) cf_print("__MSVCRT_VERSION__", "0x%04llx", __MSVCRT_VERSION__ + 0); #endif -#if defined(_USE_MINGW_ANSI_STDIO) - cf_print("_USE_MINGW_ANSI_STDIO", "%lld", _USE_MINGW_ANSI_STDIO + 0, 3); +#if defined(__MINGW64_VERSION_MAJOR) + cf_print("__MINGW64_VERSION_MAJOR", "%lld", __MINGW64_VERSION_MAJOR + 0); #endif #if defined(__USE_MINGW_ANSI_STDIO) cf_print("__USE_MINGW_ANSI_STDIO", "%lld", __USE_MINGW_ANSI_STDIO + 0, 3); diff --git a/src/pefile.cpp b/src/pefile.cpp index 5bb723c0..eb9db0ec 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -296,8 +296,8 @@ struct FixDeleter final { // helper so we don't leak memory on exceptions } // namespace void PeFile::Reloc::RelocationBlock::reset() noexcept { - rel = nullptr; - rel1 = nullptr; + rel = nullptr; // SPAN_0 + rel1 = nullptr; // SPAN_0 count = 0; } @@ -335,13 +335,13 @@ void PeFile::Reloc::initSpans() { rb.reset(); } -// check values for better error messages (instead of getting a cryptic SPAN failure) +// check values so that we have better error messages (instead of getting a cryptic SPAN failure) bool PeFile::Reloc::readFromRelocationBlock(byte *next_rb) { // set rb assert(!start_did_alloc); const unsigned off = ptr_udiff_bytes(next_rb, start); assert((off & 1) == 0); rb.reset(); - if (off >= start_size_in_bytes) // use ">=" instead of strict "==" + if (off >= start_size_in_bytes) // permissive: use ">=" instead of strict "==" return false; // EOF if (start_size_in_bytes - off < 8) throwCantPack("relocs overflow"); @@ -418,7 +418,7 @@ void PeFile::Reloc::finish(byte *(&result_ptr), unsigned &result_size) { for (unsigned ic = 0; ic < counts[0]; ic++) { const auto pos_ptr = start_buf + (RELOC_INPLACE_OFFSET + 4 * ic); const unsigned pos = get_le32(pos_ptr); - if (ic > 0 && get_le32(pos_ptr - 4) == pos) // XXX: should we check for duplicates? + if (ic > 0 && get_le32(pos_ptr - 4) == pos) if (!opt->force) throwCantPack("duplicate relocs (try --force)"); if (ic == 0 || (pos ^ prev) >= 0x10000) {