Browse Source

Use Win32 approach to TLS for Mac. (#192)

Merge branch 'FixMacVHashV2' of https://github.com/DavidLDawes/VerusCoin into dev
pull/193/head
Asher Dawes 5 years ago
committed by GitHub
parent
commit
4266851b8d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      .gitlab-ci.yml
  2. 4
      depends/hosts/darwin.mk
  3. 2
      depends/hosts/linux.mk
  4. 4
      depends/hosts/mingw32.mk
  5. 11
      depends/packages/libsodium.mk
  6. 12
      src/crypto/verus_clhash.cpp
  7. 8
      src/crypto/verus_clhash.h
  8. 2
      zcutil/build-mac.sh

10
.gitlab-ci.yml

@ -6,7 +6,7 @@ stages:
####START#### PROJECT LEVEL VARIABLES ####START####
########################################################################################################################
variables:
VERSION: 0.5.3
VERSION: 0.5.4
VERUS_CLI_LINUX: Verus-CLI-Linux-v${VERSION}.tar.gz
VERUS_CLI_WINDOWS: Verus-CLI-Windows-v${VERSION}.zip
VERUS_CLI_MACOS: Verus-CLI-MacOS-v${VERSION}.tar.gz
@ -111,7 +111,7 @@ build:windows:
########################################################################################################################
####START#### MACOS ####START####
########################################################################################################################
.build:mac:
build:mac:
stage: build
tags: ["High Sierra"]
cache:
@ -315,16 +315,16 @@ deploy:
dependencies:
- build:linux
- build:windows
#- build:mac
- build:mac
script:
- mkdir Windows && mkdir Linux && mkdir MacOS &&
mv ${VERUS_CLI_WINDOWS} Windows &&
mv ${VERUS_CLI_LINUX} Linux
# mv ${VERUS_CLI_MACOS} MacOS
mv ${VERUS_CLI_MACOS} MacOS
- echo "$AUTH_KEY" > AUTH_KEY.json &&
gcloud auth activate-service-account
--key-file AUTH_KEY.json
- gsutil cp -r Windows Linux $STAGING/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}/ # MacOS
- gsutil cp -r Windows MacOS Linux $STAGING/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}
- curl -X POST
-F token="$CI_JOB_TOKEN"
-F ref="$DOWNSTREAM_AGAMA_BRANCH"

4
depends/hosts/darwin.mk

@ -8,10 +8,10 @@ darwin_CXX=g++-6 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysro
darwin_CFLAGS=-pipe
darwin_CXXFLAGS=$(darwin_CFLAGS)
darwin_release_CFLAGS=-O1
darwin_release_CFLAGS=-O3
darwin_release_CXXFLAGS=$(darwin_release_CFLAGS)
darwin_debug_CFLAGS=-O1
darwin_debug_CFLAGS=-O0
darwin_debug_CXXFLAGS=$(darwin_debug_CFLAGS)
darwin_native_toolchain=native_cctools

2
depends/hosts/linux.mk

@ -1,7 +1,7 @@
linux_CFLAGS=-pipe
linux_CXXFLAGS=$(linux_CFLAGS)
linux_release_CFLAGS=-O1
linux_release_CFLAGS=-O3
linux_release_CXXFLAGS=$(linux_release_CFLAGS)
linux_debug_CFLAGS=-O1

4
depends/hosts/mingw32.mk

@ -3,10 +3,10 @@ mingw32_CXX=x86_64-w64-mingw32-g++-posix
mingw32_CFLAGS=-pipe -std=c11
mingw32_CXXFLAGS=$(mingw32_CFLAGS) -std=c++11
mingw32_release_CFLAGS=-O1
mingw32_release_CFLAGS=-O3
mingw32_release_CXXFLAGS=$(mingw32_release_CFLAGS)
mingw32_debug_CFLAGS=-O1
mingw32_debug_CFLAGS=-01
mingw32_debug_CXXFLAGS=$(mingw32_debug_CFLAGS)
mingw32_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC

