diff --git a/.gitattributes b/.gitattributes index 097986bb..bf70f378 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14,6 +14,9 @@ /src/stub/src/arch/**/lzma_d_c[fns].S linguist-generated /src/stub/tmp/** linguist-generated +/misc/podman/*/packages*.txt linguist-generated +/misc/testsuite/*expected_sha256sums* linguist-generated + # # make GitHub language detection more accurate # diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52a7641e..4be09ffe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,13 +92,13 @@ jobs: if: ${{ matrix.use_m32 }} run: 'make build/extra/gcc-m32/debug' - name: 'Build cmake extra/gcc-m32/release' - if: ${{ matrix.use_m32 }} + if: ${{ matrix.use_m32 && (success() || failure()) }} # run this step even if the previous step failed run: 'make build/extra/gcc-m32/release' - name: 'Build cmake extra/cross-windows-mingw32/release' - if: ${{ matrix.use_m32 }} + if: ${{ matrix.use_m32 && (success() || failure()) }} # run this step even if the previous step failed run: 'make build/extra/cross-windows-mingw32/release' - name: 'Build cmake extra/cross-windows-mingw64/release' - if: ${{ matrix.use_m32 }} + if: ${{ matrix.use_m32 && (success() || failure()) }} # run this step even if the previous step failed run: 'make build/extra/cross-windows-mingw64/release' - name: 'Make artifact' run: | @@ -206,7 +206,8 @@ jobs: if: ${{ !contains(matrix.os, 'macos-13') }} # FIXME: UPX on macos-13 is broken => disable self-test for now run: | make -C build/extra/clang/debug test -# make -C build/extra/clang/release test + #make -C build/extra/clang/release test + for f in ./build/extra/*/*/upx; do echo "===== $f"; $f --sysinfo -v; done - name: 'Run file system test suite' if: ${{ matrix.testsuite }} # for coreutils readlink run: | @@ -235,6 +236,7 @@ jobs: - { name: windows-2019-amd64, os: windows-2019, vsversion: 2019, arch: amd64 } - { name: windows-2022-amd64, os: windows-2022, vsversion: 2022, arch: amd64 } steps: + - run: git config --global core.autocrlf false - name: 'Check out code' uses: actions/checkout@v4 with: { submodules: true } @@ -283,7 +285,6 @@ jobs: env: C: ${{ matrix.name }} B: release - H: 'd:\a\upx\upx' strategy: fail-fast: false matrix: @@ -297,6 +298,7 @@ jobs: - { name: i386-win32-vs2019, os: windows-2019, vsversion: 2019, arch: amd64_x86 } - { name: i386-win32-vs2022, os: windows-2022, vsversion: 2022, arch: amd64_x86 } steps: + - run: git config --global core.autocrlf false - name: 'Check out code' uses: actions/checkout@v4 with: { submodules: true } @@ -305,6 +307,8 @@ jobs: run: | git clone --depth=1 https://github.com/upx/upx-testsuite ../deps/upx-testsuite mkdir -p -v build/$C/$B/{bzip2,ucl,upx,zlib,zstd} + repo_name="${GITHUB_REPOSITORY##*/}" # basename + echo "H=d:\\a\\$repo_name\\$repo_name" >> $GITHUB_ENV - name: 'Set up Developer Command Prompt' uses: ilammy/msvc-dev-cmd@cec98b9d092141f74527d0afa6feb2af698cfe89 # v1.12.1 with: @@ -370,6 +374,7 @@ jobs: cd $Env:H\build\$Env:C\$Env:B\upx $Env:UPX = "--no-color --no-progress" .\upx.exe --version + .\upx.exe --sysinfo -v .\upx.exe upx.exe -o upx_packed.exe dir *.exe .\upx.exe -l upx_packed.exe diff --git a/.github/workflows/test-alpine-linux.yml b/.github/workflows/test-alpine-linux.yml index f88a5692..7a19f0f5 100644 --- a/.github/workflows/test-alpine-linux.yml +++ b/.github/workflows/test-alpine-linux.yml @@ -21,7 +21,7 @@ jobs: - name: ${{ format('Build clang {0}', matrix.container) }} run: | apk update && apk upgrade && apk add clang cmake make - wget https://github.com/upx/upx/releases/download/v4.2.0/upx-4.2.0-src.tar.xz + wget https://github.com/upx/upx/releases/download/v4.2.1/upx-4.2.1-src.tar.xz tar -xoaf upx-*-src.tar.xz cd upx-*-src make build/debug CC="clang -static" CXX="clang++ -static" @@ -48,7 +48,7 @@ jobs: - name: ${{ format('Build gcc {0}', matrix.container) }} run: | apk update && apk upgrade && apk add cmake g++ make - wget https://github.com/upx/upx/releases/download/v4.2.0/upx-4.2.0-src.tar.xz + wget https://github.com/upx/upx/releases/download/v4.2.1/upx-4.2.1-src.tar.xz tar -xoaf upx-*-src.tar.xz cd upx-*-src make build/debug CC="gcc -static" CXX="g++ -static" diff --git a/.github/workflows/test-cmake-default.yml b/.github/workflows/test-cmake-default.yml index 64fada6a..9bac0a3c 100644 --- a/.github/workflows/test-cmake-default.yml +++ b/.github/workflows/test-cmake-default.yml @@ -51,6 +51,7 @@ jobs: cmake-nmake: runs-on: windows-2022 steps: + - run: git config --global core.autocrlf false - name: 'Check out code' uses: actions/checkout@v4 with: { submodules: true } @@ -100,6 +101,7 @@ jobs: cmake-vsstudio-multi-config: runs-on: windows-2022 steps: + - run: git config --global core.autocrlf false - name: 'Check out code' uses: actions/checkout@v4 with: { submodules: true } diff --git a/.github/workflows/weekly-ci-bs-by-hand.yml b/.github/workflows/weekly-ci-bs-by-hand.yml index 7921b869..854fd368 100644 --- a/.github/workflows/weekly-ci-bs-by-hand.yml +++ b/.github/workflows/weekly-ci-bs-by-hand.yml @@ -141,7 +141,7 @@ jobs: cd "upx with space"/build/by-hand bash "$testsuite" - job-by-hand-windows-gcc: # uses a POSIX-compliant shell + job-by-hand-windows: # uses a POSIX-compliant shell # ...and also uses a subdirectory "upx with space" in order to detect possible quoting issues if: github.repository_owner == 'upx' strategy: @@ -150,16 +150,29 @@ jobs: include: - { os: windows-2019 } - { os: windows-2022 } - name: ${{ format('by-hand gcc {0}', matrix.os) }} + name: ${{ format('by-hand cc {0}', matrix.os) }} runs-on: ${{ matrix.os }} steps: + - run: git config --global core.autocrlf false - name: ${{ format('Check out UPX {0} source code', github.ref_name) }} shell: bash run: | git clone --branch "$GITHUB_REF_NAME" --depth 1 "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" "upx with space" git -C "upx with space" submodule update --init - - name: 'Build by-hand with bash' + - name: 'Build by-hand with bash - clang' shell: bash run: | xflags="-static -Wall -Wextra -Werror" + # clang uses the MSVC headers, adjust settings + xflags="$xflags -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS" + export zlib_extra_flags="-DHAVE_VSNPRINTF" + export AR=false # link without using $AR + CC="clang $xflags" CXX="clang++ -std=gnu++17 $xflags" bash "./upx with space/misc/scripts/build_upx_by_hand.sh" + ls -l build/by-hand || true + - name: 'Build by-hand with bash - gcc' + if: success() || failure() # run this step even if the previous step failed + shell: bash + run: | + xflags="-static -Wall -Wextra -Werror" + # gcc uses the MingGW headers, so no extra settings are needed CC="gcc $xflags" CXX="g++ -std=gnu++17 $xflags" bash "./upx with space/misc/scripts/build_upx_by_hand.sh" diff --git a/.github/workflows/weekly-ci-bs-cmake-macos-xcode.yml b/.github/workflows/weekly-ci-bs-cmake-macos-xcode.yml index e2f68c4f..53e9d1ed 100644 --- a/.github/workflows/weekly-ci-bs-cmake-macos-xcode.yml +++ b/.github/workflows/weekly-ci-bs-cmake-macos-xcode.yml @@ -47,7 +47,9 @@ jobs: if: ${{ matrix.run_test }} run: | ctest --test-dir build/xcode -C Debug -# ctest --test-dir build/xcode -C Release + #ctest --test-dir build/xcode -C Release + ./build/xcode/Debug/upx --sysinfo -v + ./build/xcode/Release/upx --sysinfo -v - name: 'Run install tests' run: | (cd build/xcode && DESTDIR=$PWD/Install-default cmake --install .) diff --git a/.github/workflows/weekly-ci-bs-cmake-windows-make.yml b/.github/workflows/weekly-ci-bs-cmake-windows-make.yml index 0cd31e1a..a58a8247 100644 --- a/.github/workflows/weekly-ci-bs-cmake-windows-make.yml +++ b/.github/workflows/weekly-ci-bs-cmake-windows-make.yml @@ -43,6 +43,7 @@ jobs: name: ${{ format('{0} {1} {2}', matrix.cc, matrix.vsversion, matrix.arch) }} runs-on: ${{ matrix.os }} steps: + - run: git config --global core.autocrlf false - name: 'Check out code' uses: actions/checkout@v4 with: { submodules: true } @@ -64,6 +65,7 @@ jobs: ls -l build/xtarget/$xtarget/debug/upx.exe file build/xtarget/$xtarget/debug/upx.exe || true - name: 'Build cmake Make Release' + if: success() || failure() # run this step even if the previous step failed shell: bash run: | make UPX_XTARGET=$xtarget xtarget/release @@ -88,6 +90,8 @@ jobs: run: | ctest --test-dir build/xtarget/$xtarget/debug ctest --test-dir build/xtarget/$xtarget/release + ./build/xtarget/$xtarget/debug/upx.exe --sysinfo -v + ./build/xtarget/$xtarget/release/upx.exe --sysinfo -v - name: 'Run install tests' shell: bash run: | diff --git a/.github/workflows/weekly-ci-bs-cmake-windows-ninja.yml b/.github/workflows/weekly-ci-bs-cmake-windows-ninja.yml index a04260a7..b58bb87a 100644 --- a/.github/workflows/weekly-ci-bs-cmake-windows-ninja.yml +++ b/.github/workflows/weekly-ci-bs-cmake-windows-ninja.yml @@ -41,6 +41,7 @@ jobs: name: ${{ format('{0} {1} {2}', matrix.cc, matrix.vsversion, matrix.arch) }} runs-on: ${{ matrix.os }} steps: + - run: git config --global core.autocrlf false - name: 'Check out code' uses: actions/checkout@v4 with: { submodules: true } @@ -63,6 +64,7 @@ jobs: ls -l build/xtarget/$xtarget/debug/upx.exe file build/xtarget/$xtarget/debug/upx.exe || true - name: 'Build cmake Ninja Release' + if: success() || failure() # run this step even if the previous step failed shell: bash run: | make UPX_XTARGET=$xtarget xtarget/release @@ -87,6 +89,8 @@ jobs: run: | ctest --test-dir build/xtarget/$xtarget/debug ctest --test-dir build/xtarget/$xtarget/release + ./build/xtarget/$xtarget/debug/upx.exe --sysinfo -v + ./build/xtarget/$xtarget/release/upx.exe --sysinfo -v - name: 'Run install tests' shell: bash run: | diff --git a/.github/workflows/weekly-ci-bs-cmake-windows-nmake.yml b/.github/workflows/weekly-ci-bs-cmake-windows-nmake.yml index 10a8b701..3acf60c0 100644 --- a/.github/workflows/weekly-ci-bs-cmake-windows-nmake.yml +++ b/.github/workflows/weekly-ci-bs-cmake-windows-nmake.yml @@ -18,6 +18,7 @@ jobs: matrix: include: # clang-cl + - { os: windows-2019, vsversion: 2019, arch: amd64, clang_cl: true } - { os: windows-2022, vsversion: 2022, arch: amd64, clang_cl: true } # msvc - { os: windows-2019, vsversion: 2019, arch: amd64 } @@ -29,6 +30,7 @@ jobs: name: ${{ format('vs{0} {1} {2}', matrix.vsversion, matrix.arch, matrix.clang_cl && 'clang-cl' || '') }} runs-on: ${{ matrix.os }} steps: + - run: git config --global core.autocrlf false - name: 'Check out code' uses: actions/checkout@v4 with: { submodules: true } @@ -46,6 +48,7 @@ jobs: nmake dir *.exe - name: 'Build cmake NMake Release' + if: success() || failure() # run this step even if the previous step failed shell: cmd run: | set X=${{ matrix.clang_cl && '-DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl' || '' }} @@ -72,6 +75,8 @@ jobs: run: | ctest --test-dir build/debug ctest --test-dir build/release + .\build\debug\upx.exe --sysinfo -v + .\build\release\upx.exe --sysinfo -v - name: 'Run install tests' run: | env DESTDIR=./Install-debug cmake --install build/debug diff --git a/.github/workflows/weekly-ci-cc-alpine-mingw.yml b/.github/workflows/weekly-ci-cc-alpine-mingw.yml index 81f27676..60267574 100644 --- a/.github/workflows/weekly-ci-cc-alpine-mingw.yml +++ b/.github/workflows/weekly-ci-cc-alpine-mingw.yml @@ -112,6 +112,7 @@ jobs: wine=wine64 tt='./upx.exe' $wine ./upx.exe --version-short + $wine ./upx.exe --sysinfo -v $wine ./upx.exe -3 $tt -o tt.packed.exe $wine ./upx.exe -l tt.packed.exe $wine ./upx.exe -t tt.packed.exe @@ -130,6 +131,7 @@ jobs: wine=wine64 tt='./upx.exe' $wine ./upx.exe --version-short + $wine ./upx.exe --sysinfo -v $wine ./upx.exe -3 $tt -o tt.packed.exe $wine ./upx.exe -l tt.packed.exe $wine ./upx.exe -t tt.packed.exe @@ -148,6 +150,7 @@ jobs: wine=wine64 tt='./upx.exe' $wine ./upx.exe --version-short + $wine ./upx.exe --sysinfo -v $wine ./upx.exe -3 $tt -o tt.packed.exe $wine ./upx.exe -l tt.packed.exe $wine ./upx.exe -t tt.packed.exe @@ -166,6 +169,7 @@ jobs: wine=wine64 tt='./upx.exe' $wine ./upx.exe --version-short + $wine ./upx.exe --sysinfo -v $wine ./upx.exe -3 $tt -o tt.packed.exe $wine ./upx.exe -l tt.packed.exe $wine ./upx.exe -t tt.packed.exe diff --git a/.github/workflows/weekly-ci-cc-llvm-mingw.yml b/.github/workflows/weekly-ci-cc-llvm-mingw.yml index 3c86a78e..b7be9393 100644 --- a/.github/workflows/weekly-ci-cc-llvm-mingw.yml +++ b/.github/workflows/weekly-ci-cc-llvm-mingw.yml @@ -26,12 +26,12 @@ jobs: - name: llvm-mingw-20230614-ucrt llvm_version: 16.0.6 url: 'https://github.com/mstorsjo/llvm-mingw/releases/download/20230614/llvm-mingw-20230614-ucrt-ubuntu-20.04-x86_64.tar.xz' - - name: llvm-mingw-20231017-msvcrt - llvm_version: 17.0.3 - url: 'https://github.com/mstorsjo/llvm-mingw/releases/download/20231017/llvm-mingw-20231017-msvcrt-ubuntu-20.04-x86_64.tar.xz' - - name: llvm-mingw-20231017-ucrt - llvm_version: 17.0.3 - url: 'https://github.com/mstorsjo/llvm-mingw/releases/download/20231017/llvm-mingw-20231017-ucrt-ubuntu-20.04-x86_64.tar.xz' + - name: llvm-mingw-20231031-msvcrt + llvm_version: 17.0.4 + url: 'https://github.com/mstorsjo/llvm-mingw/releases/download/20231031/llvm-mingw-20231031-msvcrt-ubuntu-20.04-x86_64.tar.xz' + - name: llvm-mingw-20231031-ucrt + llvm_version: 17.0.4 + url: 'https://github.com/mstorsjo/llvm-mingw/releases/download/20231031/llvm-mingw-20231031-ucrt-ubuntu-20.04-x86_64.tar.xz' name: ${{ format('{0} {1}', matrix.name, matrix.llvm_version) }} runs-on: ubuntu-latest steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index 64c199da..001980cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -429,7 +429,7 @@ upx_sanitize_target(${t}) if(MSVC_FRONTEND) target_compile_options(${t} PRIVATE ${warn_WN} -wd4127 -wd4244 -wd4267 ${warn_WX}) else() - target_compile_options(${t} PRIVATE ${warn_Wall} -Wno-implicit-fallthrough ${warn_Werror}) + target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror}) endif() endif() # UPX_CONFIG_DISABLE_BZIP2 @@ -453,8 +453,8 @@ endif() if(MSVC_FRONTEND) target_compile_options(${t} PRIVATE -W3 ${warn_WX}) else() - target_compile_options(${t} PRIVATE -Wall ${warn_Werror}) - ##target_compile_options(${t} PRIVATE ${warn_Wall} -Wno-cast-align -Wno-cast-qual ${warn_Werror}) + ##target_compile_options(${t} PRIVATE -Wall ${warn_Werror}) + target_compile_options(${t} PRIVATE ${warn_Wall} -Wno-cast-align -Wno-cast-qual ${warn_Werror}) endif() if(NOT UPX_CONFIG_DISABLE_ZSTD) @@ -524,6 +524,7 @@ include(CTest) if(NOT CMAKE_CROSSCOMPILING) add_test(NAME upx-version COMMAND upx --version) add_test(NAME upx-help COMMAND upx --help) + add_test(NAME upx-sysinfo COMMAND upx --sysinfo) endif() if(NOT CMAKE_CROSSCOMPILING AND NOT UPX_CONFIG_DISABLE_SELF_PACK_TEST) # IMPORTANT NOTE: these tests can only work if the host executable format is supported by UPX! diff --git a/misc/scripts/build_upx_by_hand.sh b/misc/scripts/build_upx_by_hand.sh index fc3d2aed..af4cb309 100755 --- a/misc/scripts/build_upx_by_hand.sh +++ b/misc/scripts/build_upx_by_hand.sh @@ -27,13 +27,13 @@ fi # protect against security threats caused by misguided compiler "optimizations" mandatory_flags="-fno-strict-aliasing -fno-strict-overflow -funsigned-char" # not mandatory but good practice when using : -mandatory_flags="$mandatory_flags -DWIN32_LEAN_AND_MEAN" +sensible_flags="-DWIN32_LEAN_AND_MEAN" if test "x$OPTIMIZE" != "x" && test "x$OPTIMIZE" != "x0"; then # not mandatory and not minimal, but usually a good idea: - mandatory_flags="-Wall -O2 $mandatory_flags" + sensible_flags="-Wall -O2 $sensible_flags" fi -CC="$CC $mandatory_flags" -CXX="$CXX $mandatory_flags" +CC="$CC $sensible_flags $mandatory_flags" +CXX="$CXX $sensible_flags $mandatory_flags" # go to upx top-level directory # HINT: set "top_srcdir" manually if your system does not have "readlink" @@ -93,8 +93,9 @@ check_submodule() { # build run "+" mkdir -p "build/by-hand" if check_submodule bzip2; then + test -z "${bzip2_extra_flags+set}" && bzip2_extra_flags= for f in "$rel_top_srcdir"/vendor/bzip2/*.c; do - run "CC $f" $CC -c "$f" + run "CC $f" $CC $bzip2_extra_flags -c "$f" done fi if check_submodule ucl; then @@ -103,13 +104,15 @@ if check_submodule ucl; then done fi if check_submodule zlib; then + test -z "${zlib_extra_flags+set}" && zlib_extra_flags="-DHAVE_UNISTD_H -DHAVE_VSNPRINTF" for f in "$rel_top_srcdir"/vendor/zlib/*.c; do - run "CC $f" $CC -DHAVE_UNISTD_H -DHAVE_VSNPRINTF -c "$f" + run "CC $f" $CC $zlib_extra_flags -c "$f" done fi if check_submodule zstd; then + test -z "${zstd_extra_flags+set}" && zstd_extra_flags="-DDYNAMIC_BMI2=0 -DZSTD_DISABLE_ASM" for f in "$rel_top_srcdir"/vendor/zstd/lib/*/*.c; do - run "CC $f" $CC -DDYNAMIC_BMI2=0 -DZSTD_DISABLE_ASM -c "$f" + run "CC $f" $CC $zstd_extra_flags -c "$f" done fi run "+" cd "$rel_top_srcdir" || exit 1 diff --git a/src/compress/compress_zstd.cpp b/src/compress/compress_zstd.cpp index c08c17e9..2f585e4d 100644 --- a/src/compress/compress_zstd.cpp +++ b/src/compress/compress_zstd.cpp @@ -221,6 +221,7 @@ TEST_CASE("upx_zstd_decompress") { d_len = 31; r = upx_zstd_decompress(c_data, 16, d_buf, &d_len, M_ZSTD, nullptr); CHECK(r == UPX_E_OUTPUT_OVERRUN); + UNUSED(r); } #endif // WITH_ZSTD diff --git a/src/headers.h b/src/headers.h index 5b2ddc83..1f2a8fc9 100644 --- a/src/headers.h +++ b/src/headers.h @@ -152,4 +152,10 @@ static_assert(sizeof(void *) == 8); #endif #endif +#ifdef WANT_WINDOWS_LEAN_H +#if defined(_WIN32) || defined(__CYGWIN__) +#include "util/windows_lean.h" +#endif +#endif + /* vim:set ts=4 sw=4 et: */ diff --git a/src/help.cpp b/src/help.cpp index 1d98f90e..981bb1ac 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -25,6 +25,7 @@ */ +#define WANT_WINDOWS_LEAN_H 1 // _WIN32_WINNT #include "conf.h" #include "compress/compress.h" // upx_ucl_version_string() // for list_all_packers(): @@ -449,19 +450,51 @@ void show_sysinfo(const char *options_var) { con_fprintf(f, "UPX version: "); fflush(f); show_version(true); + con_fprintf(f, "UPX version internal: 0x%06x %s\n", UPX_VERSION_HEX, UPX_VERSION_STRING); } fflush(stdout); // Compilation Flags - if (opt->verbose >= 2) { + { size_t cf_count = 0; - auto cf_print = [f, &cf_count](const char *name, const char *fmt, upx_int64_t v) noexcept { + auto cf_print = [f, &cf_count](const char *name, const char *fmt, upx_int64_t v, + int need_verbose = 2) noexcept { + if (opt->verbose < need_verbose) + return; if (cf_count++ == 0) con_fprintf(f, "\nCompilation flags:\n"); con_fprintf(f, " %s = ", name); con_fprintf(f, fmt, v); con_fprintf(f, "\n"); }; + // compiler +#if defined(ACC_CC_CLANG) + cf_print("ACC_CC_CLANG", "0x%06llx", ACC_CC_CLANG + 0, 3); +#endif +#if defined(ACC_CC_GNUC) + cf_print("ACC_CC_GNUC", "0x%06llx", ACC_CC_GNUC + 0, 3); +#endif +#if defined(ACC_CC_MSC) + cf_print("ACC_CC_MSC", "%lld", ACC_CC_MSC + 0, 3); +#endif +#if defined(__clang__) + cf_print("__clang__", "%lld", __clang__ + 0); +#endif +#if defined(__clang_major__) + cf_print("__clang_major__", "%lld", __clang_major__ + 0); +#endif +#if defined(__GNUC__) + cf_print("__GNUC__", "%lld", __GNUC__ + 0); +#endif +#if defined(__GNUC_MINOR__) + cf_print("__GNUC_MINOR__", "%lld", __GNUC_MINOR__ + 0); +#endif +#if defined(_MSC_VER) + cf_print("_MSC_VER", "%lld", _MSC_VER + 0); +#endif +#if defined(_MSC_FULL_VER) + cf_print("_MSC_FULL_VER", "%lld", _MSC_FULL_VER + 0); +#endif // OS and libc #if defined(WINVER) cf_print("WINVER", "0x%04llx", WINVER + 0); @@ -473,21 +506,16 @@ void show_sysinfo(const char *options_var) { 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); + cf_print("_USE_MINGW_ANSI_STDIO", "%lld", _USE_MINGW_ANSI_STDIO + 0, 3); #endif #if defined(__USE_MINGW_ANSI_STDIO) - cf_print("__USE_MINGW_ANSI_STDIO", "%lld", __USE_MINGW_ANSI_STDIO + 0); + cf_print("__USE_MINGW_ANSI_STDIO", "%lld", __USE_MINGW_ANSI_STDIO + 0, 3); #endif #if defined(__GLIBC__) cf_print("__GLIBC__", "%lld", __GLIBC__ + 0); #endif #if defined(__GLIBC_MINOR__) cf_print("__GLIBC_MINOR__", "%lld", __GLIBC_MINOR__ + 0); -#endif - // compiler -#if defined(_MSC_VER) && defined(_MSC_FULL_VER) - cf_print("_MSC_VER", "%lld", _MSC_VER + 0); - cf_print("_MSC_FULL_VER", "%lld", _MSC_FULL_VER + 0); #endif UNUSED(cf_count); UNUSED(cf_print); @@ -517,6 +545,8 @@ void show_sysinfo(const char *options_var) { con_fprintf(f, "\n"); if (e && e[0]) con_fprintf(f, "Contents of environment variable %s: '%s'\n\n", options_var, e); + else if (e) + con_fprintf(f, "Environment variable '%s' is set but empty.\n\n", options_var); else con_fprintf(f, "Environment variable '%s' is not set.\n\n", options_var); } diff --git a/src/options.cpp b/src/options.cpp index 69bd5599..93c59518 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -39,6 +39,7 @@ std::mutex opt_lock_mutex; **************************************************************************/ void Options::reset() noexcept { +#define opt ERROR_DO_NOT_USE_opt // protect against using the wrong variable Options *const o = this; mem_clear(o); o->crp.reset(); @@ -81,6 +82,7 @@ void Options::reset() noexcept { o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST o->win32_pe.strip_relocs = -1; o->win32_pe.keep_resource = ""; +#undef opt } /************************************************************************* @@ -88,7 +90,7 @@ void Options::reset() noexcept { **************************************************************************/ TEST_CASE("Options::reset") { -#define opt DO_NOT_USE_opt +#define opt ERROR_DO_NOT_USE_opt // protect against using the wrong variable COMPILE_TIME_ASSERT(std::is_standard_layout::value) COMPILE_TIME_ASSERT(std::is_nothrow_default_constructible::value) COMPILE_TIME_ASSERT(std::is_trivially_copyable::value) @@ -97,7 +99,6 @@ TEST_CASE("Options::reset") { Options *const o = &local_options; o->reset(); CHECK(o->o_unix.osabi0 == 3); - // static_assert(TABLESIZE(o->win32_pe.compress_rt) == 25); // 25 == RT_LAST CHECK(o->win32_pe.compress_exports); CHECK(o->win32_pe.compress_icons); diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 650412dc..c6be909f 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -1637,15 +1637,15 @@ PackLinuxElf64amd::defineSymbols(Filter const *ft) PackLinuxElf64::defineSymbols(ft); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.elf-so_entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.elf-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.elf-so_fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.shlib-init.h" void @@ -1677,9 +1677,9 @@ PackLinuxElf32x86::buildLoader(const Filter *ft) tmp, sizeof(stub_i386_linux_elf_fold), ft ); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-bsd.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-bsd.elf-fold.h" void @@ -1705,10 +1705,10 @@ PackBSDElf32x86::buildLoader(const Filter *ft) tmp, sizeof(stub_i386_bsd_elf_fold), ft); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-netbsd.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-netbsd.elf-fold.h" #define WANT_NHDR_ENUM @@ -1738,7 +1738,7 @@ PackNetBSDElf32x86::buildLoader(const Filter *ft) tmp, sizeof(stub_i386_netbsd_elf_fold), ft); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-openbsd.elf-fold.h" void @@ -1764,33 +1764,33 @@ PackOpenBSDElf32x86::buildLoader(const Filter *ft) tmp, sizeof(stub_i386_openbsd_elf_fold), ft); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v5a-linux.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v5a-linux.elf-so_entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v5a-linux.elf-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v5a-linux.elf-so_fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v5t-linux.shlib-init.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v4a-linux.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v4a-linux.elf-so_entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v4a-linux.elf-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v4a-linux.elf-so_fold.h" #if 0 -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v4a-linux.shlib-init.h" #endif -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/armeb.v4a-linux.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/armeb.v4a-linux.elf-fold.h" void @@ -1822,11 +1822,11 @@ PackLinuxElf32armLe::buildLoader(Filter const *ft) } } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/mipsel.r3000-linux.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/mipsel.r3000-linux.elf-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/mipsel.r3000-linux.shlib-init.h" void @@ -1843,11 +1843,11 @@ PackLinuxElf32mipsel::buildLoader(Filter const *ft) stub_mipsel_r3000_linux_elf_fold, sizeof(stub_mipsel_r3000_linux_elf_fold), ft); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/mips.r3000-linux.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/mips.r3000-linux.elf-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/mips.r3000-linux.shlib-init.h" void @@ -1864,9 +1864,9 @@ PackLinuxElf32mipseb::buildLoader(Filter const *ft) stub_mips_r3000_linux_elf_fold, sizeof(stub_mips_r3000_linux_elf_fold), ft); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc-linux.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc-linux.elf-fold.h" void @@ -1877,9 +1877,9 @@ PackLinuxElf32ppc::buildLoader(const Filter *ft) stub_powerpc_linux_elf_fold, sizeof(stub_powerpc_linux_elf_fold), ft); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc64le-linux.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc64le-linux.elf-fold.h" void @@ -1890,9 +1890,9 @@ PackLinuxElf64ppcle::buildLoader(const Filter *ft) stub_powerpc64le_linux_elf_fold, sizeof(stub_powerpc64le_linux_elf_fold), ft); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc64-linux.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc64-linux.elf-fold.h" void @@ -1903,15 +1903,15 @@ PackLinuxElf64ppc::buildLoader(const Filter *ft) stub_powerpc64_linux_elf_fold, sizeof(stub_powerpc64_linux_elf_fold), ft); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/amd64-linux.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/amd64-linux.elf-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/amd64-linux.elf-so_entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/amd64-linux.elf-so_fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/amd64-linux.shlib-init.h" void @@ -1928,15 +1928,15 @@ PackLinuxElf64amd::buildLoader(const Filter *ft) stub_amd64_linux_elf_fold, sizeof(stub_amd64_linux_elf_fold), ft); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm64-linux.elf-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm64-linux.elf-so_entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm64-linux.elf-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm64-linux.elf-so_fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm64-linux.shlib-init.h" void diff --git a/src/p_lx_exc.cpp b/src/p_lx_exc.cpp index 24f83c19..d80ad18c 100644 --- a/src/p_lx_exc.cpp +++ b/src/p_lx_exc.cpp @@ -74,14 +74,14 @@ PackBSDI386::PackBSDI386(InputFile *f) : super(f) } } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.elf.execve-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.elf.execve-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-bsd.elf.execve-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-bsd.elf.execve-fold.h" diff --git a/src/p_lx_interp.cpp b/src/p_lx_interp.cpp index bd03d262..469d2513 100644 --- a/src/p_lx_interp.cpp +++ b/src/p_lx_interp.cpp @@ -50,9 +50,9 @@ // **************************************************************************/ -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.elf.interp-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.elf.interp-fold.h" PackLinuxElf32x86interp::PackLinuxElf32x86interp(InputFile *f) : diff --git a/src/p_lx_sh.cpp b/src/p_lx_sh.cpp index 82a1850d..f7c25486 100644 --- a/src/p_lx_sh.cpp +++ b/src/p_lx_sh.cpp @@ -47,9 +47,9 @@ // **************************************************************************/ -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.elf.shell-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.elf.shell-fold.h" diff --git a/src/p_mach.cpp b/src/p_mach.cpp index 96455422..7878916c 100644 --- a/src/p_mach.cpp +++ b/src/p_mach.cpp @@ -45,48 +45,48 @@ # pragma GCC diagnostic ignored "-Wcast-align" #endif -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-darwin.macho-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-darwin.macho-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-darwin.macho-upxmain.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-darwin.dylib-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/amd64-darwin.macho-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/amd64-darwin.macho-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/amd64-darwin.macho-upxmain.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/amd64-darwin.dylib-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v5a-darwin.macho-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v5a-darwin.macho-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm64-darwin.macho-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm64-darwin.macho-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc-darwin.macho-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc-darwin.macho-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc-darwin.macho-upxmain.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc-darwin.dylib-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc64-darwin.macho-entry.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc64-darwin.macho-fold.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc64-darwin.dylib-entry.h" // Packing a Darwin (Mach-o) Mac OS X dylib (dynamic shared library) diff --git a/src/p_vmlinx.cpp b/src/p_vmlinx.cpp index adcedc72..63736e2e 100644 --- a/src/p_vmlinx.cpp +++ b/src/p_vmlinx.cpp @@ -38,15 +38,15 @@ #include "p_vmlinx.h" #include "linker.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.kernel.vmlinux.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/amd64-linux.kernel.vmlinux.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v5a-linux.kernel.vmlinux.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/armeb.v5a-linux.kernel.vmlinux.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc-linux.kernel.vmlinux.h" @@ -943,7 +943,7 @@ void PackVmlinuxPPC32::buildLoader(const Filter *ft) addLoader("IDENTSTR,UPX1HEAD", nullptr); } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc64le-linux.kernel.vmlinux.h" void PackVmlinuxPPC64LE::buildLoader(const Filter *ft) { @@ -971,15 +971,15 @@ void PackVmlinuxPPC64LE::buildLoader(const Filter *ft) } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.kernel.vmlinux-head.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/amd64-linux.kernel.vmlinux-head.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v5a-linux.kernel.vmlinux-head.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/armeb.v5a-linux.kernel.vmlinux-head.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc-linux.kernel.vmlinux-head.h" unsigned PackVmlinuxI386::write_vmlinux_head( @@ -1166,7 +1166,7 @@ bool PackVmlinuxPPC32::has_valid_vmlinux_head() return false; } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/powerpc64le-linux.kernel.vmlinux-head.h" bool PackVmlinuxPPC64LE::has_valid_vmlinux_head() { diff --git a/src/p_vmlinz.cpp b/src/p_vmlinz.cpp index 8e0cbb40..d9abdb51 100644 --- a/src/p_vmlinz.cpp +++ b/src/p_vmlinz.cpp @@ -37,7 +37,7 @@ #include "linker.h" #include -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/i386-linux.kernel.vmlinuz.h" static const unsigned stack_offset_during_uncompression = 0x9000; @@ -921,9 +921,9 @@ Linker* PackVmlinuzARMEL::newLinker() const return new ElfLinkerArmLE; } -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v5a-linux.kernel.vmlinux.h" -static const +static const CLANG_FORMAT_DUMMY_STATEMENT #include "stub/arm.v5a-linux.kernel.vmlinuz-head.h" void PackVmlinuzARMEL::buildLoader(const Filter *ft) diff --git a/src/work.cpp b/src/work.cpp index 3b839172..bd8c7e38 100644 --- a/src/work.cpp +++ b/src/work.cpp @@ -30,15 +30,13 @@ // of class PackerBase which then does the actual work. // And see p_com.cpp for a simple executable format. +#define WANT_WINDOWS_LEAN_H 1 // _get_osfhandle, GetFileTime, SetFileTime #include "headers.h" #if USE_UTIMENSAT #include #include #include #endif -#if defined(_WIN32) || defined(__CYGWIN__) -#include "util/windows_lean.h" // _get_osfhandle, GetFileTime, SetFileTime -#endif #include "conf.h" #include "file.h" #include "packmast.h"