From 42d49e9d50482941e5c547a9f497c90d2229e705 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Mon, 3 Oct 2016 13:13:13 +0200 Subject: [PATCH] Update Makefile and check_whitespace.sh. --- .appveyor.yml | 2 +- src/Makefile | 30 ++++++++++-------------- src/conf.h | 5 ++++ src/s_win32.cpp | 4 ++-- src/stub/scripts/check_whitespace.sh | 5 ++-- src/stub/scripts/check_whitespace_git.sh | 13 ++++++---- 6 files changed, 32 insertions(+), 27 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index a698ed2f..7735f800 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -81,7 +81,7 @@ build_script: - set s=c:\projects\upx\src - cat .GITREV.txt - set /p GITREV=<.GITREV.txt - - cl -MT -EHsc -O2 -W4 -wd4244 -DUPX_VERSION_GITREV="""%GITREV%""" %DEFS% -DWITH_LZMA=0x443 -DUCL_NO_ASM -I%s%\lzma-sdk -Ic:\projects\deps\ucl-1.03\include -Ic:\projects\deps\zlib-1.2.8 -Feupx.exe %s%\*.cpp %BDIR%\ucl-1.03\ucl.lib %BDIR%\zlib-1.2.8\zlib.lib + - cl -MT -EHsc -J -O2 -W4 -DUPX_VERSION_GITREV="""%GITREV%""" %DEFS% -DWITH_LZMA=0x443 -DUCL_NO_ASM -I%s%\lzma-sdk -Ic:\projects\deps\ucl-1.03\include -Ic:\projects\deps\zlib-1.2.8 -Feupx.exe %s%\*.cpp %BDIR%\ucl-1.03\ucl.lib %BDIR%\zlib-1.2.8\zlib.lib test_script: - set UPX=--no-color --no-progress diff --git a/src/Makefile b/src/Makefile index 2f094995..ca63c35c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -10,15 +10,6 @@ BUILD_TYPE_SANITIZE ?= 0 BUILD_USE_DEPEND ?= 1 MAKEFLAGS += -r -ifneq ($(upx_CXX),) -CXX = $(upx_CXX) -endif -ifneq ($(upx_CXXLD),) -CXXLD = $(upx_CXXLD) -else -CXXLD = $(CXX) -endif - .SUFFIXES: export SHELL = /bin/sh override e = $($1) $(EXTRA_$1) $(upx_$1) $(upx_EXTRA_$1) $($(basename $(notdir $@)).$1) @@ -36,6 +27,9 @@ ifneq ($(srcdir),.) VPATH := . $(srcdir) endif +# toolchain +CXX ?= g++ +CXXLD = $(CXX) exeext ?= .out libext ?= .a objext ?= .o @@ -46,8 +40,8 @@ upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext))) ifneq ($(wildcard $(top_srcdir)/.git/.),) UPX_VERSION_GITREV := $(strip $(shell cd '$(top_srcdir)' && git rev-parse --short=12 HEAD || echo 'ERROR')) ifneq ($(UPX_VERSION_GITREV),) -x := $(strip $(shell cd '$(top_srcdir)' && git diff --exit-code HEAD >/dev/null && echo '' || echo '+')) -DEFS += '-DUPX_VERSION_GITREV="$(UPX_VERSION_GITREV)$(x)"' +GITREV_PLUS := $(strip $(shell cd '$(top_srcdir)' && git diff --exit-code HEAD >/dev/null && echo '' || echo '+')) +DEFS += '-DUPX_VERSION_GITREV="$(UPX_VERSION_GITREV)$(GITREV_PLUS)"' endif endif @@ -63,10 +57,11 @@ DEFS += -DWITH_LZMA=$(UPX_LZMA_VERSION) CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) ifeq ($(BUILD_TYPE_DEBUG),1) -CXXFLAGS += -O0 -g +CXXFLAGS_OPTIMIZE ?= -O0 -g else -CXXFLAGS += -O2 +CXXFLAGS_OPTIMIZE ?= -O2 endif +CXXFLAGS += $(CXXFLAGS_OPTIMIZE) # protect against security threats caused by misguided C++ compiler "optimizations" ifeq ($(findstring clang,$(CXX)),) CXXFLAGS += -fno-delete-null-pointer-checks @@ -78,14 +73,14 @@ CXXFLAGS_WERROR ?= -Werror CXXFLAGS += $(CXXFLAGS_WERROR) ifeq ($(BUILD_TYPE_SANITIZE),1) -CXXFLAGS_SANITIZE := -fsanitize=address,undefined -fno-omit-frame-pointer -DACC_CFG_NO_UNALIGNED +CXXFLAGS_SANITIZE ?= -fsanitize=address,undefined -fno-omit-frame-pointer -DACC_CFG_NO_UNALIGNED CXXFLAGS += $(CXXFLAGS_SANITIZE) LDFLAGS += $(CXXFLAGS_SANITIZE) # these are the only 2 objects that are actually speed-sensitive -compress_lzma$(objext) filteri$(objext) : CXXFLAGS := $(filter-out $(CXXFLAGS_SANITIZE),$(CXXFLAGS)) +compress_lzma$(objext) filteri$(objext) : CXXFLAGS_SANITIZE = endif - +# rules all: upx$(exeext) | ./.depend .DELETE_ON_ERROR: upx$(exeext) $(upx_OBJECTS) ./.depend @@ -97,7 +92,7 @@ upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES) %.o : %.cpp | ./.depend $(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<) -%.cpp.ii : %.cpp | ./.depend +%.cpp.ii : %.cpp $(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -E $<) ifeq ($(BUILD_USE_DEPEND),1) @@ -137,6 +132,7 @@ else ifeq ($(MAKECMDGOALS),clean) else ifeq ($(MAKECMDGOALS),distclean) else ifeq ($(MAKECMDGOALS),maintainer-clean) else ifeq ($(MAKECMDGOALS),clang-format) +else ifeq ($(MAKECMDGOALS),check-whitespace) else ifeq ($(BUILD_USE_DEPEND),1) -include ./.depend diff --git a/src/conf.h b/src/conf.h index d9f36e70..c5f82113 100644 --- a/src/conf.h +++ b/src/conf.h @@ -48,9 +48,14 @@ // other compilers may work, but we're NOT interested into supporting them # error "only clang and gcc are officially supported" #endif +// UPX sanity checks for a sane compiler #if !defined(UINT_MAX) || (UINT_MAX != 0xffffffffL) # error "UINT_MAX" #endif +ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4) +ACC_COMPILE_TIME_ASSERT_HEADER((1u << 31) << 1 == 0) +ACC_COMPILE_TIME_ASSERT_HEADER(((int)(1u << 31)) >> 31 == -1) // arithmetic right shift +ACC_COMPILE_TIME_ASSERT_HEADER((char)(-1) > 0) // -funsigned-char // FIXME - quick hack for arm-wince-gcc-3.4 (Debian pocketpc-*.deb packages) #if 1 && (ACC_ARCH_ARM) && defined(__pe__) && !defined(__CEGCC__) && !defined(_WIN32) diff --git a/src/s_win32.cpp b/src/s_win32.cpp index 09997ca9..de538521 100644 --- a/src/s_win32.cpp +++ b/src/s_win32.cpp @@ -42,9 +42,9 @@ #if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200)) /* avoid -W4 warnings in */ -#pragma warning(disable: 4032) +#pragma warning(disable : 4032) /* avoid -W4 warnings in */ -#pragma warning(disable: 4201 4214 4514) +#pragma warning(disable : 4201 4214 4514) #endif #if defined(__RSXNT__) #define timeval win32_timeval /* struct timeval already in */ diff --git a/src/stub/scripts/check_whitespace.sh b/src/stub/scripts/check_whitespace.sh index 051ec689..c10fcda7 100755 --- a/src/stub/scripts/check_whitespace.sh +++ b/src/stub/scripts/check_whitespace.sh @@ -15,9 +15,10 @@ find . \ -type f -iname '*.exe' -prune -o \ -type f -iname '*.pdf' -prune -o \ -type f -iname '*.swp' -prune -o \ - -type f -print0 | LC_ALL=C sort -z | \ -xargs -0r perl -n -e ' + -type f -print0 | \ +LC_ALL=C sort -z | xargs -0r perl -n -e ' #print("$ARGV\n"); + if (m,[\x00\x01\x02\xfe\xff],) { print "ERROR: binary file detected $ARGV: $_"; exit(1); } 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 diff --git a/src/stub/scripts/check_whitespace_git.sh b/src/stub/scripts/check_whitespace_git.sh index c04db8c2..7caed2c3 100755 --- a/src/stub/scripts/check_whitespace_git.sh +++ b/src/stub/scripts/check_whitespace_git.sh @@ -7,12 +7,15 @@ set -e; set -o pipefail [[ -z $1 ]] || cd "$1" || exit 1 [[ -d .git ]] || exit 1 -# info: cannot use "-z" as that needs GNU sed 4.2.2 which is not installed on Ubuntu 12.04 -git ls-files --full-name | sed 's/^/\.\//' |\ -sed -e '/lzma-sdk$/d' -e '/\.exe$/d' |\ -LC_ALL=C sort | \ -xargs -r perl -n -e ' +git ls-files --full-name -z | perl -0 -n -e ' + s,^,./,; + if (m,^\./src/lzma-sdk(\0|$),) { } + elsif (m,\.bat(\0|$),) { } + elsif (m,\.exe(\0|$),) { } + else { print; } +' | LC_ALL=C sort -z | xargs -0r perl -n -e ' #print("$ARGV\n"); + if (m,[\x00\x01\x02\xfe\xff],) { print "ERROR: binary file detected $ARGV: $_"; exit(1); } 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