diff --git a/.appveyor.yml b/.appveyor.yml index 441a7238..a698ed2f 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -4,7 +4,7 @@ os: Visual Studio 2015 environment: - global: { TRAVIS_OS_NAME: windows, C: "", B: release, CROSS: "", T: "" } + global: { TRAVIS_OS_NAME: windows, CROSS: "", C: "", B: release, T: "" } matrix: - { C: msvc-10.0-x86, CL_VERSION: 16.00, VS_VERSION: 2010 } ### - { C: msvc-10.0-x64, CL_VERSION: 16.00, VS_VERSION: 2010 } # AppVeyor: x64 compiler is not installed @@ -20,6 +20,8 @@ environment: init: - git config --global core.autocrlf input - where bash & where cat & where curl & where git & where sed & where tar +# - bash --version & git --version & sed --version & tar --version + - git --version & bash --version # - dir "c:\Program Files\Git\usr\bin" # - dir "c:\cygwin\bin" # - dir "c:\mingw\bin" diff --git a/.circle.yml b/.circle.yml index f955457d..5c0d0b57 100644 --- a/.circle.yml +++ b/.circle.yml @@ -9,9 +9,9 @@ branches: machine: environment: TRAVIS_OS_NAME: linux + CROSS: C: gcc-4.8-m64 B: release - CROSS: T: checkout: diff --git a/.github/travis_build.sh b/.github/travis_build.sh index 0a591284..9ccdc10b 100644 --- a/.github/travis_build.sh +++ b/.github/travis_build.sh @@ -24,35 +24,11 @@ echo "$CC --version"; $CC --version echo "$CXX --version"; $CXX --version echo -# whitespace +# check whitespace if [[ $TRAVIS_OS_NAME == linux ]]; then cd / && cd $upx_SRCDIR || exit 1 echo "Checking source code for whitespace violations..." -find . \ - -type d -name '.git' -prune -o \ - -type d -name '.hg' -prune -o \ - -type d -name 'build' -prune -o \ - -type d -name 'tmp' -prune -o \ - -type f -iname '*.bat' -prune -o \ - -type f -iname '*.exe' -prune -o \ - -type f -iname '*.pdf' -prune -o \ - -type f -print0 | LC_ALL=C sort -z | \ -xargs -0r perl -n -e ' - if (m,[\r\x1a],) { print "ERROR: DOS EOL detected $ARGV: $_"; exit(1); } - if (m,([ \t]+)$,) { - # allow exactly two trailing spaces for GitHub flavoured Markdown in .md files - if ($1 ne " " || $ARGV !~ m,\.md$,) { - print "ERROR: trailing whitespace detected $ARGV: $_"; exit(1); - } - } - if (m,\t,) { - if ($ARGV =~ m,(^|/)\.gitmodules$,) { } - elsif ($ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { } - elsif ($ARGV =~ m,/tmp/.*\.(disasm|dump)$,) { } - elsif ($ARGV =~ m,/src/stub/src/arch/.*\.S$,) { } - else { print "ERROR: hard TAB detected $ARGV: $_"; exit(1); } - } -' || exit 1 +bash ./src/stub/scripts/check_whitespace.sh || exit 1 echo " Passed." fi # linux @@ -64,7 +40,7 @@ set -x cd / && cd $ucl_BUILDDIR || exit 1 if [[ -n $BM_CROSS || $TRAVIS_OS_NAME == windows ]]; then - # configure is too old + # ucl-1.03/configure is too old - build manually rm -f ./*.o libucl.a $CC -O2 -I$ucl_SRCDIR/include -I$ucl_SRCDIR -c $ucl_SRCDIR/src/*.c $AR rcs libucl.a *.o @@ -81,12 +57,13 @@ fi # build zlib # -if [[ $BUILD_LOCAL_ZLIB ]]; then +if [[ $BUILD_LOCAL_ZLIB == 1 ]]; then cd / && cd $zlib_BUILDDIR || exit 1 + # build manually rm -f ./*.o libz.a $CC -O2 -c $zlib_SRCDIR/*.c $AR rcs libz.a *.o -fi # BUILD_LOCAL_ZLIB +fi # # build UPX @@ -97,7 +74,7 @@ cd / && cd $upx_BUILDDIR || exit 1 make="make -f $upx_SRCDIR/src/Makefile" EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -DUCL_NO_ASM" EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$ucl_BUILDDIR/src/.libs" -if [[ $BUILD_LOCAL_ZLIB ]]; then +if [[ $BUILD_LOCAL_ZLIB == 1 ]]; then EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -I$zlib_SRCDIR" EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$zlib_BUILDDIR" fi @@ -124,11 +101,11 @@ if [[ $BM_B =~ (^|\+)ALLOW_FAIL($|\+) ]]; then fi export EXTRA_CPPFLAGS EXTRA_CXXFLAGS EXTRA_LDFLAGS -$make +[[ -z $upx_exeext ]] && upx_exeext=.out +$make exeext=$upx_exeext -[[ -z $exeext ]] && exeext=.out -ls -l upx${exeext} -$SIZE upx${exeext} || true -file upx${exeext} +ls -l upx${upx_exeext} +$SIZE upx${upx_exeext} || true +file upx${upx_exeext} exit 0 diff --git a/.github/travis_init.sh b/.github/travis_init.sh index 00bd4d16..19066f41 100644 --- a/.github/travis_init.sh +++ b/.github/travis_init.sh @@ -6,12 +6,12 @@ #set -x # debug umask 022 -# rename short Build-Matrix variables to more readable names +# rename short variables to more readable Build-Matrix BM_ names # C is COMPILER -# B is BUILD_TYPE -# T is TESTSUITE_FLAGS -BM_C=$C; BM_B=$B; BM_CROSS=$CROSS; BM_T=$T -unset C B CROSS T +# B is BUILD_OPTIONS +# T is TESTSUITE_OPTIONS +BM_CROSS=$CROSS; BM_C=$C; BM_B=$B; BM_T=$T +unset CROSS C B T [[ -z $BM_C ]] && BM_C=gcc [[ -z $BM_B ]] && BM_B=release @@ -41,7 +41,7 @@ CC=false CXX=false SCAN_BUILD=false AR=ar SIZE=size if [[ -n $APPVEYOR_JOB_ID ]]; then BUILD_LOCAL_ZLIB=1 - export exeext=.exe + upx_exeext=.exe # dir c:\cygwin case $BM_C in gcc-m32 | gcc-4.9-m32) @@ -68,7 +68,7 @@ if [[ -n $BM_CROSS ]]; then case $BM_CROSS-$BM_C in arm-linux-gnueabi-gcc | arm-linux-gnueabi-gcc-4.6) export upx_EXTRA_LDFLAGS="-static-libgcc -static-libstdc++" - [[ -z $upx_qemu ]] && upx_qemu="qemu-arm-static -L/usr/arm-linux-gnueabi" + [[ -z $upx_qemu ]] && upx_qemu="qemu-arm -L/usr/arm-linux-gnueabi" x=arm-linux-gnueabi; AR="$x-ar"; CC="$x-gcc"; CXX="$x-g++" ;; arm-linux-gnueabihf-gcc | arm-linux-gnueabihf-gcc-4.6) export upx_EXTRA_LDFLAGS="-static-libgcc -static-libstdc++" @@ -142,22 +142,28 @@ done [[ -z $lcov_OUTPUTDIR ]] && lcov_OUTPUTDIR=$(readlink -mn -- "$toptop_bdir/.lcov-results") unset toptop_builddir toptop_bdir -# ensure absolute dirs +# ensure absolute directories +make_absolute() { + while [[ $# -gt 0 ]]; do + if [[ -n ${!1} ]]; then + d=$(readlink -mn -- "${!1}") + eval $1="$d" + fi + shift + done +} for var_prefix in ucl upx upx_testsuite zlib; do -for var_suffix in _BUILDDIR _SRCDIR; do - var_name=${var_prefix}${var_suffix} - if [[ -n ${!var_name} ]]; then - d=$(readlink -mn -- "${!var_name}") - eval $var_name="$d" - fi + for var_suffix in _BUILDDIR _SRCDIR; do + make_absolute ${var_prefix}${var_suffix} + done done -done -unset var_name var_prefix var_suffix +make_absolute lcov_OUTPUTDIR +unset var_prefix var_suffix print_settings() { local v var_prefix var_suffix # Build Matrix - for v in TRAVIS_OS_NAME BM_C BM_B BM_CROSS BM_T; do + for v in TRAVIS_OS_NAME BM_CROSS BM_C BM_B BM_T; do [[ -n ${!v} ]] && echo "${v}='${!v}'" done # BM_C related @@ -166,8 +172,8 @@ print_settings() { v=EXTRA_${v} [[ -n ${!v} ]] && echo "${v}='${!v}'" done - # dirs and other info - for v in TRAVIS_XCODE_SDK UPX_UCLDIR; do + # directories and other info + for v in TRAVIS_XCODE_SDK UPX_UCLDIR lcov_OUTPUTDIR; do [[ -n ${!v} ]] && echo "${v}='${!v}'" done for var_prefix in ucl upx upx_testsuite zlib; do @@ -179,5 +185,4 @@ print_settings() { ##env | LC_ALL=C sort } - true diff --git a/.github/travis_testsuite_1.sh b/.github/travis_testsuite_1.sh index 3695f8bb..6c43cbc8 100644 --- a/.github/travis_testsuite_1.sh +++ b/.github/travis_testsuite_1.sh @@ -16,7 +16,6 @@ argv0="$0"; argv0dir=$(readlink -en -- "$0"); argv0dir=$(dirname "$argv0dir") fi source "$argv0dir/travis_init.sh" || exit 1 -# BM_T is TESTSUITE_FLAGS if [[ $BM_T =~ (^|\+)SKIP($|\+) ]]; then echo "UPX testsuite SKIPPED." exit 0 @@ -58,32 +57,33 @@ testsuite_check_sha() { diff -u $1/.sha256sums.expected $1/.sha256sums.current || true #exit 1 exit_code=1 + let num_errors+=1 || true fi echo } testsuite_run_compress() { testsuite_header $testdir - local f ff - for f in $upx_testsuite_SRCDIR/files/packed/*/upx-3.91*; do + local f + for f in t01_decompressed/*/*; do testsuite_split_f $f [[ -z $fb ]] && continue mkdir -p $testdir/$fsubdir - ff=t01_decompressed/$fsubdir/$fb - $upx_exe --prefer-ucl "$@" $ff -o $testdir/$fsubdir/$fb + $upx_run --prefer-ucl "$@" $f -o $testdir/$fsubdir/$fb done testsuite_check_sha $testdir - $upx_exe -l $testdir/*/* - $upx_exe --file-info $testdir/*/* - $upx_exe -t $testdir/*/* + $upx_run -l $testdir/*/* + $upx_run --file-info $testdir/*/* + $upx_run -t $testdir/*/* } # /*********************************************************************** # // init # ************************************************************************/ -#set -x +#set -x # debug exit_code=0 +num_errors=0 if [[ $BM_T =~ (^|\+)ALLOW_FAIL($|\+) ]]; then echo "ALLOW_FAIL" @@ -93,32 +93,38 @@ fi [[ -z $upx_exe && -f $upx_BUILDDIR/upx.out ]] && upx_exe=$upx_BUILDDIR/upx.out [[ -z $upx_exe && -f $upx_BUILDDIR/upx.exe ]] && upx_exe=$upx_BUILDDIR/upx.exe if [[ -z $upx_exe ]]; then exit 1; fi +upx_run=$upx_exe if [[ $BM_T =~ (^|\+)qemu($|\+) && -n $upx_qemu ]]; then - upx_exe="$upx_qemu $upx_qemu_flags -- $upx_exe" + upx_run="$upx_qemu $upx_qemu_flags -- $upx_exe" fi if [[ $BM_T =~ (^|\+)wine($|\+) && -n $upx_wine ]]; then - upx_exe="$upx_wine $upx_wine_flags $upx_exe" + upx_run="$upx_wine $upx_wine_flags $upx_exe" fi -if ! $upx_exe --version >/dev/null; then exit 1; fi - if [[ $BM_T =~ (^|\+)valgrind($|\+) ]]; then - valgrind_flags="--leak-check=full --show-reachable=yes" - valgrind_flags="-q --leak-check=no --error-exitcode=1" - valgrind_flags="--leak-check=no --error-exitcode=1" - upx_exe="valgrind $valgrind_flags $upx_exe" + if [[ -z $upx_valgrind ]]; then + upx_valgrind="valgrind" + fi + if [[ -z $upx_valgrind_flags ]]; then + upx_valgrind_flags="--leak-check=full --show-reachable=yes" + upx_valgrind_flags="-q --leak-check=no --error-exitcode=1" + upx_valgrind_flags="--leak-check=no --error-exitcode=1" + fi + upx_run="$upx_valgrind $upx_valgrind_flags $upx_exe" fi if [[ $BM_B =~ (^|\+)coverage($|\+) ]]; then (cd / && cd $upx_BUILDDIR && lcov -d . --zerocounters) fi -rm -rf ./testsuite_1 -mkdir testsuite_1 -cd testsuite_1 - export UPX= export UPX="--no-color --no-progress" +# let's go +if ! $upx_run --version >/dev/null; then exit 1; fi +rm -rf ./testsuite_1 +mkbuilddirs testsuite_1 +cd testsuite_1 || exit 1 + # /*********************************************************************** # // decompression tests @@ -142,7 +148,7 @@ for f in $upx_testsuite_SRCDIR/files/packed/*/upx-3.91*; do testsuite_split_f $f [[ -z $fb ]] && continue mkdir -p $testdir/$fsubdir - $upx_exe -d $f -o $testdir/$fsubdir/$fb + $upx_run -d $f -o $testdir/$fsubdir/$fb done testsuite_check_sha $testdir @@ -222,10 +228,21 @@ a647ed1aea16f58b544228279ad7159cd3ec5c3533efef1fd2df5a5a59b5d663 *i386-win32.pe/ time testsuite_run_compress --all-methods --no-lzma --no-filter +testsuite_header "UPX testsuite summary" +echo "upx_exe='$upx_exe'" +if [[ $upx_run != $upx_exe ]]; then + echo "upx_run='$upx_run'" +fi +if [[ -f $upx_exe ]]; then + ls -l "$upx_exe" + file "$upx_exe" || true +fi +echo "upx_testsuite_SRCDIR='$upx_testsuite_SRCDIR'" +echo "upx_testsuite_BUILDDIR='$upx_testsuite_BUILDDIR'" echo if [[ $exit_code == 0 ]]; then echo "UPX testsuite passed. All done." else - echo "UPX-ERROR: UPX testsuite FAILED. See log file." + echo "UPX-ERROR: UPX testsuite FAILED with $num_errors error(s). See log file." fi exit $exit_code diff --git a/.travis.yml b/.travis.yml index f435b21a..adc80605 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ addons: env: global: - - C= B= CROSS= T= + - CROSS= C= B= T= matrix: - TRAVIS_EMPTY_JOB_WORKAROUND=true @@ -140,19 +140,19 @@ matrix: addons: { apt: { sources: *S, packages: [ "clang-3.8" ] } } - os: linux compiler: gcc - env: C=gcc-4.6 CROSS=arm-linux-gnueabi T=SKIP + env: CROSS=arm-linux-gnueabi C=gcc-4.6 T=SKIP addons: { apt: { packages: [ "g++-arm-linux-gnueabi", "qemu-user" ] } } - os: linux compiler: gcc - env: C=gcc-4.6 CROSS=arm-linux-gnueabihf T=SKIP + env: CROSS=arm-linux-gnueabihf C=gcc-4.6 T=SKIP addons: { apt: { packages: [ "g++-arm-linux-gnueabihf", "qemu-user" ] } } - os: linux compiler: gcc - env: C=gcc-4.6 CROSS=i386-w64-mingw32 T=wine + env: CROSS=i386-w64-mingw32 C=gcc-4.6 T=wine addons: { apt: { packages: [ "binutils-mingw-w64-i686", "g++-mingw-w64-i686", "wine" ] } } - os: linux compiler: gcc - env: C=gcc-4.6 CROSS=x86_64-w64-mingw32 T=wine + env: CROSS=x86_64-w64-mingw32 C=gcc-4.6 T=wine addons: { apt: { packages: [ "binutils-mingw-w64-x86-64", "g++-mingw-w64-x86-64", "wine" ] } } - os: osx compiler: clang diff --git a/src/Makefile b/src/Makefile index 703c9597..8adb4aa9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -85,7 +85,7 @@ compress_lzma$(objext) filteri$(objext) : CXXFLAGS := $(filter-out $(CXXFLAGS_SA endif -all: upx$(exeext) | ./.depend +all: check-whitespace upx$(exeext) | ./.depend .DELETE_ON_ERROR: upx$(exeext) $(upx_OBJECTS) ./.depend upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES) @@ -106,6 +106,11 @@ else .PHONY: ./.depend endif +ifeq ($(shell uname),Linux) +check-whitespace : ; bash $(top_srcdir)/src/stub/scripts/check_whitespace.sh $(top_srcdir) +endif +.PHONY: check-whitespace + ./.depend compress_lzma$(objext) : INCLUDES += -I$(UPX_LZMADIR) diff --git a/src/p_mach.cpp b/src/p_mach.cpp index 0512f572..c8481dc5 100644 --- a/src/p_mach.cpp +++ b/src/p_mach.cpp @@ -2086,7 +2086,7 @@ int PackMachBase::canUnpack() unsigned const *p; for (p = (unsigned const *)&buf[0x1000]; p > lo; ) if (*--p) { overlay_offset = *(TE32 const *)p; - if (overlay_offset < offLINK) { + if ((off_t)overlay_offset < offLINK) { overlay_offset -= (char const *)p - (char const *)lo + (offLINK - 0x1000) - sizeof(l_info); fi->seek(overlay_offset, SEEK_SET); @@ -2097,7 +2097,7 @@ int PackMachBase::canUnpack() } } } - + overlay_offset = 0; } } diff --git a/src/stub/scripts/check_whitespace.sh b/src/stub/scripts/check_whitespace.sh new file mode 100755 index 00000000..bffb987d --- /dev/null +++ b/src/stub/scripts/check_whitespace.sh @@ -0,0 +1,33 @@ +#! /usr/bin/env bash +## vim:set ts=4 sw=4 et: +set -e; set -o pipefail + +# Copyright (C) Markus Franz Xaver Johannes Oberhumer + +[[ -z $1 ]] || cd "$1" || exit 1 + +find . \ + -type d -name '.git' -prune -o \ + -type d -name '.hg' -prune -o \ + -type d -name 'build*' -prune -o \ + -type d -name 'tmp*' -prune -o \ + -type f -iname '*.bat' -prune -o \ + -type f -iname '*.exe' -prune -o \ + -type f -iname '*.pdf' -prune -o \ + -type f -print0 | LC_ALL=C sort -z | \ +xargs -0r perl -n -e ' + if (m,[\r\x1a],) { print "ERROR: DOS EOL detected $ARGV: $_"; exit(1); } + if (m,([ \t]+)$,) { + # allow exactly two trailing spaces for GitHub flavoured Markdown in .md files + if ($1 ne " " || $ARGV !~ m,\.md$,) { + print "ERROR: trailing whitespace detected $ARGV: $_"; exit(1); + } + } + if (m,\t,) { + if ($ARGV =~ m,(^|/)\.gitmodules$,) { } + elsif ($ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { } + elsif ($ARGV =~ m,/tmp/.*\.(disasm|dump)$,) { } + elsif ($ARGV =~ m,/src/stub/src/arch/.*\.S$,) { } + else { print "ERROR: hard TAB detected $ARGV: $_"; exit(1); } + } +' || exit 1