diff --git a/src/compat/byteswap.h b/src/compat/byteswap.h index 8b5d5b62f..c30b60189 100644 --- a/src/compat/byteswap.h +++ b/src/compat/byteswap.h @@ -1,64 +1,64 @@ // Copyright (c) 2014-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_COMPAT_BYTESWAP_H #define BITCOIN_COMPAT_BYTESWAP_H #if defined(HAVE_CONFIG_H) -#include "config/bitcoin-config.h" +#include #endif #include #if defined(HAVE_BYTESWAP_H) #include #endif #if defined(__APPLE__) #if !defined(bswap_16) // Mac OS X / Darwin features; we include a check for bswap_16 because if it is // already defined, protobuf has defined these macros for us already; if it // isn't, we do it ourselves. In either case, we get the exact same result // regardless which path was taken #include #define bswap_16(x) OSSwapInt16(x) #define bswap_32(x) OSSwapInt32(x) #define bswap_64(x) OSSwapInt64(x) #endif // !defined(bswap_16) #else // Non-Mac OS X / non-Darwin #if HAVE_DECL_BSWAP_16 == 0 inline uint16_t bswap_16(uint16_t x) { return (x >> 8) | ((x & 0x00ff) << 8); } #endif // HAVE_DECL_BSWAP16 #if HAVE_DECL_BSWAP_32 == 0 inline uint32_t bswap_32(uint32_t x) { return (((x & 0xff000000U) >> 24) | ((x & 0x00ff0000U) >> 8) | ((x & 0x0000ff00U) << 8) | ((x & 0x000000ffU) << 24)); } #endif // HAVE_DECL_BSWAP32 #if HAVE_DECL_BSWAP_64 == 0 inline uint64_t bswap_64(uint64_t x) { return (((x & 0xff00000000000000ull) >> 56) | ((x & 0x00ff000000000000ull) >> 40) | ((x & 0x0000ff0000000000ull) >> 24) | ((x & 0x000000ff00000000ull) >> 8) | ((x & 0x00000000ff000000ull) << 8) | ((x & 0x0000000000ff0000ull) << 24) | ((x & 0x000000000000ff00ull) << 40) | ((x & 0x00000000000000ffull) << 56)); } #endif // HAVE_DECL_BSWAP64 #endif // defined(__APPLE__) #endif // BITCOIN_COMPAT_BYTESWAP_H diff --git a/src/compat/endian.h b/src/compat/endian.h index 3bac1ddd5..6e3e795c1 100644 --- a/src/compat/endian.h +++ b/src/compat/endian.h @@ -1,172 +1,172 @@ // Copyright (c) 2014-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_COMPAT_ENDIAN_H #define BITCOIN_COMPAT_ENDIAN_H #if defined(HAVE_CONFIG_H) -#include "config/bitcoin-config.h" +#include #endif -#include "compat/byteswap.h" +#include #include #if defined(HAVE_ENDIAN_H) #include #elif defined(HAVE_SYS_ENDIAN_H) #include #endif #if defined(WORDS_BIGENDIAN) #if HAVE_DECL_HTOBE16 == 0 inline uint16_t htobe16(uint16_t host_16bits) { return host_16bits; } #endif // HAVE_DECL_HTOBE16 #if HAVE_DECL_HTOLE16 == 0 inline uint16_t htole16(uint16_t host_16bits) { return bswap_16(host_16bits); } #endif // HAVE_DECL_HTOLE16 #if HAVE_DECL_BE16TOH == 0 inline uint16_t be16toh(uint16_t big_endian_16bits) { return big_endian_16bits; } #endif // HAVE_DECL_BE16TOH #if HAVE_DECL_LE16TOH == 0 inline uint16_t le16toh(uint16_t little_endian_16bits) { return bswap_16(little_endian_16bits); } #endif // HAVE_DECL_LE16TOH #if HAVE_DECL_HTOBE32 == 0 inline uint32_t htobe32(uint32_t host_32bits) { return host_32bits; } #endif // HAVE_DECL_HTOBE32 #if HAVE_DECL_HTOLE32 == 0 inline uint32_t htole32(uint32_t host_32bits) { return bswap_32(host_32bits); } #endif // HAVE_DECL_HTOLE32 #if HAVE_DECL_BE32TOH == 0 inline uint32_t be32toh(uint32_t big_endian_32bits) { return big_endian_32bits; } #endif // HAVE_DECL_BE32TOH #if HAVE_DECL_LE32TOH == 0 inline uint32_t le32toh(uint32_t little_endian_32bits) { return bswap_32(little_endian_32bits); } #endif // HAVE_DECL_LE32TOH #if HAVE_DECL_HTOBE64 == 0 inline uint64_t htobe64(uint64_t host_64bits) { return host_64bits; } #endif // HAVE_DECL_HTOBE64 #if HAVE_DECL_HTOLE64 == 0 inline uint64_t htole64(uint64_t host_64bits) { return bswap_64(host_64bits); } #endif // HAVE_DECL_HTOLE64 #if HAVE_DECL_BE64TOH == 0 inline uint64_t be64toh(uint64_t big_endian_64bits) { return big_endian_64bits; } #endif // HAVE_DECL_BE64TOH #if HAVE_DECL_LE64TOH == 0 inline uint64_t le64toh(uint64_t little_endian_64bits) { return bswap_64(little_endian_64bits); } #endif // HAVE_DECL_LE64TOH #else // WORDS_BIGENDIAN #if HAVE_DECL_HTOBE16 == 0 inline uint16_t htobe16(uint16_t host_16bits) { return bswap_16(host_16bits); } #endif // HAVE_DECL_HTOBE16 #if HAVE_DECL_HTOLE16 == 0 inline uint16_t htole16(uint16_t host_16bits) { return host_16bits; } #endif // HAVE_DECL_HTOLE16 #if HAVE_DECL_BE16TOH == 0 inline uint16_t be16toh(uint16_t big_endian_16bits) { return bswap_16(big_endian_16bits); } #endif // HAVE_DECL_BE16TOH #if HAVE_DECL_LE16TOH == 0 inline uint16_t le16toh(uint16_t little_endian_16bits) { return little_endian_16bits; } #endif // HAVE_DECL_LE16TOH #if HAVE_DECL_HTOBE32 == 0 inline uint32_t htobe32(uint32_t host_32bits) { return bswap_32(host_32bits); } #endif // HAVE_DECL_HTOBE32 #if HAVE_DECL_HTOLE32 == 0 inline uint32_t htole32(uint32_t host_32bits) { return host_32bits; } #endif // HAVE_DECL_HTOLE32 #if HAVE_DECL_BE32TOH == 0 inline uint32_t be32toh(uint32_t big_endian_32bits) { return bswap_32(big_endian_32bits); } #endif // HAVE_DECL_BE32TOH #if HAVE_DECL_LE32TOH == 0 inline uint32_t le32toh(uint32_t little_endian_32bits) { return little_endian_32bits; } #endif // HAVE_DECL_LE32TOH #if HAVE_DECL_HTOBE64 == 0 inline uint64_t htobe64(uint64_t host_64bits) { return bswap_64(host_64bits); } #endif // HAVE_DECL_HTOBE64 #if HAVE_DECL_HTOLE64 == 0 inline uint64_t htole64(uint64_t host_64bits) { return host_64bits; } #endif // HAVE_DECL_HTOLE64 #if HAVE_DECL_BE64TOH == 0 inline uint64_t be64toh(uint64_t big_endian_64bits) { return bswap_64(big_endian_64bits); } #endif // HAVE_DECL_BE64TOH #if HAVE_DECL_LE64TOH == 0 inline uint64_t le64toh(uint64_t little_endian_64bits) { return little_endian_64bits; } #endif // HAVE_DECL_LE64TOH #endif // WORDS_BIGENDIAN #endif // BITCOIN_COMPAT_ENDIAN_H diff --git a/src/compat/glibc_compat.cpp b/src/compat/glibc_compat.cpp index 2a7d6ced2..76f92ecf4 100644 --- a/src/compat/glibc_compat.cpp +++ b/src/compat/glibc_compat.cpp @@ -1,68 +1,68 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #if defined(HAVE_CONFIG_H) -#include "config/bitcoin-config.h" +#include #endif #include #include #if defined(HAVE_SYS_SELECT_H) #include #endif // Prior to GLIBC_2.14, memcpy was aliased to memmove. extern "C" void *memmove(void *a, const void *b, size_t c); extern "C" void *memcpy(void *a, const void *b, size_t c) { return memmove(a, b, c); } extern "C" void __chk_fail(void) __attribute__((__noreturn__)); extern "C" FDELT_TYPE __fdelt_warn(FDELT_TYPE a) { if (a >= FD_SETSIZE) __chk_fail(); return a / __NFDBITS; } extern "C" FDELT_TYPE __fdelt_chk(FDELT_TYPE) __attribute__((weak, alias("__fdelt_warn"))); #if defined(__i386__) || defined(__arm__) extern "C" int64_t __udivmoddi4(uint64_t u, uint64_t v, uint64_t *rp); extern "C" int64_t __wrap___divmoddi4(int64_t u, int64_t v, int64_t *rp) { int32_t c1 = 0, c2 = 0; int64_t uu = u, vv = v; int64_t w; int64_t r; if (uu < 0) { c1 = ~c1, c2 = ~c2, uu = -uu; } if (vv < 0) { c1 = ~c1, vv = -vv; } w = __udivmoddi4(uu, vv, (uint64_t *)&r); if (c1) w = -w; if (c2) r = -r; *rp = r; return w; } #endif extern "C" float log2f_old(float x); #ifdef __i386__ __asm(".symver log2f_old,log2f@GLIBC_2.1"); #elif defined(__amd64__) __asm(".symver log2f_old,log2f@GLIBC_2.2.5"); #elif defined(__arm__) __asm(".symver log2f_old,log2f@GLIBC_2.4"); #elif defined(__aarch64__) __asm(".symver log2f_old,log2f@GLIBC_2.17"); #endif extern "C" float __wrap_log2f(float x) { return log2f_old(x); } diff --git a/src/compat/glibc_sanity.cpp b/src/compat/glibc_sanity.cpp index 2325a4708..80f55562c 100644 --- a/src/compat/glibc_sanity.cpp +++ b/src/compat/glibc_sanity.cpp @@ -1,60 +1,60 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #if defined(HAVE_CONFIG_H) -#include "config/bitcoin-config.h" +#include #endif #include #if defined(HAVE_SYS_SELECT_H) #include #endif extern "C" void *memcpy(void *a, const void *b, size_t c); void *memcpy_int(void *a, const void *b, size_t c) { return memcpy(a, b, c); } namespace { // trigger: Use the memcpy_int wrapper which calls our internal memcpy. // A direct call to memcpy may be optimized away by the compiler. // test: Fill an array with a sequence of integers. memcpy to a new empty array. // Verify that the arrays are equal. Use an odd size to decrease the odds of // the call being optimized away. template bool sanity_test_memcpy() { unsigned int memcpy_test[T]; unsigned int memcpy_verify[T] = {}; for (unsigned int i = 0; i != T; ++i) memcpy_test[i] = i; memcpy_int(memcpy_verify, memcpy_test, sizeof(memcpy_test)); for (unsigned int i = 0; i != T; ++i) { if (memcpy_verify[i] != i) return false; } return true; } #if defined(HAVE_SYS_SELECT_H) // trigger: Call FD_SET to trigger __fdelt_chk. FORTIFY_SOURCE must be defined // as >0 and optimizations must be set to at least -O2. // test: Add a file descriptor to an empty fd_set. Verify that it has been // correctly added. bool sanity_test_fdelt() { fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds); return FD_ISSET(0, &fds); } #endif } // namespace bool glibc_sanity_test() { #if defined(HAVE_SYS_SELECT_H) if (!sanity_test_fdelt()) return false; #endif return sanity_test_memcpy<1025>(); } diff --git a/src/compat/strnlen.cpp b/src/compat/strnlen.cpp index 5b6221395..3c63c8e10 100644 --- a/src/compat/strnlen.cpp +++ b/src/compat/strnlen.cpp @@ -1,17 +1,17 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #if defined(HAVE_CONFIG_H) -#include "config/bitcoin-config.h" +#include #endif #include #if HAVE_DECL_STRNLEN == 0 size_t strnlen(const char *start, size_t max_len) { const char *end = (const char *)memchr(start, '\0', max_len); return end ? (size_t)(end - start) : max_len; } #endif // HAVE_DECL_STRNLEN