From 224267f13d1e4863aa928e4686c4dc28caf176d4 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Wed, 2 Sep 2020 16:38:13 -0400 Subject: [PATCH] Revert "build: Add support for building with musl and Alpine Linux" --- depends/config.guess | 9 +- depends/packages/fontconfig.mk | 22 ++--- ...with-integer-width-macros-from-TS-18.patch | 73 +++++++++++++++ doc/assets-attribution.md | 6 +- doc/build-unix.md | 25 +----- gridcoinresearch.pro | 1 + src/Makefile.am | 1 + src/compat.h | 2 +- src/netbase.cpp | 18 ++-- src/strlcpy.h | 90 +++++++++++++++++++ src/util.cpp | 85 ++++-------------- 11 files changed, 208 insertions(+), 124 deletions(-) create mode 100644 depends/patches/fontconfig/0001-Avoid-conflicts-with-integer-width-macros-from-TS-18.patch create mode 100644 src/strlcpy.h diff --git a/depends/config.guess b/depends/config.guess index 9e6ad35b56..69ed3e573b 100755 --- a/depends/config.guess +++ b/depends/config.guess @@ -150,14 +150,7 @@ Linux|GNU|GNU/*) #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` - - # If ldd exists, use it to detect musl libc. - if command -v ldd >/dev/null && \ - ldd --version 2>&1 | grep -q ^musl - then - LIBC=musl - fi - ;; + ;; esac # Note: order is significant - the case branches are not exclusive. diff --git a/depends/packages/fontconfig.mk b/depends/packages/fontconfig.mk index 128599ba77..ccb6023a40 100644 --- a/depends/packages/fontconfig.mk +++ b/depends/packages/fontconfig.mk @@ -1,33 +1,29 @@ package=fontconfig +GCCFLAGS?= $(package)_version=2.12.1 -$(package)_download_path=https://www.freedesktop.org/software/fontconfig/release/ +$(package)_download_path=http://www.freedesktop.org/software/fontconfig/release/ $(package)_file_name=$(package)-$($(package)_version).tar.bz2 $(package)_sha256_hash=b449a3e10c47e1d1c7a6ec6e2016cca73d3bd68fbbd4f0ae5cc6b573f7d6c7f3 $(package)_dependencies=freetype expat +$(package)_patches=0001-Avoid-conflicts-with-integer-width-macros-from-TS-18.patch define $(package)_set_vars - $(package)_config_opts=--disable-docs --disable-static --disable-libxml2 --disable-iconv - $(package)_config_opts += --disable-dependency-tracking --enable-option-checking + $(package)_config_opts=--disable-docs --disable-static + $(package)_cxxflags_aarch64_linux = $(GCCFLAGS) + $(package)_cflags_aarch64_linux = $(GCCFLAGS) + $(package)_cxxflags_arm_linux = $(GCCFLAGS) + $(package)_cflags_arm_linux = $(GCCFLAGS) endef define $(package)_config_cmds + patch -p1 < $($(package)_patch_dir)/0001-Avoid-conflicts-with-integer-width-macros-from-TS-18.patch &&\ $($(package)_autoconf) endef -# 2.12.1 uses CHAR_WIDTH which is reserved and clashes with some glibc versions, but newer versions of fontconfig -# have broken makefiles which needlessly attempt to re-generate headers with gperf. -# Instead, change all uses of CHAR_WIDTH, and disable the rule that forces header re-generation. -# This can be removed once the upstream build is fixed. define $(package)_build_cmds - sed -i 's/CHAR_WIDTH/CHARWIDTH/g' fontconfig/fontconfig.h src/fcobjshash.gperf src/fcobjs.h src/fcobjshash.h && \ - sed -i 's/fcobjshash.h: fcobjshash.gperf/fcobjshash.h:/' src/Makefile && \ $(MAKE) endef define $(package)_stage_cmds $(MAKE) DESTDIR=$($(package)_staging_dir) install endef - -define $(package)_postprocess_cmds - rm lib/*.la -endef diff --git a/depends/patches/fontconfig/0001-Avoid-conflicts-with-integer-width-macros-from-TS-18.patch b/depends/patches/fontconfig/0001-Avoid-conflicts-with-integer-width-macros-from-TS-18.patch new file mode 100644 index 0000000000..c60f679e32 --- /dev/null +++ b/depends/patches/fontconfig/0001-Avoid-conflicts-with-integer-width-macros-from-TS-18.patch @@ -0,0 +1,73 @@ +From 20cddc824c6501c2082cac41b162c34cd5fcc530 Mon Sep 17 00:00:00 2001 +From: Khem Raj +Date: Sun, 11 Dec 2016 14:32:00 -0800 +Subject: [PATCH] Avoid conflicts with integer width macros from TS + 18661-1:2014 + +glibc 2.25+ has now defined these macros in +https://sourceware.org/git/?p=glibc.git;a=commit;h=5b17fd0da62bf923cb61d1bb7b08cf2e1f1f9c1a + +Signed-off-by: Khem Raj +--- +Upstream-Status: Submitted + + fontconfig/fontconfig.h | 2 +- + src/fcobjs.h | 2 +- + src/fcobjshash.gperf | 2 +- + src/fcobjshash.h | 2 +- + 4 files changed, 4 insertions(+), 4 deletions(-) + +Index: fontconfig-2.12.1/fontconfig/fontconfig.h +=================================================================== +--- fontconfig-2.12.1.orig/fontconfig/fontconfig.h ++++ fontconfig-2.12.1/fontconfig/fontconfig.h +@@ -128,7 +128,8 @@ typedef int FcBool; + #define FC_USER_CACHE_FILE ".fonts.cache-" FC_CACHE_VERSION + + /* Adjust outline rasterizer */ +-#define FC_CHAR_WIDTH "charwidth" /* Int */ ++#define FC_CHARWIDTH "charwidth" /* Int */ ++#define FC_CHAR_WIDTH FC_CHARWIDTH + #define FC_CHAR_HEIGHT "charheight"/* Int */ + #define FC_MATRIX "matrix" /* FcMatrix */ + +Index: fontconfig-2.12.1/src/fcobjs.h +=================================================================== +--- fontconfig-2.12.1.orig/src/fcobjs.h ++++ fontconfig-2.12.1/src/fcobjs.h +@@ -51,7 +51,7 @@ FC_OBJECT (DPI, FcTypeDouble, NULL) + FC_OBJECT (RGBA, FcTypeInteger, NULL) + FC_OBJECT (SCALE, FcTypeDouble, NULL) + FC_OBJECT (MINSPACE, FcTypeBool, NULL) +-FC_OBJECT (CHAR_WIDTH, FcTypeInteger, NULL) ++FC_OBJECT (CHARWIDTH, FcTypeInteger, NULL) + FC_OBJECT (CHAR_HEIGHT, FcTypeInteger, NULL) + FC_OBJECT (MATRIX, FcTypeMatrix, NULL) + FC_OBJECT (CHARSET, FcTypeCharSet, FcCompareCharSet) +Index: fontconfig-2.12.1/src/fcobjshash.gperf +=================================================================== +--- fontconfig-2.12.1.orig/src/fcobjshash.gperf ++++ fontconfig-2.12.1/src/fcobjshash.gperf +@@ -44,7 +44,7 @@ int id; + "rgba",FC_RGBA_OBJECT + "scale",FC_SCALE_OBJECT + "minspace",FC_MINSPACE_OBJECT +-"charwidth",FC_CHAR_WIDTH_OBJECT ++"charwidth",FC_CHARWIDTH_OBJECT + "charheight",FC_CHAR_HEIGHT_OBJECT + "matrix",FC_MATRIX_OBJECT + "charset",FC_CHARSET_OBJECT +Index: fontconfig-2.12.1/src/fcobjshash.h +=================================================================== +--- fontconfig-2.12.1.orig/src/fcobjshash.h ++++ fontconfig-2.12.1/src/fcobjshash.h +@@ -284,7 +284,7 @@ FcObjectTypeLookup (register const char + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str43,FC_CHARSET_OBJECT}, + {-1}, + #line 47 "fcobjshash.gperf" +- {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str45,FC_CHAR_WIDTH_OBJECT}, ++ {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str45,FC_CHARWIDTH_OBJECT}, + #line 48 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str46,FC_CHAR_HEIGHT_OBJECT}, + #line 55 "fcobjshash.gperf" + diff --git a/doc/assets-attribution.md b/doc/assets-attribution.md index 878a7f4d30..47c256d060 100644 --- a/doc/assets-attribution.md +++ b/doc/assets-attribution.md @@ -1,6 +1,10 @@ Assets Attribution =================== +Code: src/strlcpy.h +Author: Todd C. Miller +License: ISC + Icon: src/qt/res/icons/clock*.png, src/qt/res/src/*.svg Designer: Wladimir van der Laan @@ -32,7 +36,7 @@ License: LGPL Icon: scripts/img/reload.xcf (modified),src/qt/res/movies/update_spinner.mng Icon Pack: Kids Designer: Everaldo (Everaldo Coelho) -License: GNU/GPL +License: GNU/GPL Site: http://findicons.com/icon/17102/reload?id=17102 Gridcoin Logo: CryptoCoinTalk Community diff --git a/doc/build-unix.md b/doc/build-unix.md index 83419eb377..f5200870fe 100644 --- a/doc/build-unix.md +++ b/doc/build-unix.md @@ -81,7 +81,7 @@ Dependency Build Instructions: Ubuntu & Debian ---------------------------------------------- Build requirements: - sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils + sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils Options when installing required Boost library files: @@ -198,29 +198,6 @@ Once these are installed, they will be found by configure and a gridcoinresearch built by default. -Dependency Build Instructions: Alpine Linux ----------------------------------------------- - -Build requirements: - - apk add autoconf automake boost-dev build-base curl-dev db-dev libtool libzip-dev miniupnpc-dev openssl-dev pkgconfig - -**Note:** Alpine Linux only includes Berkeley DB version 5.3 in the package repositories, so we must -run _configure_ with the following option: - - ./configure --with-incompatible-bdb - -To build the wallet with Berkeley DB version 4.8, we need to compile the library from source. See the -[README](../depends/README.md) in the depends directory for one option. - -Dependencies for the GUI: Alpine Linux ------------------------------------------ - -To build the Qt GUI on Alpine Linux, we need these dependencies: - - apk add libqrencode-dev protobuf-dev qt5-qtbase-dev qt5-qtcharts-dev qt5-qtsvg-dev qt5-qttools-dev - - Setup and Build Example: Arch Linux ----------------------------------- This example lists the steps necessary to setup and build a command line only of the latest changes on Arch Linux: diff --git a/gridcoinresearch.pro b/gridcoinresearch.pro index f84f2a73b4..e5006dd7ac 100755 --- a/gridcoinresearch.pro +++ b/gridcoinresearch.pro @@ -212,6 +212,7 @@ HEADERS += src/qt/bitcoingui.h \ src/scrypt.h \ src/pbkdf2.h \ src/serialize.h \ + src/strlcpy.h \ src/main.h \ src/miner.h \ src/net.h \ diff --git a/src/Makefile.am b/src/Makefile.am index e284bddf0c..aeb02157b2 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -137,6 +137,7 @@ GRIDCOIN_CORE_H = \ serialize.h \ span.h \ streams.h \ + strlcpy.h \ support/allocators/secure.h \ support/allocators/zeroafterfree.h \ support/cleanse.h \ diff --git a/src/compat.h b/src/compat.h index d49fca83fd..a3075e467c 100644 --- a/src/compat.h +++ b/src/compat.h @@ -40,7 +40,7 @@ #else #include #include -#include +#include #include #include #include diff --git a/src/netbase.cpp b/src/netbase.cpp index 14331ec04b..db10e855a9 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -12,11 +12,11 @@ #endif #ifndef WIN32 -#include +#include #endif +#include "strlcpy.h" #include // for to_lower() -#include // for startswith() and endswith() using namespace std; @@ -91,16 +91,18 @@ bool static LookupIntern(const char *pszName, std::vector& vIP, unsign bool LookupHost(const char *pszName, std::vector& vIP, unsigned int nMaxSolutions, bool fAllowLookup) { - std::string str(pszName); - std::string strHost = str; - if (str.empty()) + if (pszName[0] == 0) return false; - if (boost::algorithm::starts_with(str, "[") && boost::algorithm::ends_with(str, "]")) + char psz[256]; + char *pszHost = psz; + strlcpy(psz, pszName, sizeof(psz)); + if (psz[0] == '[' && psz[strlen(psz)-1] == ']') { - strHost = str.substr(1, str.size() - 2); + pszHost = psz+1; + psz[strlen(psz)-1] = 0; } - return LookupIntern(strHost.c_str(), vIP, nMaxSolutions, fAllowLookup); + return LookupIntern(pszHost, vIP, nMaxSolutions, fAllowLookup); } bool Lookup(const char *pszName, std::vector& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions) diff --git a/src/strlcpy.h b/src/strlcpy.h new file mode 100644 index 0000000000..2cc786e953 --- /dev/null +++ b/src/strlcpy.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 1998 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef BITCOIN_STRLCPY_H +#define BITCOIN_STRLCPY_H + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +inline size_t strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0) + { + while (--n != 0) + { + if ((*d++ = *s++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) + { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +inline size_t strlcat(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') + { + if (n != 1) + { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} +#endif diff --git a/src/util.cpp b/src/util.cpp index a9689ac226..99edb9e53f 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -5,13 +5,12 @@ #include "netbase.h" // for AddTimeData #include "sync.h" +#include "strlcpy.h" #include "version.h" #include "ui_interface.h" #include "util.h" -#include // for to_lower() #include -#include // for startswith() and endswith() #include //For day of year #include #include @@ -355,24 +354,24 @@ void ParseParameters(int argc, const char* const argv[]) mapMultiArgs.clear(); for (int i = 1; i < argc; i++) { - std::string str(argv[i]); - std::string strValue; - size_t is_index = str.find('='); - if (is_index != std::string::npos) + char psz[10000]; + strlcpy(psz, argv[i], sizeof(psz)); + char* pszValue = (char*)""; + if (strchr(psz, '=')) { - strValue = str.substr(is_index+1); - str = str.substr(0, is_index); + pszValue = strchr(psz, '='); + *pszValue++ = '\0'; } -#ifdef WIN32 - boost::to_lower(str); - if (boost::algorithm::starts_with(str, "/")) - str = "-" + str.substr(1); -#endif - if (str[0] != '-') + #ifdef WIN32 + _strlwr(psz); + if (psz[0] == '/') + psz[0] = '-'; + #endif + if (psz[0] != '-') break; - mapArgs[str] = strValue; - mapMultiArgs[str].push_back(strValue); + mapArgs[psz] = pszValue; + mapMultiArgs[psz].push_back(pszValue); } // New 0.6 features: @@ -876,7 +875,7 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample) if (abs64(nTimeOffset) >= 70 * 60) { nTimeOffset = 0; - + static bool fDone; if (!fDone) { @@ -1070,33 +1069,7 @@ bool ThreadHandler::createThread(void(*pfn)(ThreadHandlerPtr), ThreadHandlerPtr { try { -#if defined(__linux__) && !defined(__GLIBCXX__) - // - // Explicitly set the stack size for this thread to 2 MB. - // - // This supports compilation with musl libc which provides a default - // stack size of 128 KB. Gridcoin chose the scrypt algorithm to hash - // blocks early in the chain. The selected scrypt parameters require - // more than 128 KB of stack space, so we need to increase the stack - // size for threads that hash blocks. - // - // This function is used to create those threads. Since we will port - // Bitcoin's newer thread management utilities, I will not take time - // to generalize this patch. Ideally, we should specify a stack size - // suitable for the application instead of relying on the default of - // the libc implementation. For now, we will let glibc do its thing. - // 2 MB is the typical default for glibc on x86 platforms so this is - // the size we'll start with. After testing, we may choose a smaller - // stack size. This patch may apply to other libc implementations as - // well. - // - boost::thread::attributes attrs; - attrs.set_stack_size(2 << 20); - - boost::thread *newThread = new boost::thread(attrs, std::bind(pfn, parg)); -#else boost::thread *newThread = new boost::thread(pfn, parg); -#endif threadGroup.add_thread(newThread); threadMap[tname] = newThread; } catch(boost::thread_resource_error &e) { @@ -1110,33 +1083,7 @@ bool ThreadHandler::createThread(void(*pfn)(void*), void* parg, const std::strin { try { -#if defined(__linux__) && !defined(__GLIBCXX__) - // - // Explicitly set the stack size for this thread to 2 MB. - // - // This supports compilation with musl libc which provides a default - // stack size of 128 KB. Gridcoin chose the scrypt algorithm to hash - // blocks early in the chain. The selected scrypt parameters require - // more than 128 KB of stack space, so we need to increase the stack - // size for threads that hash blocks. - // - // This function is used to create those threads. Since we will port - // Bitcoin's newer thread management utilities, I will not take time - // to generalize this patch. Ideally, we should specify a stack size - // suitable for the application instead of relying on the default of - // the libc implementation. For now, we will let glibc do its thing. - // 2 MB is the typical default for glibc on x86 platforms so this is - // the size we'll start with. After testing, we may choose a smaller - // stack size. This patch may apply to other libc implementations as - // well. - // - boost::thread::attributes attrs; - attrs.set_stack_size(2 << 20); - - boost::thread *newThread = new boost::thread(attrs, std::bind(pfn, parg)); -#else boost::thread *newThread = new boost::thread(pfn, parg); -#endif threadGroup.add_thread(newThread); threadMap[tname] = newThread; } catch(boost::thread_resource_error &e) {