From 526aafc64b87a74a7cbdd95ebe91aa329805dec4 Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Thu, 22 Jan 2015 22:11:40 +0100 Subject: [PATCH 1/7] move definition of ZT_SALSA20_SSE into Salsa20.cpp --- make-freebsd.mk | 21 --------------------- make-linux.mk | 21 --------------------- make-mac.mk | 3 --- node/Salsa20.hpp | 5 +++++ windows/ZeroTierOne/ZeroTierOne.vcxproj | 4 ++-- 5 files changed, 7 insertions(+), 47 deletions(-) diff --git a/make-freebsd.mk b/make-freebsd.mk index 69f094abb..2eea8eafb 100644 --- a/make-freebsd.mk +++ b/make-freebsd.mk @@ -9,27 +9,6 @@ include objects.mk OBJS+=osnet/BSDEthernetTapFactory.o osnet/BSDEthernetTap.o osnet/BSDRoutingTable.o TESTNET_OBJS=testnet/SimNet.o testnet/SimNetSocketManager.o testnet/TestEthernetTap.o testnet/TestEthernetTapFactory.o testnet/TestRoutingTable.o -# Enable SSE-optimized Salsa20 on x86 and x86_64 machines -MACHINE=$(shell uname -m) -ifeq ($(MACHINE),x86_64) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),amd64) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),i686) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),i586) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),i386) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),x86) - DEFS+=-DZT_SALSA20_SSE -endif - # "make official" is a shortcut for this ifeq ($(ZT_OFFICIAL_RELEASE),1) ZT_AUTO_UPDATE=1 diff --git a/make-linux.mk b/make-linux.mk index 2033e35ce..e0951711a 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -10,27 +10,6 @@ include objects.mk OBJS+=osnet/LinuxRoutingTable.o osnet/LinuxEthernetTap.o osnet/LinuxEthernetTapFactory.o TESTNET_OBJS=testnet/SimNet.o testnet/SimNetSocketManager.o testnet/TestEthernetTap.o testnet/TestEthernetTapFactory.o testnet/TestRoutingTable.o -# Enable SSE-optimized Salsa20 on x86 and x86_64 machines -MACHINE=$(shell uname -m) -ifeq ($(MACHINE),x86_64) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),amd64) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),i686) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),i586) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),i386) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),x86) - DEFS+=-DZT_SALSA20_SSE -endif - # "make official" is a shortcut for this ifeq ($(ZT_OFFICIAL_RELEASE),1) ZT_AUTO_UPDATE=1 diff --git a/make-mac.mk b/make-mac.mk index 26ca8fe0b..854990bb9 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -25,9 +25,6 @@ ifeq ($(ZT_AUTO_UPDATE),1) DEFS+=-DZT_AUTO_UPDATE endif -# Enable SSE-optimized Salsa20 -- all Intel macs support SSE2 -DEFS+=-DZT_SALSA20_SSE - ifeq ($(ZT_DEBUG),1) # DEFS+=-DZT_TRACE -DZT_LOG_STDOUT CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) diff --git a/node/Salsa20.hpp b/node/Salsa20.hpp index 0c1f3be46..6f51a160b 100644 --- a/node/Salsa20.hpp +++ b/node/Salsa20.hpp @@ -11,6 +11,11 @@ #include "Constants.hpp" +/* Enable SSE-optimized Salsa20 on SSE2 machines */ +#ifdef __SSE2__ +#define ZT_SALSA20_SSE +#endif + #ifdef ZT_SALSA20_SSE #include #endif // ZT_SALSA20_SSE diff --git a/windows/ZeroTierOne/ZeroTierOne.vcxproj b/windows/ZeroTierOne/ZeroTierOne.vcxproj index a651b5f73..49392b54d 100644 --- a/windows/ZeroTierOne/ZeroTierOne.vcxproj +++ b/windows/ZeroTierOne/ZeroTierOne.vcxproj @@ -270,7 +270,7 @@ true true $(SolutionDir)\ext\bin\libcrypto\include - ZT_OFFICIAL_RELEASE;ZT_AUTO_UPDATE;ZT_SALSA20_SSE;%(PreprocessorDefinitions) + ZT_OFFICIAL_RELEASE;ZT_AUTO_UPDATE;%(PreprocessorDefinitions) MultiThreaded NoExtensions true @@ -294,7 +294,7 @@ true true $(SolutionDir)\ext\bin\libcrypto\include - ZT_OFFICIAL_RELEASE;ZT_AUTO_UPDATE;ZT_SALSA20_SSE;%(PreprocessorDefinitions) + ZT_OFFICIAL_RELEASE;ZT_AUTO_UPDATE;%(PreprocessorDefinitions) MultiThreaded NotSet true From 3abbe613661cfb917540788fb96870efa2b3c4ca Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Thu, 22 Jan 2015 22:24:39 +0100 Subject: [PATCH 2/7] allow use of environment variables to set/extend CC, CXX, CFLAGS and LDFLAGS --- make-freebsd.mk | 15 ++++++++------- make-linux.mk | 15 ++++++++------- make-mac.mk | 11 ++++++----- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/make-freebsd.mk b/make-freebsd.mk index 2eea8eafb..e57859e4c 100644 --- a/make-freebsd.mk +++ b/make-freebsd.mk @@ -1,5 +1,5 @@ -CC=cc -CXX=c++ +CC?=cc +CXX?=c++ INCLUDES= DEFS= @@ -21,15 +21,16 @@ endif # "make debug" is a shortcut for this ifeq ($(ZT_DEBUG),1) # DEFS+=-DZT_TRACE -DZT_LOG_STDOUT - CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) - LDFLAGS= + CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) + LDFLAGS+= STRIP=echo # The following line enables optimization for the crypto code, since # C25519 in particular is almost UNUSABLE in heavy testing without it. -ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) +ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) else - CFLAGS=-Wall -O3 -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) - LDFLAGS=-pie -Wl,-z,relro,-z,now + CFLAGS?=-O3 + CFLAGS+=-Wall -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) + LDFLAGS+=-pie -Wl,-z,relro,-z,now STRIP=strip --strip-all endif diff --git a/make-linux.mk b/make-linux.mk index e0951711a..58a38dbde 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -1,6 +1,6 @@ # Pick clang or gcc, with preference for clang -CC=$(shell which clang gcc cc 2>/dev/null | head -n 1) -CXX=$(shell which clang++ g++ c++ 2>/dev/null | head -n 1) +CC?=$(shell which clang gcc cc 2>/dev/null | head -n 1) +CXX?=$(shell which clang++ g++ c++ 2>/dev/null | head -n 1) INCLUDES= DEFS= @@ -22,15 +22,16 @@ endif # "make debug" is a shortcut for this ifeq ($(ZT_DEBUG),1) # DEFS+=-DZT_TRACE -DZT_LOG_STDOUT - CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) - LDFLAGS= + CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) + LDFLAGS+= STRIP=echo # The following line enables optimization for the crypto code, since # C25519 in particular is almost UNUSABLE in heavy testing without it. -ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) +ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) else - CFLAGS=-Wall -O3 -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) - LDFLAGS=-pie -Wl,-z,relro,-z,now + CFLAGS?=-O3 + CFLAGS+=-Wall -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) + LDFLAGS+=-pie -Wl,-z,relro,-z,now -static-libstdc++ STRIP=strip --strip-all endif diff --git a/make-mac.mk b/make-mac.mk index 854990bb9..d6adec426 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -1,5 +1,5 @@ -CC=clang -CXX=clang++ +CC?=clang +CXX?=clang++ INCLUDES= DEFS= @@ -27,13 +27,14 @@ endif ifeq ($(ZT_DEBUG),1) # DEFS+=-DZT_TRACE -DZT_LOG_STDOUT - CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) + CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) STRIP=echo # The following line enables optimization for the crypto code, since # C25519 in particular is almost UNUSABLE in heavy testing without it. -ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) +ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) else - CFLAGS=-arch i386 -arch x86_64 -Wall -O3 -flto -fPIE -fvectorize -fstack-protector -pthread -mmacosx-version-min=10.6 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS) + CFLAGS?=-O3 + CFLAGS+=-arch i386 -arch x86_64 -Wall -flto -fPIE -fvectorize -fstack-protector -pthread -mmacosx-version-min=10.6 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS) STRIP=strip endif From a66bd4137f4ace5b79e3065c12f4d2f2d2e26c86 Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Fri, 23 Jan 2015 13:11:04 +0100 Subject: [PATCH 3/7] there is a space expected behind the arguments --- main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 438144c62..c18f726a6 100644 --- a/main.cpp +++ b/main.cpp @@ -573,8 +573,8 @@ static void printHelp(const char *cn,FILE *out) fprintf(out,"Available switches:"ZT_EOL_S); fprintf(out," -h - Display this help"ZT_EOL_S); fprintf(out," -v - Show version"ZT_EOL_S); - fprintf(out," -p - Port for UDP (default: 9993)"ZT_EOL_S); - fprintf(out," -t - Port for TCP (default: disabled)"ZT_EOL_S); + fprintf(out," -p - Port for UDP (default: 9993)"ZT_EOL_S); + fprintf(out," -t - Port for TCP (default: disabled)"ZT_EOL_S); //fprintf(out," -T - Override root topology, do not authenticate or update"ZT_EOL_S); #ifdef __UNIX_LIKE__ fprintf(out," -d - Fork and run as daemon (Unix-ish OSes)"ZT_EOL_S); From 4dd243cdc7cc027318309ac6d539e5ec9ac7fa01 Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Fri, 23 Jan 2015 14:05:06 +0100 Subject: [PATCH 4/7] move -fstack-protector to the optional CFLAGS part --- make-freebsd.mk | 4 ++-- make-linux.mk | 6 +++--- make-mac.mk | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/make-freebsd.mk b/make-freebsd.mk index e57859e4c..2a62c9f3d 100644 --- a/make-freebsd.mk +++ b/make-freebsd.mk @@ -28,8 +28,8 @@ ifeq ($(ZT_DEBUG),1) # C25519 in particular is almost UNUSABLE in heavy testing without it. ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) else - CFLAGS?=-O3 - CFLAGS+=-Wall -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) + CFLAGS?=-O3 -fstack-protector + CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS) LDFLAGS+=-pie -Wl,-z,relro,-z,now STRIP=strip --strip-all endif diff --git a/make-linux.mk b/make-linux.mk index 58a38dbde..949fc16d4 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -29,9 +29,9 @@ ifeq ($(ZT_DEBUG),1) # C25519 in particular is almost UNUSABLE in heavy testing without it. ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) else - CFLAGS?=-O3 - CFLAGS+=-Wall -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) - LDFLAGS+=-pie -Wl,-z,relro,-z,now -static-libstdc++ + CFLAGS?=-O3 -fstack-protector + CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS) + LDFLAGS+=-pie -Wl,-z,relro,-z,now STRIP=strip --strip-all endif diff --git a/make-mac.mk b/make-mac.mk index d6adec426..8ea8b48c7 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -33,8 +33,8 @@ ifeq ($(ZT_DEBUG),1) # C25519 in particular is almost UNUSABLE in heavy testing without it. ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) else - CFLAGS?=-O3 - CFLAGS+=-arch i386 -arch x86_64 -Wall -flto -fPIE -fvectorize -fstack-protector -pthread -mmacosx-version-min=10.6 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS) + CFLAGS?=-O3 -fstack-protector + CFLAGS+=-arch i386 -arch x86_64 -Wall -flto -fPIE -fvectorize -pthread -mmacosx-version-min=10.6 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS) STRIP=strip endif From 1b6414a3cc0bc5dc041445753f6d2a715715b30e Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Fri, 6 Feb 2015 17:23:40 +0100 Subject: [PATCH 5/7] drop namespace from std::size_t and std::ptrdiff_t the C and C++ definitions identical, but they might not be defined in std for some alternative stdc++ libraries --- control/NodeControlClient.cpp | 2 ++ node/Array.hpp | 22 ++++++++++++---------- node/InetAddress.cpp | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/control/NodeControlClient.cpp b/control/NodeControlClient.cpp index 6fd7b12ed..e5ea2c20e 100644 --- a/control/NodeControlClient.cpp +++ b/control/NodeControlClient.cpp @@ -33,6 +33,8 @@ #include "IpcListener.hpp" #include "NodeControlService.hpp" +#include "stddef.h" + #ifdef __WINDOWS__ #include #include diff --git a/node/Array.hpp b/node/Array.hpp index ce179c16c..a1779909a 100644 --- a/node/Array.hpp +++ b/node/Array.hpp @@ -31,12 +31,14 @@ #include #include +#include "stddef.h" + namespace ZeroTier { /** * Static array -- a simple thing that's belonged in STL since the time of the dinosaurs */ -template +template class Array { public: @@ -44,19 +46,19 @@ public: Array(const Array &a) { - for(std::size_t i=0;i reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; @@ -83,11 +85,11 @@ public: inline const_reverse_iterator rbegin() const throw() { return const_reverse_iterator(begin()); } inline const_reverse_iterator rend() const throw() { return const_reverse_iterator(end()); } - inline std::size_t size() const throw() { return S; } - inline std::size_t max_size() const throw() { return S; } + inline size_t size() const throw() { return S; } + inline size_t max_size() const throw() { return S; } - inline reference operator[](const std::size_t n) throw() { return data[n]; } - inline const_reference operator[](const std::size_t n) const throw() { return data[n]; } + inline reference operator[](const size_t n) throw() { return data[n]; } + inline const_reference operator[](const size_t n) const throw() { return data[n]; } inline reference front() throw() { return data[0]; } inline const_reference front() const throw() { return data[0]; } diff --git a/node/InetAddress.cpp b/node/InetAddress.cpp index 832acf04c..5e36be0d5 100644 --- a/node/InetAddress.cpp +++ b/node/InetAddress.cpp @@ -137,7 +137,7 @@ std::string InetAddress::toString() const void InetAddress::fromString(const std::string &ipSlashPort) { - std::size_t slashAt = ipSlashPort.find('/'); + size_t slashAt = ipSlashPort.find('/'); if ((slashAt == std::string::npos)||(slashAt >= ipSlashPort.length())) set(ipSlashPort,0); else { From daafb659206ec6be223ac347735f68d94b524a67 Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Fri, 6 Feb 2015 17:38:27 +0100 Subject: [PATCH 6/7] remove unused swap definition in std namepsace it interferes with using libustl --- node/Peer.hpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/node/Peer.hpp b/node/Peer.hpp index 78506fd23..fe5362e3f 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -400,13 +400,4 @@ private: } // namespace ZeroTier -// Add a swap() for shared ptr's to peers to speed up peer sorts -namespace std { - template<> - inline void swap(ZeroTier::SharedPtr &a,ZeroTier::SharedPtr &b) - { - a.swap(b); - } -} - #endif From e30192d0823451473dbec3371e976a30fdc9d547 Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Fri, 6 Feb 2015 17:56:22 +0100 Subject: [PATCH 7/7] allow CXXFLAGS to be set separately --- make-freebsd.mk | 3 ++- make-linux.mk | 3 ++- make-mac.mk | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/make-freebsd.mk b/make-freebsd.mk index 2a62c9f3d..b50efa813 100644 --- a/make-freebsd.mk +++ b/make-freebsd.mk @@ -34,7 +34,8 @@ else STRIP=strip --strip-all endif -CXXFLAGS=$(CFLAGS) -fno-rtti +CXXFLAGS?=-fno-rtti +CXXFLAGS=$(CFLAGS) all: one diff --git a/make-linux.mk b/make-linux.mk index 949fc16d4..9719f36a2 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -40,7 +40,8 @@ endif #LDFLAGS= #STRIP=echo -CXXFLAGS=$(CFLAGS) -fno-rtti +CXXFLAGS?=-fno-rtti +CXXFLAGS+=$(CFLAGS) all: one diff --git a/make-mac.mk b/make-mac.mk index 8ea8b48c7..c9e05c5a4 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -38,7 +38,8 @@ else STRIP=strip endif -CXXFLAGS=$(CFLAGS) -fno-rtti +CXXFLAGS?=-fno-rtti +CXXFLAGS=$(CFLAGS) all: one