From a21a006fe9e1c0fd84d345b1d3571b3f3283648b Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Tue, 19 Mar 2024 16:03:37 +0100 Subject: [PATCH] all: yet more minor cleanups --- .clang-format | 1 - .clang-tidy | 1 - .clangd | 1 - .editorconfig | 1 + .gitattributes | 1 + .github/workflows/ci.yml | 6 ++--- misc/scripts/run_cmake_config.sh | 40 ++++++++++++++++++++++++++++++++ misc/testsuite/test_symlinks.sh | 5 ++-- src/conf.h | 7 +++--- src/util/system_headers.h | 11 ++------- 10 files changed, 54 insertions(+), 20 deletions(-) create mode 100755 misc/scripts/run_cmake_config.sh diff --git a/.clang-format b/.clang-format index 5c712459..e0ca9108 100644 --- a/.clang-format +++ b/.clang-format @@ -3,7 +3,6 @@ # for clang-format-15.0.6 from https://github.com/upx/upx-stubtools/releases # # "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite." --Rob Pike - --- BasedOnStyle: LLVM ColumnLimit: 100 diff --git a/.clang-tidy b/.clang-tidy index e4202aa2..84d6398b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,7 +1,6 @@ # vim:set ft=yaml ts=2 sw=2 et: # Copyright (C) Markus Franz Xaver Johannes Oberhumer # for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/ - --- Checks: > -*, diff --git a/.clangd b/.clangd index 5e969f48..c96b58dd 100644 --- a/.clangd +++ b/.clangd @@ -1,7 +1,6 @@ # vim:set ft=yaml ts=2 sw=2 et: # Copyright (C) Markus Franz Xaver Johannes Oberhumer # for clangd-17 from https://clangd.llvm.org/ - --- # treat *.h files as C++ source code If: diff --git a/.editorconfig b/.editorconfig index 0f52a6a3..3786de05 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,3 +1,4 @@ +# Copyright (C) Markus Franz Xaver Johannes Oberhumer # see https://editorconfig.org/ root = true diff --git a/.gitattributes b/.gitattributes index bf70f378..9b127bc2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ +# Copyright (C) Markus Franz Xaver Johannes Oberhumer # see https://github.com/github-linguist/linguist # # HINT: check settings with diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad3e2ba1..c2892330 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -218,9 +218,9 @@ jobs: if ! brew install coreutils; then brew update && brew install coreutils; fi fi case "${{ matrix.os }}" in - macos-11 | macos-12) echo "UPX_DEBUG_FORCE_PACK_MACOS=1" >> $GITHUB_ENV ;; - # FIXME: UPX on macos-13+ is broken => disable self-test for now - macos-13 | macos-14) echo "UPX_CONFIG_DISABLE_SELF_PACK_TEST=ON" >> $GITHUB_ENV ;; + macos-11 | macos-12) echo "UPX_DEBUG_FORCE_PACK_MACOS=1" >> $GITHUB_ENV ;; + # FIXME: UPX on macos-13+ is broken => disable self-test for now + macos-13 | macos-14) echo "UPX_CONFIG_DISABLE_SELF_PACK_TEST=ON" >> $GITHUB_ENV ;; esac - name: 'Check out code' uses: actions/checkout@v4 diff --git a/misc/scripts/run_cmake_config.sh b/misc/scripts/run_cmake_config.sh new file mode 100755 index 00000000..3e8fa027 --- /dev/null +++ b/misc/scripts/run_cmake_config.sh @@ -0,0 +1,40 @@ +#! /usr/bin/env bash +## vim:set ts=4 sw=4 et: +set -e; set -o pipefail + +# Copyright (C) Markus Franz Xaver Johannes Oberhumer +# assemble cmake config flags; useful for CI jobs + +cmake_config_flags=() + +add_flag() { + [[ -z "${!1}" ]] || cmake_config_flags+=( -D$1="${!1}" ) +} + +# pass common CMake settings from environment to cmake +for v in CMAKE_VERBOSE_MAKEFILE; do + add_flag $v +done +# pass common CMake toolchain settings from environment to cmake +for v in CMAKE_ADDR2LINE CMAKE_AR CMAKE_DLLTOOL CMAKE_LINKER CMAKE_NM CMAKE_OBJCOPY CMAKE_OBJDUMP CMAKE_RANLIB CMAKE_READELF CMAKE_STRIP CMAKE_TAPI; do + add_flag $v +done +# pass common CMake LTO toolchain settings from environment to cmake (for use with "-flto") +for v in CMAKE_C_COMPILER_AR CMAKE_C_COMPILER_RANLIB CMAKE_CXX_COMPILER_AR CMAKE_CXX_COMPILER_RANLIB; do + add_flag $v +done +# pass common CMake cross compilation settings from environment to cmake +for v in CMAKE_SYSTEM_NAME CMAKE_SYSTEM_PROCESSOR CMAKE_CROSSCOMPILING_EMULATOR; do + add_flag $v +done +# pass UPX config options from environment to cmake; see CMakeLists.txt +for v in UPX_CONFIG_DISABLE_GITREV UPX_CONFIG_DISABLE_SANITIZE UPX_CONFIG_DISABLE_WSTRICT UPX_CONFIG_DISABLE_WERROR UPX_CONFIG_DISABLE_SELF_PACK_TEST; do + add_flag $v +done +# pass UPX extra compile options from environment to cmake; see CMakeLists.txt +for v in UPX_CONFIG_EXTRA_COMPILE_OPTIONS_BZIP2 UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UCL UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UPX UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZLIB UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZSTD; do + add_flag $v +done + +exec "${CMAKE:-cmake}" $UPX_CMAKE_CONFIG_FLAGS "${cmake_config_flags[@]}" "$@" +exit 99 diff --git a/misc/testsuite/test_symlinks.sh b/misc/testsuite/test_symlinks.sh index 617ad95e..a6f9f79f 100755 --- a/misc/testsuite/test_symlinks.sh +++ b/misc/testsuite/test_symlinks.sh @@ -18,8 +18,9 @@ umask 0022 # disable on macOS for now, see https://github.com/upx/upx/issues/612 if [[ "$(uname)" == Darwin ]]; then - echo "$0: SKIPPED" - exit 0 + case "$UPX_DEBUG_FORCE_PACK_MACOS" in + "" | "0") echo "$0: SKIPPED"; exit 0 ;; + esac fi id || true diff --git a/src/conf.h b/src/conf.h index 2d444aff..a12fceb8 100644 --- a/src/conf.h +++ b/src/conf.h @@ -145,13 +145,13 @@ typedef acc_int64_t upx_int64_t; typedef acc_uint64_t upx_uint64_t; typedef acc_uintptr_t upx_uintptr_t; -// convention: use "byte" when dealing with data; use "char/uchar" when dealing +// UPX convention: use "byte" when dealing with data; use "char/uchar" when dealing // with strings; use "upx_uint8_t" when dealing with small integers typedef unsigned char byte; #define upx_byte byte #define upx_bytep byte * typedef unsigned char uchar; -// convention: use "charptr" when dealing with abstract pointer arithmetics +// UPX convention: use "charptr" when dealing with abstract pointer arithmetics #define charptr upx_charptr_unit_type * // upx_charptr_unit_type is some opaque type with sizeof(type) == 1 struct alignas(1) upx_charptr_unit_type final { char hidden__; }; @@ -192,7 +192,7 @@ typedef upx_int64_t upx_off_t; #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 +// note: noexcept(false) is the default for all C++ functions anyway #define may_throw noexcept(false) #define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e) @@ -230,6 +230,7 @@ typedef upx_int64_t upx_off_t; #endif #if defined(HAVE_DUP) && (HAVE_DUP + 0 == 0) +// TODO later: add upx_fd_dup() util #undef dup #define dup(x) (-1) #endif diff --git a/src/util/system_headers.h b/src/util/system_headers.h index d6c60e6b..c3d0c2cf 100644 --- a/src/util/system_headers.h +++ b/src/util/system_headers.h @@ -62,12 +62,12 @@ #endif // sanity checks -#if defined(__ILP32) || defined(__ILP32__) +#if defined(_ILP32) || defined(__ILP32) || defined(__ILP32__) static_assert(sizeof(int) == 4); static_assert(sizeof(long) == 4); static_assert(sizeof(void *) == 4); #endif -#if defined(__LP64) || defined(__LP64__) +#if defined(_LP64) || defined(__LP64) || defined(__LP64__) static_assert(sizeof(int) == 4); static_assert(sizeof(long) == 8); static_assert(sizeof(void *) == 8); @@ -153,13 +153,6 @@ static_assert(sizeof(void *) == sizeof(long)); // UPX vendor git submodule headers #include -#if WITH_BOOST_PFR -#include -#include -#endif -#if WITH_RANGELESS_FN -#include -#endif #ifndef WITH_VALGRIND #define WITH_VALGRIND 1 #endif