From 3538d796a758dc18e2e1c08b7cd13225e650f1aa Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Tue, 2 Apr 2024 08:05:43 +0200 Subject: [PATCH] CI updates --- .github/workflows/ci.yml | 32 +++++++++++++++--------------- misc/cmake/functions.cmake | 6 +++++- src/check/dt_check.cpp | 40 +++++++++++++++++++++++++++++--------- src/util/xspan.h | 2 +- 4 files changed, 53 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6965c9f8..6daba372 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -293,8 +293,8 @@ jobs: fail-fast: false matrix: include: - - { name: windows-2019-amd64, os: windows-2019, vsversion: 2019, arch: amd64 } - - { name: windows-2022-amd64, os: windows-2022, vsversion: 2022, arch: amd64 } + - { name: windows-2019-amd64, os: windows-2019, vsversion: 2019, vsarch: amd64 } + - { name: windows-2022-amd64, os: windows-2022, vsversion: 2022, vsarch: amd64 } steps: - run: git config --global core.autocrlf false - name: 'Check out code' @@ -306,7 +306,7 @@ jobs: uses: ilammy/msvc-dev-cmd@v1 with: vsversion: ${{ matrix.vsversion }} - arch: ${{ matrix.arch }} + arch: ${{ matrix.vsarch }} - name: 'Build debug' run: 'make build/debug' - name: 'Build release' @@ -325,12 +325,12 @@ jobs: name: ${{ env.artifact_name }} path: tmp/artifact - name: 'Run ctest tests' - if: ${{ matrix.arch != 'amd64_arm64' }} + if: ${{ matrix.vsarch != 'amd64_arm64' }} run: | ctest --test-dir build/debug -C Debug ctest --test-dir build/release -C Release - name: 'Run test suite build/release' - if: ${{ matrix.arch != 'amd64_arm64' }} + if: ${{ matrix.vsarch != 'amd64_arm64' }} shell: bash run: | export upx_testsuite_SRCDIR="$(readlink -en ../deps/upx-testsuite)" @@ -348,14 +348,14 @@ jobs: fail-fast: false matrix: include: - - { name: amd64-win64-vs2019, os: windows-2019, vsversion: 2019, arch: amd64 } - - { name: amd64-win64-vs2022, os: windows-2022, vsversion: 2022, arch: amd64 } - - { name: arm64-win64-vs2019, os: windows-2019, vsversion: 2019, arch: amd64_arm64 } - - { name: arm64-win64-vs2022, os: windows-2022, vsversion: 2022, arch: amd64_arm64 } - - { name: arm64ec-win64-vs2022, os: windows-2022, vsversion: 2022, arch: amd64_arm64, cl_machine_flags: -arm64EC, link_machine_flags: '/machine:arm64ec' } - # { name: arm64x-win64-vs2022, os: windows-2022, vsversion: 2022, arch: amd64_arm64, cl_machine_flags: -arm64EC, link_machine_flags: '/machine:arm64x' } - - { name: i386-win32-vs2019, os: windows-2019, vsversion: 2019, arch: amd64_x86 } - - { name: i386-win32-vs2022, os: windows-2022, vsversion: 2022, arch: amd64_x86 } + - { name: amd64-win64-vs2019, os: windows-2019, vsversion: 2019, vsarch: amd64 } + - { name: amd64-win64-vs2022, os: windows-2022, vsversion: 2022, vsarch: amd64 } + - { name: arm64-win64-vs2019, os: windows-2019, vsversion: 2019, vsarch: amd64_arm64 } + - { name: arm64-win64-vs2022, os: windows-2022, vsversion: 2022, vsarch: amd64_arm64 } + - { name: arm64ec-win64-vs2022, os: windows-2022, vsversion: 2022, vsarch: amd64_arm64, cl_machine_flags: -arm64EC, link_machine_flags: '/machine:arm64ec' } + # { name: arm64x-win64-vs2022, os: windows-2022, vsversion: 2022, vsarch: amd64_arm64, cl_machine_flags: -arm64EC, link_machine_flags: '/machine:arm64x' } + - { name: i386-win32-vs2019, os: windows-2019, vsversion: 2019, vsarch: amd64_x86 } + - { name: i386-win32-vs2022, os: windows-2022, vsversion: 2022, vsarch: amd64_x86 } steps: - run: git config --global core.autocrlf false - name: 'Check out code' @@ -372,7 +372,7 @@ jobs: uses: ilammy/msvc-dev-cmd@v1 with: vsversion: ${{ matrix.vsversion }} - arch: ${{ matrix.arch }} + arch: ${{ matrix.vsarch }} - name: 'Build by hand' shell: cmd run: | @@ -426,7 +426,7 @@ jobs: name: ${{ env.artifact_name }} path: tmp/artifact - name: 'Run basic tests' - if: ${{ matrix.arch != 'amd64_arm64' }} + if: ${{ matrix.vsarch != 'amd64_arm64' }} run: | $ErrorActionPreference = 'stop' $ErrorView = 'NormalView' @@ -440,7 +440,7 @@ jobs: .\upx.exe -t upx_packed.exe .\upx_packed.exe --version - name: 'Run test suite' - if: ${{ matrix.arch != 'amd64_arm64' }} + if: ${{ matrix.vsarch != 'amd64_arm64' }} shell: bash run: | export upx_testsuite_SRCDIR="$(readlink -en ../deps/upx-testsuite)" diff --git a/misc/cmake/functions.cmake b/misc/cmake/functions.cmake index dc5d05ea..6e18c1f2 100644 --- a/misc/cmake/functions.cmake +++ b/misc/cmake/functions.cmake @@ -110,7 +110,11 @@ endfunction() function(upx_add_glob_files) # ARGV set(var_name ${ARGV0}) list(REMOVE_AT ARGV 0) - file(GLOB files ${ARGV}) + if(${CMAKE_VERSION} VERSION_LESS "3.3") + file(GLOB files ${ARGV}) + else() + file(GLOB files LIST_DIRECTORIES false ${ARGV}) + endif() set(result "") if(DEFINED ${var_name}) set(result "${${var_name}}") diff --git a/src/check/dt_check.cpp b/src/check/dt_check.cpp index bc001a66..a55c57d2 100644 --- a/src/check/dt_check.cpp +++ b/src/check/dt_check.cpp @@ -370,6 +370,36 @@ static noinline double u64_f64_sub_div(upx_uint64_t a, upx_uint64_t b) { return (a - b) / 1000000.0; } +// extra debugging; floating point edge cases cause portability problems in practice +static noinline bool shall_test_float_division_by_zero(void) { + static bool result = false; // default is false + static upx_std_once_flag init_done; + upx_std_call_once(init_done, []() noexcept { + const char envvar[] = "UPX_DEBUG_TEST_FLOAT_DIVISION_BY_ZERO"; + const char *e = getenv(envvar); + bool force = (e && e[0] && strcmp(e, "2") == 0); + if (force) + result = true; + else if (is_envvar_true(envvar)) { +#if defined(__clang__) && defined(__FAST_MATH__) && defined(__INTEL_LLVM_COMPILER) + // warning: comparison with NaN always evaluates to false in fast floating point modes + fprintf(stderr, "upx: WARNING: ignoring %s: __FAST_MATH__\n", envvar); +#elif defined(__clang__) && (__clang_major__ < 9) && defined(__SANITIZE_UNDEFINED_BEHAVIOR__) + // UBSAN problem with clang < 9 + // @COMPILER_BUG @CLANG_BUG @UBSAN_BUG + fprintf(stderr, "upx: WARNING: ignoring %s: UBSAN\n", envvar); +#elif defined(__clang__) && (__clang_major__ < 8) + // NOTE: cannot reliably detect __SANITIZE_UNDEFINED_BEHAVIOR__ on older clang versions + // @COMPILER_BUG @CLANG_BUG @UBSAN_BUG + fprintf(stderr, "upx: WARNING: ignoring %s: clang %d\n", envvar, __clang_major__); +#else + result = true; +#endif + } + }); + return result; +} + template struct TestFloat { static constexpr Int X = 1000000; @@ -385,18 +415,10 @@ struct TestFloat { assert_noexcept(sub_div(3 * X, X, Float(X)) == Float(2)); assert_noexcept(sub_div_x(3 * X, X) == Float(2)); // extra debugging; floating point edge cases cause portability problems in practice - if (is_envvar_true("UPX_DEBUG_TEST_FLOAT_DIVISION_BY_ZERO")) { -#if defined(__clang__) && defined(__FAST_MATH__) && defined(__INTEL_LLVM_COMPILER) - // warning: comparison with NaN always evaluates to false in fast floating point modes - fprintf(stderr, "upx: WARNING: ignoring UPX_DEBUG_TEST_FLOAT_DIVISION_BY_ZERO\n"); -#elif defined(__clang__) && (__clang_major__ < 9) && defined(__SANITIZE_UNDEFINED_BEHAVIOR__) - // @COMPILER_BUG @CLANG_BUG - fprintf(stderr, "upx: WARNING: ignoring UPX_DEBUG_TEST_FLOAT_DIVISION_BY_ZERO\n"); -#else + if (shall_test_float_division_by_zero()) { assert_noexcept(std::isnan(div(0, Float(0)))); assert_noexcept(std::isinf(div(1, Float(0)))); assert_noexcept(std::isinf(div(Int(-1), Float(0)))); -#endif } } }; diff --git a/src/util/xspan.h b/src/util/xspan.h index a5947d08..f7bd2413 100644 --- a/src/util/xspan.h +++ b/src/util/xspan.h @@ -38,7 +38,7 @@ // Automatic conversion to underlying pointer; do NOT enable this config as this // defeats the main purpose of a checked pointer => use raw_bytes() as needed; -// and see xspan_fwd.h how to make this more convenient. +// and see "xspan_fwd.h" how to make this more convenient. #ifndef XSPAN_CONFIG_ENABLE_IMPLICIT_CONVERSION #define XSPAN_CONFIG_ENABLE_IMPLICIT_CONVERSION 0 #endif