From 038743c69447480f54849308041fa467a2a219e8 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Thu, 2 May 2024 03:21:27 +0200 Subject: [PATCH] CI updates --- .github/workflows/ci.yml | 7 +-- misc/cmake/self_pack_test.cmake | 2 +- misc/scripts/readlink-en.py | 17 +++++++ misc/scripts/readlink-fn.py | 3 +- misc/testsuite/test_symlinks.sh | 80 +++++++++++++++++++++------------ src/bele.h | 12 +++-- src/util/xspan.h | 2 +- 7 files changed, 84 insertions(+), 39 deletions(-) create mode 100755 misc/scripts/readlink-en.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a652b2cc..b6410d08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -204,10 +204,10 @@ jobs: # only run "brew update" if needed if ! brew install coreutils; then brew update && brew install coreutils; fi fi + echo "UPX_DEBUG_FORCE_PACK_MACOS=1" >> $GITHUB_ENV 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 ;; + # FIXME: UPX on macos-13+ is broken => disable run-packed for now + macos-13 | macos-14) echo "UPX_CONFIG_DISABLE_RUN_PACKED_TEST=ON" >> $GITHUB_ENV ;; esac - name: 'Check out code' uses: actions/checkout@v4 @@ -265,6 +265,7 @@ jobs: if: ${{ matrix.testsuite }} # for coreutils readlink run: | export PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH" + export upx_test_file="$PWD"/build/extra/clang/release/upx env -C build/extra/clang/release bash "$PWD"/misc/testsuite/test_symlinks.sh - name: 'Run test suite build/extra/clang/release' if: ${{ matrix.testsuite }} diff --git a/misc/cmake/self_pack_test.cmake b/misc/cmake/self_pack_test.cmake index 8c3e03f2..63f6efce 100644 --- a/misc/cmake/self_pack_test.cmake +++ b/misc/cmake/self_pack_test.cmake @@ -44,7 +44,7 @@ upx_add_test(upx-unpack-nrv2d upx -d upx-packed-nrv2d${exe} ${fo} -o upx-u upx_add_test(upx-unpack-nrv2e upx -d upx-packed-nrv2e${exe} ${fo} -o upx-unpacked-nrv2e${exe}) upx_add_test(upx-unpack-lzma upx -d upx-packed-lzma${exe} ${fo} -o upx-unpacked-lzma${exe}) -# all unpacked files must be identical! +# all unpacked files must be identical upx_add_test(upx-compare-fa "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-fa${exe}) upx_add_test(upx-compare-fn "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-fn${exe}) upx_add_test(upx-compare-fr "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-fr${exe}) diff --git a/misc/scripts/readlink-en.py b/misc/scripts/readlink-en.py new file mode 100755 index 00000000..52eb5739 --- /dev/null +++ b/misc/scripts/readlink-en.py @@ -0,0 +1,17 @@ +#! /usr/bin/env python3 +## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*- + +# simulate "readlink -en FILE" +# - result may differ from actual readlink(1) for edge cases +# - works with Python2 and Python3 +# +# Copyright (C) Markus Franz Xaver Johannes Oberhumer + +import os, sys +if len(sys.argv) != 2: + sys.exit(1) +real_path = os.path.realpath(sys.argv[1]) +if not os.path.exists(real_path): + sys.exit(1) +sys.stdout.write(real_path) +sys.stdout.flush() diff --git a/misc/scripts/readlink-fn.py b/misc/scripts/readlink-fn.py index 39603498..1de0a68d 100755 --- a/misc/scripts/readlink-fn.py +++ b/misc/scripts/readlink-fn.py @@ -10,5 +10,6 @@ import os, sys if len(sys.argv) != 2: sys.exit(1) -sys.stdout.write(os.path.realpath(sys.argv[1])) +real_path = os.path.realpath(sys.argv[1]) +sys.stdout.write(real_path) sys.stdout.flush() diff --git a/misc/testsuite/test_symlinks.sh b/misc/testsuite/test_symlinks.sh index 9063a14e..5147c46f 100755 --- a/misc/testsuite/test_symlinks.sh +++ b/misc/testsuite/test_symlinks.sh @@ -10,10 +10,11 @@ argv0=$0; argv0abs=$(readlink -fn "$argv0"); argv0dir=$(dirname "$argv0abs") # $upx_exe (required, but with convenience fallback "./upx") # optional settings: # $upx_exe_runner (e.g. "qemu-x86_64 -cpu Nehalem" or "valgrind") +# $upx_test_file # -# IMPORTANT NOTE: do NOT run as user root!! -# IMPORTANT NOTE: this script only works on Unix!! +# IMPORTANT NOTE: this script only works on Unix +# IMPORTANT NOTE: do NOT run as user root! umask 0022 # disable on macOS for now, see https://github.com/upx/upx/issues/612 @@ -61,7 +62,7 @@ if ! "${run_upx[@]}" -L >/dev/null 2>&1; then echo "UPX-ERROR: FATAL: upx -L FAI if ! "${run_upx[@]}" --help >/dev/null; then echo "UPX-ERROR: FATAL: upx --help FAILED"; exit 1; fi #*********************************************************************** -# util +# util functions #*********************************************************************** exit_code=0 @@ -162,17 +163,7 @@ create_files() { chmod -R a-w z_dir_4 } -#*********************************************************************** -# -#*********************************************************************** - -#set -x # debug - -export UPX="--prefer-ucl --no-color --no-progress" -export UPX_DEBUG_DISABLE_GITREV_WARNING=1 -export UPX_DEBUG_DOCTEST_DISABLE=1 # already checked above - -testsuite_header() { +print_header() { local x='==========='; x="$x$x$x$x$x$x$x" echo -e "\n${x}\n${1}\n${x}\n" } @@ -187,19 +178,40 @@ leave_dir() { cd .. } -# create a tmpdir in current directory +#*********************************************************************** +# setup +#*********************************************************************** + +#set -x # debug + +export UPX="--prefer-ucl --no-color --no-progress" +export UPX_DEBUG_DISABLE_GITREV_WARNING=1 +export UPX_DEBUG_DOCTEST_DISABLE=1 # already checked above + +# get $test_file +if [[ -f $upx_test_file ]]; then + test_file="$(readlink -fn "$upx_test_file")" +else + for test_file in /usr/bin/gmake /usr/bin/make /usr/bin/env /bin/ls; do + if [[ -f $test_file ]]; then + test_file="$(readlink -fn "$test_file")" + break + fi + done +fi +ls -l "$test_file" +file "$test_file" || true + +# create and enter a tmpdir in the current directory tmpdir="$(mktemp -d tmp-upx-test-XXXXXX)" cd "./$tmpdir" || exit 1 -for test_file in /usr/bin/make /usr/bin/gmake /usr/bin/env /bin/ls; do - if [[ -f $test_file ]]; then - test_file="$(readlink -fn "$test_file")" - break - fi -done +#*********************************************************************** +# default +#*********************************************************************** -testsuite_header "default" -flags="-qq -1 --no-filter" +print_header "default" +flags="-qq -2 --no-filter" mkdir default cd default create_files @@ -261,8 +273,12 @@ assert_symlink_dangling z_symlink_dangling leave_dir cd .. -testsuite_header "force-overwrite" -flags="-qq -1 --no-filter --force-overwrite" +#*********************************************************************** +# force-overwrite +#*********************************************************************** + +print_header "force-overwrite" +flags="-qq -2 --no-filter --force-overwrite" mkdir force-overwrite cd force-overwrite create_files @@ -324,9 +340,12 @@ assert_symlink_dangling z_symlink_dangling leave_dir cd .. -if [[ 1 == 1 ]]; then -testsuite_header "link" -flags="-qq -1 --no-filter --link" +#*********************************************************************** +# link +#*********************************************************************** + +print_header "link" +flags="-qq -2 --no-filter --link" mkdir link cd link create_files @@ -387,7 +406,10 @@ assert_symlink_to_dir z_symlink_dir assert_symlink_dangling z_symlink_dangling leave_dir cd .. -fi + +#*********************************************************************** +# done +#*********************************************************************** # clean up cd .. diff --git a/src/bele.h b/src/bele.h index 23f3299b..8cdb20b2 100644 --- a/src/bele.h +++ b/src/bele.h @@ -69,6 +69,8 @@ struct LE16; struct LE32; struct LE64; +namespace bele_detail { + // Note: // void is explicitly allowed (but there is no automatic pointer conversion because of template!) // char is explicitly allowed @@ -94,10 +96,12 @@ using enable_if_xe32 = std::enable_if_t, T>; template using enable_if_xe64 = std::enable_if_t, T>; -#define REQUIRE_XE16 template > -#define REQUIRE_XE24 template > -#define REQUIRE_XE32 template > -#define REQUIRE_XE64 template > +} // namespace bele_detail + +#define REQUIRE_XE16 template > +#define REQUIRE_XE24 template > +#define REQUIRE_XE32 template > +#define REQUIRE_XE64 template > #endif // permissive version diff --git a/src/util/xspan.h b/src/util/xspan.h index f7bd2413..1d7b1779 100644 --- a/src/util/xspan.h +++ b/src/util/xspan.h @@ -161,7 +161,7 @@ inline R *xspan_make_helper__(MemBuffer &mb) noexcept { // cast to a different type (creates a new value) #define XSPAN_TYPE_CAST(type, x) (upx::ptr_static_cast(x)) // poison a pointer: point to a non-null invalid address -#define XSPAN_INVALIDATE(x) ptr_invalidate_and_poison(x) +#define XSPAN_INVALIDATE(x) (ptr_invalidate_and_poison(x)) #endif // WITH_XSPAN