11
depends/packages/libsodium.mk

@ -1,3 +1,12 @@
ifeq ($(build_os),darwin)
package=libsodium
$(package)_version=1.0.11
$(package)_download_path=https://supernetorg.bintray.com/misc
$(package)_file_name=libsodium-1.0.11.tar.gz
$(package)_sha256_hash=a14549db3c49f6ae2170cbbf4664bd48ace50681045e8dbea7c8d9fb96f9c765
$(package)_dependencies=
$(package)_config_opts=
else
package=libsodium
$(package)_version=1.0.15
$(package)_download_path=https://download.libsodium.org/libsodium/releases/old
@ -5,7 +14,7 @@ $(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=fb6a9e879a2f674592e4328c5d9f79f082405ee4bb05cb6e679b90afe9e178f4
$(package)_dependencies=
$(package)_config_opts=
endif
define $(package)_preprocess_cmds
cd $($(package)_build_subdir); ./autogen.sh

12
src/crypto/verus_clhash.cpp

@ -32,11 +32,14 @@
#ifdef _WIN32
#define posix_memalign(p, a, s) (((*(p)) = _aligned_malloc((s), (a))), *(p) ?0 :errno)
#endif
#if defined(__APPLE__) || defined(_WIN32)
thread thread_specific_ptr verusclhasher_key;
thread thread_specific_ptr verusclhasher_descr;
#else
thread_local thread_specific_ptr verusclhasher_key;
thread_local thread_specific_ptr verusclhasher_descr;
#ifdef _WIN32
#endif
#if defined(__APPLE__) || defined(_WIN32)
// attempt to workaround horrible mingw/gcc destructor bug on Windows, which passes garbage in the this pointer
// we use the opportunity of control here to clean up all of our tls variables. we could keep a list, but this is a safe,
// functional hack
@ -50,7 +53,8 @@ thread_specific_ptr::~thread_specific_ptr() {
verusclhasher_descr.reset();
}
}
#endif
#endif //defined(__APPLE__) || defined(_WIN32)
int __cpuverusoptimized = 0x80;
// multiply the length and the some key, no modulo
static inline __attribute__((always_inline)) __m128i lazyLengthHash(uint64_t keylength, uint64_t length) {

8
src/crypto/verus_clhash.h

@ -73,9 +73,11 @@ struct thread_specific_ptr {
std::free(ptr);
}
ptr = newptr;
}
void *get() { return ptr; }
#ifdef _WIN32 // horrible MingW and gcc thread local storage bug workaround
#if defined(__APPLE__) || defined(_WIN32)
// horrible MingW and Mac with gcc thread local storage bug workaround
~thread_specific_ptr();
#else
~thread_specific_ptr() {
@ -167,7 +169,7 @@ struct verusclhasher {
verusclhasher(uint64_t keysize=VERUSKEYSIZE) : keySizeInBytes((keysize >> 5) << 5)
{
#ifdef __APPLE__
__tls_init();
__tls_init();
#endif
if (IsCPUVerusOptimized())
{
@ -186,7 +188,7 @@ struct verusclhasher {
}
// get buffer space for mutating and refresh keys
void *key = NULL;
if (!(key = verusclhasher_key.get()) &&
if (!(key = verusclhasher_key.get()) &&
(verusclhasher_key.reset((unsigned char *)alloc_aligned_buffer(keySizeInBytes << 1)), key = verusclhasher_key.get()))
{
verusclhash_descr *pdesc;

2
zcutil/build-mac.sh

@ -44,7 +44,7 @@ make "$@" -C ./depends/ V=1 NO_QT=1 NO_PROTON=1
./autogen.sh
CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie -g" \
CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc@6/6.5.0/include/c++/6.5.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \
CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@6/6.5.0/include/c++/6.5.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \
./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG"
make "$@" V=1 NO_GTEST=1 STATIC=1

Loading…
Cancel
Save