diff --git a/.circle.yml b/.circle.yml index 47058ac3..00f679d6 100644 --- a/.circle.yml +++ b/.circle.yml @@ -8,7 +8,6 @@ branches: machine: environment: - TRAVIS_BUILD_DIR: $HOME/upx TRAVIS_OS_NAME: linux C: gcc-4.8-m64 B: release @@ -20,14 +19,14 @@ checkout: dependencies: pre: - - mkdir -p $TRAVIS_BUILD_DIR/deps - - cd $TRAVIS_BUILD_DIR/deps && wget --no-check-certificate -q -O - https://download.freenas.org/distfiles/ucl-1.03.tar.gz | tar -xz - - cd $TRAVIS_BUILD_DIR/deps && git clone https://github.com/upx/upx-testsuite + - mkdir -p ../deps + - cd ../deps && wget --no-check-certificate -q -O - https://download.freenas.org/distfiles/ucl-1.03.tar.gz | tar -xz + - cd ../deps && git clone https://github.com/upx/upx-testsuite override: - - bash $TRAVIS_BUILD_DIR/.github/travis_build.sh + - bash ./.github/travis_build.sh test: override: - - bash $TRAVIS_BUILD_DIR/.github/travis_testsuite.sh + - bash ./.github/travis_testsuite.sh # vim:set ts=2 sw=2 et: diff --git a/.github/travis_build.sh b/.github/travis_build.sh index b3d38eca..644b9e01 100644 --- a/.github/travis_build.sh +++ b/.github/travis_build.sh @@ -5,10 +5,9 @@ set -e; set -o pipefail # Support for Travis CI -- https://travis-ci.org/upx/upx/builds # Copyright (C) Markus Franz Xaver Johannes Oberhumer -source "$TRAVIS_BUILD_DIR/.github/travis_init.sh" || exit 1 +source ./.github/travis_init.sh || exit 1 echo "BUILD_METHOD='$BUILD_METHOD'" -echo "BUILD_DIR='$BUILD_DIR'" echo "UPX_UCLDIR='$UPX_UCLDIR'" echo "CC='$CC'" echo "CXX='$CXX'" @@ -18,17 +17,20 @@ echo "CXXFLAGS='$CXXFLAGS'" echo "LDFLAGS='$LDFLAGS'" echo "LIBS='$LIBS'" echo "SCAN_BUILD='$SCAN_BUILD'" -#env | LC_ALL=C sort +##env | LC_ALL=C sort echo "$CC --version"; $CC --version echo "$CXX --version"; $CXX --version # whitespace -if test "$TRAVIS_OS_NAME" = "linux"; then +if [[ $TRAVIS_OS_NAME == linux ]]; then +cd $upx_SRCDIR || exit 1 echo "Checking source code for whitespace violations..." find . \ -type d -name '.git' -prune -o \ - -type d -name 'deps' -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 \ @@ -43,7 +45,7 @@ xargs -0r perl -n -e ' } if (m,\t,) { if ($ARGV =~ m,(^|/)\.gitmodules$,) { } - elsif ($ARGV =~ m,(^|/)make(file|vars),i) { } + elsif ($ARGV =~ m,(^|/)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); } @@ -58,38 +60,42 @@ set -x # build UCL # -cd /; cd "$UPX_UCLDIR" || exit 1 -./configure --enable-static --disable-shared --disable-asm +cd $ucl_BUILDDIR || exit 1 +if [[ ! -f config.status ]]; then +$ucl_SRCDIR/configure --enable-static --disable-shared --disable-asm +fi make # # build UPX # -cd /; cd "$BUILD_DIR" || exit 1 -make="make -f $TRAVIS_BUILD_DIR/src/Makefile" -export EXTRA_CPPFLAGS="-DUCL_NO_ASM" -case $BUILD_METHOD in - debug | debug+* | *+debug | *+debug+*) - make="$make USE_DEBUG=1" ;; +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" +case $BUILD_METHOD in coverage | coverage+* | *+coverage | *+coverage+*) + EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS -fprofile-arcs -ftest-coverage" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage" ;; esac -case $BUILD_METHOD in - sanitize | sanitize+* | *+sanitize | *+sanitize+*) - case $TRAVIS_OS_NAME-$CC in linux-gcc*) export EXTRA_LDFLAGS="-fuse-ld=gold" ;; esac - make="$make USE_SANITIZE=1" ;; +case $BUILD_METHOD in debug | debug+* | *+debug | *+debug+*) + make="$make USE_DEBUG=1" ;; esac -case $BUILD_METHOD in - scan-build | scan-build+* | *+scan-build | *+scan-build+*) - make="$SCAN_BUILD $make" ;; +case $BUILD_METHOD in sanitize | sanitize+* | *+sanitize | *+sanitize+*) + case $TRAVIS_OS_NAME-$CC in linux-gcc*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fuse-ld=gold" ;; esac + make="$make USE_SANITIZE=1" ;; esac -case $BUILD_METHOD in - valgrind | valgrind+* | *+valgrind | *+valgrind+*) - export EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -DWITH_VALGRIND" ;; +case $BUILD_METHOD in scan-build | scan-build+* | *+scan-build | *+scan-build+*) + make="$SCAN_BUILD $make" ;; esac -if test "$ALLOW_FAIL" = "1"; then +case $BUILD_METHOD in valgrind | valgrind+* | *+valgrind | *+valgrind+*) + EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -DWITH_VALGRIND" ;; +esac +if [[ $ALLOW_FAIL == 1 ]]; then echo "ALLOW_FAIL=$ALLOW_FAIL" set +e fi +export EXTRA_CPPFLAGS EXTRA_CXXFLAGS EXTRA_LDFLAGS $make diff --git a/.github/travis_init.sh b/.github/travis_init.sh index bc873df3..8777487d 100644 --- a/.github/travis_init.sh +++ b/.github/travis_init.sh @@ -3,17 +3,11 @@ # Support for Travis CI -- https://travis-ci.org/upx/upx/builds # Copyright (C) Markus Franz Xaver Johannes Oberhumer +#set -x # debug umask 022 -cd /; cd "$TRAVIS_BUILD_DIR" || exit 1 - -if test "X$C" = "X"; then C=gcc; fi -BUILD_DIR="$TRAVIS_BUILD_DIR/build/$C" -mkdir -p "$BUILD_DIR" - -if test "X$B" = "X"; then B=release; fi -BUILD_METHOD="$B" CC=false CXX=false SCAN_BUILD=false +[[ -z $C ]] && C=gcc case $C in clang | clang-m?? | clang-3.4-m?? | clang-[678][0-9][0-9]-m??) # standard system compiler @@ -37,4 +31,32 @@ case $C in esac export CC CXX -export UPX_UCLDIR="$TRAVIS_BUILD_DIR/deps/ucl-1.03" +[[ -z $B ]] && B=release +BUILD_METHOD="$B" + +# dirs +[[ -z $upx_SRCDIR ]] && upx_SRCDIR="$PWD" +[[ -z $ucl_SRCDIR ]] && ucl_SRCDIR="$PWD/../deps/ucl-1.03" +[[ -z $upx_testsuite_SRCDIR ]] && upx_testsuite_SRCDIR="$PWD/../deps/upx-testsuite" + +[[ -z $tmake_top_builddir ]] && tmake_top_builddir="$PWD/../build" +[[ -z $tmake_top_bdir ]] && tmake_top_bdir="$tmake_top_builddir/$C/$B" +upx_BUILDDIR="$tmake_top_bdir/upx" +ucl_BUILDDIR="$tmake_top_bdir/ucl-1.03" +upx_testsuite_BUILDDIR="$tmake_top_bdir/upx-testsuite" +# tools +lcov_OUTPUTDIR="$tmake_top_bdir/.lcov-results" + +mkdir -p -v $upx_BUILDDIR $ucl_BUILDDIR $upx_testsuite_BUILDDIR +[[ -d $tmake_top_bdir/.mfxnobackup ]] || echo "timestamp" > $tmake_top_bdir/.mfxnobackup + +export UPX_UCLDIR="$ucl_SRCDIR" + +# check dirs +cd / && cd $ucl_BUILDDIR || exit 1 +cd / && cd $ucl_SRCDIR || exit 1 +cd / && cd $upx_testsuite_BUILDDIR || exit 1 +cd / && cd $upx_testsuite_SRCDIR || exit 1 +cd / && cd $upx_BUILDDIR || exit 1 +# enter srcdir +cd / && cd $upx_SRCDIR || exit 1 diff --git a/.github/travis_testsuite.sh b/.github/travis_testsuite.sh index 2db76ee9..bcaa0703 100644 --- a/.github/travis_testsuite.sh +++ b/.github/travis_testsuite.sh @@ -5,17 +5,17 @@ set -e; set -o pipefail # Support for Travis CI -- https://travis-ci.org/upx/upx/builds # Copyright (C) Markus Franz Xaver Johannes Oberhumer -source "$TRAVIS_BUILD_DIR/.github/travis_init.sh" || exit 1 +source ./.github/travis_init.sh || exit 1 set -x -cd /; cd "$BUILD_DIR" || exit 1 -if test "$ALLOW_FAIL" = "1"; then +cd $upx_BUILDDIR || exit 1 +if [[ $ALLOW_FAIL == 1 ]]; then echo "ALLOW_FAIL=$ALLOW_FAIL" set +e - if ! test -x $PWD/upx.out; then exit 0; fi + if [[ ! -x $PWD/upx.out ]]; then exit 0; fi fi -if ! test -x $PWD/upx.out; then exit 1; fi +if [[ ! -x $PWD/upx.out ]]; then exit 1; fi # # very first version of the upx-testsuite @@ -24,61 +24,96 @@ if ! test -x $PWD/upx.out; then exit 1; fi exit_code=0 sha256sum=sha256sum -if test "$TRAVIS_OS_NAME" = "osx"; then +if [[ $TRAVIS_OS_NAME == osx ]]; then sha256sum=gsha256sum # brew install coreutils fi -upx="$PWD/upx.out" -case $BUILD_METHOD in - valgrind | valgrind+* | *+valgrind | *+valgrind+*) - upx="valgrind --leak-check=full --show-reachable=yes $upx" ;; +upx=$PWD/upx.out +case $BUILD_METHOD in valgrind | valgrind+* | *+valgrind | *+valgrind+*) + upx="valgrind --leak-check=full --show-reachable=yes $upx" ;; esac -upx_391=false -if test "$TRAVIS_OS_NAME" = "linux"; then - cp "$TRAVIS_BUILD_DIR/deps/upx-testsuite/files/packed/amd64-linux.elf/upx-3.91" upx391.out - upx_391="$PWD/upx391.out" +upx_391= +if [[ $TRAVIS_OS_NAME == linux ]]; then + rm -f upx391.out + cp $upx_testsuite_SRCDIR/files/packed/amd64-linux.elf/upx-3.91 upx391.out + upx_391="$PWD/upx391.out --fake-stub-version=3.92 --fake-stub-year=2016" fi +case $BUILD_METHOD in coverage | coverage+* | *+coverage | *+coverage+*) + lcov -d $upx_BUILDDIR --zerocounters ;; +esac + $upx --version $upx --help -cd /; cd "$TRAVIS_BUILD_DIR/deps/upx-testsuite/files" || exit 1 +cd $upx_testsuite_SRCDIR/files || exit 1 ls -l packed/*/upx-3.91* $upx -l packed/*/upx-3.91* $upx --file-info packed/*/upx-3.91* $upx -t packed/*/upx-3.91* -for f in packed/*/upx-3.91*; do +cd $upx_testsuite_BUILDDIR || exit 1 +rm -rf ./t +for f in $upx_testsuite_SRCDIR/files/packed/*/upx-3.91*; do echo "===== $f" - if test "$TRAVIS_OS_NAME" = "linux"; then - $upx_391 -d $f -o v391.tmp - $upx -d $f -o v392.tmp - $sha256sum v391.tmp v392.tmp - cmp -s v391.tmp v392.tmp - $upx_391 --lzma --fake-stub-version=3.92 --fake-stub-year=2016 v391.tmp -o v391_packed.tmp - $upx --lzma v392.tmp -o v392_packed.tmp - $sha256sum v391_packed.tmp v392_packed.tmp + mkdir -p ./t + if [[ -n $upx_391 ]]; then + $upx_391 -d $f -o t/v391 + $upx -d $f -o t/v392 + $sha256sum t/v391 t/v392 + cmp -s t/v391 t/v392 + $upx_391 --lzma t/v391 -o t/v391_packed + $upx --lzma t/v392 -o t/v392_packed + $sha256sum t/v391_packed t/v392_packed else - $upx -d $f -o v392.tmp - $sha256sum v392.tmp - $upx --lzma v392.tmp -o v392_packed.tmp - $sha256sum v392_packed.tmp + $upx -d $f -o t/v392 + $sha256sum t/v392 + $upx --lzma t/v392 -o t/v392_packed + $sha256sum t/v392_packed fi - $upx -d v392_packed.tmp -o v392_decompressed.tmp + $upx -d t/v392_packed -o t/v392_decompressed # after the first compression+decompression step the exe should be # canonicalized so that further compression+decompression runs # should yield identical results - if ! cmp -s v392.tmp v392_decompressed.tmp; then + if ! cmp -s t/v392 t/v392_decompressed; then # UPX 3.91 and 3.92 differ; run one more compression+decompression - ls -l v392.tmp v392_decompressed.tmp + ls -l t/v392 t/v392_decompressed echo "UPX-WARNING: $f" - $upx v392_decompressed.tmp -o v392_packed_2.tmp - $upx -d v392_packed_2.tmp -o v392_decompressed_2.tmp - if ! cmp -s v392_decompressed.tmp v392_decompressed_2.tmp; then - ls -l v392_decompressed.tmp v392_decompressed_2.tmp + $upx t/v392_decompressed -o t/v392_packed_2 + $upx -d t/v392_packed_2 -o t/v392_decompressed_2 + if ! cmp -s t/v392_decompressed t/v392_decompressed_2; then + ls -l t/v392_decompressed t/v392_decompressed_2 echo "UPX-ERROR: $f" exit_code=1 fi fi - rm *.tmp + # + u391=$upx_391 + [[ -z $u391 ]] && u391=true + x=t/v392 + $u391 --lzma -2 $x -o t/x_v391_lzma2 + $upx --lzma -2 $x -o t/x_v392_lzma2 + $u391 --lzma -2 --small $x -o t/x_v391_lzma2_small + $upx --lzma -2 --small $x -o t/x_v392_lzma2_small + $u391 --lzma -2 --all-filters $x -o t/x_v391_lzma2_small_all_filters + $upx --lzma -2 --all-filters $x -o t/x_v392_lzma2_small_all_filters + ls -l t/x_v* + $upx -t t/x_v* + $sha256sum t/x_v* + # + rm -rf ./t done +case $BUILD_METHOD in coverage | coverage+* | *+coverage | *+coverage+*) + if [[ -n $TRAVIS_JOB_ID ]]; then + cd $upx_SRCDIR || exit 1 + coveralls -b $upx_BUILDDIR --gcov-options '\-lp' || true + else + cd $upx_BUILDDIR || exit 1 + mkdir -p $lcov_OUTPUTDIR + lcov -d . --capture -o $lcov_OUTPUTDIR/upx.info + cd $lcov_OUTPUTDIR || exit 1 + genhtml upx.info + fi + ;; +esac + exit $exit_code diff --git a/.gitignore b/.gitignore index 2ba7c78b..81bf8c04 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ /maint* .depend +GNUmakefile +MMakefile Makevars.local* *.a @@ -21,8 +23,6 @@ doc/*.man doc/*.ps doc/*.tex -src/GNUmakefile -src/MMakefile src/compress_nrv* src/*.mft src/*.rc diff --git a/.travis.yml b/.travis.yml index 79dd523c..03a868b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,9 @@ sudo: false language: cpp notifications: - email: false + email: + on_success: never + on_failure: change branches: only: @@ -45,6 +47,10 @@ matrix: - os: linux compiler: gcc env: C=gcc-4.6-m64 + - os: linux + compiler: gcc + env: C=gcc-4.6-m64 B=coverage + addons: { apt: { packages: [ lcov ] } } - os: linux compiler: gcc env: C=gcc-5-m32 @@ -80,7 +86,7 @@ matrix: - os: linux compiler: gcc env: C=gcc-6-m64 B=valgrind - addons: { apt: { sources: *S, packages: [ "g++-6", "valgrind" ] } } + addons: { apt: { sources: *S, packages: [ "g++-6", valgrind ] } } - os: linux compiler: clang env: C=clang-3.4-m32 @@ -164,16 +170,26 @@ matrix: osx_image: xcode8 install: - - umask 022; DEPS_DIR="$TRAVIS_BUILD_DIR/deps"; mkdir -p "$DEPS_DIR" && cd "$DEPS_DIR" - - travis_retry wget --no-check-certificate -q -O - https://download.freenas.org/distfiles/ucl-1.03.tar.gz | tar -xz - - travis_retry git clone https://github.com/upx/upx-testsuite + - umask 022; cd $TRAVIS_BUILD_DIR && mkdir -p ../deps + - cd ../deps && travis_retry wget --no-check-certificate -q -O - https://download.freenas.org/distfiles/ucl-1.03.tar.gz | tar -xz + - cd ../deps && travis_retry git clone https://github.com/upx/upx-testsuite - | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + cd / + if [[ $TRAVIS_OS_NAME == linux ]]; then + case $B in coverage | coverage+* | *+coverage | *+coverage+*) + travis_retry pip install --user cpp-coveralls ;; + esac + fi + if [[ $TRAVIS_OS_NAME == osx ]]; then if ! gsha256sum /dev/null 2>/dev/null; then travis_retry brew install coreutils; fi + case $B in coverage | coverage+* | *+coverage | *+coverage+*) + travis_retry brew install lcov + travis_retry pip install --user cpp-coveralls ;; + esac fi script: - - bash $TRAVIS_BUILD_DIR/.github/travis_build.sh - - bash $TRAVIS_BUILD_DIR/.github/travis_testsuite.sh + - cd $TRAVIS_BUILD_DIR && bash ./.github/travis_build.sh + - cd $TRAVIS_BUILD_DIR && bash ./.github/travis_testsuite.sh # vim:set ts=2 sw=2 et: diff --git a/src/Makefile b/src/Makefile index d4577c51..69a9f919 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,7 @@ endif .SUFFIXES: export SHELL = /bin/sh -override e = $($1) $(EXTRA_$1) $(upx_$1) $($(basename $(notdir $@)).$1) +override e = $($1) $(EXTRA_$1) $(upx_$1) $(upx_EXTRA_$1) $($(basename $(notdir $@)).$1) ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.77 3.78 3.78.1 3.79 3.79.1 3.80),) $(error GNU make 3.81 or better is required) @@ -69,7 +69,6 @@ ifdef USE_DEBUG CXXFLAGS += -O0 -g else CXXFLAGS += -O2 -LDFLAGS += -s endif # protect against security threats caused by misguided C++ compiler "optimizations" ifeq ($(findstring clang,$(CXX)),)