Skip to content

Commit

Permalink
fix compilation for MacOS 11 and Ubuntu 18
Browse files Browse the repository at this point in the history
resolved class-memaccess and unused-but-set-variable warnings
improved -pthread and -maes usage
fixed old libcurl compatibility
  • Loading branch information
dynexcoin committed Apr 2, 2024
1 parent 8e9f077 commit 96de334
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 37 deletions.
35 changes: 9 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CONFIGURATION_TYPES "Release;Debug;RelWithDebInfo" CACHE TYPE INTERNAL FORCE)
set(CMAKE_CONFIGURATION_TYPES "Release;Debug;RelWithDebInfo" CACHE STRING INTERNAL FORCE)
set(CMAKE_SKIP_INSTALL_RULES ON)
set(CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY ON)
set(CMAKE_SUPPRESS_REGENERATION ON)
Expand All @@ -20,15 +20,8 @@ else()
set(ARM64 OFF)
endif()

#if(WIN32)
# option(CMAKE_USE_WIN32_THREADS_INIT "using WIN32 threads" ON)
#else(UNIX)
# set(CMAKE_THREAD_LIBS_INIT "-lpthread")
# set(CMAKE_HAVE_THREADS_LIBRARY 1)
# set(CMAKE_USE_WIN32_THREADS_INIT 0)
# set(CMAKE_USE_PTHREADS_INIT 1)
# set(THREADS_PREFER_PTHREAD_FLAG ON)
#endif()
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

if(MSVC)
include_directories(src/Platform/Windows)
Expand Down Expand Up @@ -68,7 +61,7 @@ else()
else()
set(ARCH_FLAG "-march=${ARCH}")
endif()
set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-error=undef -Wno-unused-parameter -Wno-undef -Wno-unused-const-variable -Wno-unused-variable -Wno-unused-but-set-variable -Wno-write-strings -Wno-unused-function ")
set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-error=undef -Wno-unused-parameter -Wno-undef -Wno-unused-const-variable -Wno-unused-variable -Wno-write-strings -Wno-unused-function ")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(WARNINGS "${WARNINGS} -Wno-error=mismatched-tags -Wno-error=null-conversion -Wno-overloaded-shift-op-parentheses -Wno-error=shift-count-overflow -Wno-error=tautological-constant-out-of-range-compare -Wno-error=unneeded-internal-declaration -Wno-unused-private-field")
else()
Expand All @@ -88,25 +81,15 @@ else()
set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c17 ${MINGW_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 ${MINGW_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG}")

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_HAS_TR1_TUPLE=0")

CHECK_CXX_COMPILER_FLAG("-Werror -Wclass-memaccess" CLASS_MEMACCESS)
if(CLASS_MEMACCESS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess")
if(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
endif()

CHECK_CXX_COMPILER_FLAG("-Werror -maes" MAES)
if (MAES)
if(NOT ARM64)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes")
endif()

CHECK_CXX_COMPILER_FLAG("-Werror -pthread" PTHREAD)
if (PTHREAD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_HAS_TR1_TUPLE=0")

if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8))
set(DEBUG_FLAGS "-g3 -Og")
Expand Down
2 changes: 2 additions & 0 deletions src/DynexCNCore/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ bool AuthBlock(uint32_t height, uint32_t nonce, ILogger& log) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);

curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
#ifdef CURLOPT_MAXAGE_CONN
curl_easy_setopt(curl, CURLOPT_MAXAGE_CONN, 1800L);
#endif
curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 60L);
curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L);

Expand Down
4 changes: 2 additions & 2 deletions src/DynexCNCore/Currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,8 @@ bool Currency::checkProofOfWorkV2(Crypto::cn_context& context, const Block& bloc
bool r = Crypto::generate_key_derivation(targets[i].viewPublicKey, txkey.secretKey, derivation);
assert(r == true);
// CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << targets[i].viewPublicKey << ", " << txkey.sec << ")");
r = Crypto::derive_public_key(derivation, i, targets[i].spendPublicKey, outEphemeralPubKey);
assert(r == true);
bool r2 = Crypto::derive_public_key(derivation, i, targets[i].spendPublicKey, outEphemeralPubKey);
assert(r2 == true);
// CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to derive_public_key(" << derivation << ", " << i << ", " << targets[i].spendPublicKey << ")");
KeyOutput tk;
tk.key = outEphemeralPubKey;
Expand Down
4 changes: 2 additions & 2 deletions src/Platform/FreeBSD/System/Dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ Dispatcher::~Dispatcher() {

auto result = close(kqueue);
assert(result != -1);
result = pthread_mutex_destroy(reinterpret_cast<pthread_mutex_t*>(this->mutex));
assert(result != -1);
auto result2 = pthread_mutex_destroy(reinterpret_cast<pthread_mutex_t*>(this->mutex));
assert(result2 != -1);
}

void Dispatcher::clear() {
Expand Down
8 changes: 4 additions & 4 deletions src/Platform/Linux/System/Dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ Dispatcher::~Dispatcher() {

auto result = close(epoll);
assert(result == 0);
result = close(remoteSpawnEvent);
assert(result == 0);
result = pthread_mutex_destroy(reinterpret_cast<pthread_mutex_t*>(this->mutex));
assert(result == 0);
auto result2 = close(remoteSpawnEvent);
assert(result2 == 0);
auto result3 = pthread_mutex_destroy(reinterpret_cast<pthread_mutex_t*>(this->mutex));
assert(result3 == 0);
}

void Dispatcher::clear() {
Expand Down
4 changes: 2 additions & 2 deletions src/Platform/OSX/System/Dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ Dispatcher::~Dispatcher() {
}
auto result = close(kqueue);
assert(result != -1);
result = pthread_mutex_destroy(reinterpret_cast<pthread_mutex_t*>(this->mutex));
assert(result != -1);
auto result2 = pthread_mutex_destroy(reinterpret_cast<pthread_mutex_t*>(this->mutex));
assert(result2 != -1);
}

void Dispatcher::clear() {
Expand Down
7 changes: 6 additions & 1 deletion src/crypto/chacha8.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ namespace Crypto {
}

inline void generate_chacha8_key(Crypto::cn_context &context, const std::string& password, chacha8_key& key) {
/*
static_assert(sizeof(chacha8_key) <= sizeof(Hash), "Size of hash must be at least that of chacha8_key");
Hash pwd_hash;
cn_slow_hash(context, password.data(), password.size(), pwd_hash);
memcpy(&key, &pwd_hash, sizeof(key));
memset(&pwd_hash, 0, sizeof(pwd_hash));
memset(&pwd_hash, 0, sizeof(pwd_hash)); // better use memset_s
*/
static_assert(sizeof(chacha8_key) == sizeof(Hash), "Size of hash must be equal to chacha8_key");
// write directly
cn_slow_hash(password.data(), password.size(), reinterpret_cast<char*>(&key.data));
}
}

Expand Down

0 comments on commit 96de334

Please sign in to comment.