updated compatibility (NAV)

This commit is contained in:
Michel van Kessel
2020-12-18 19:31:24 +01:00
parent e4281a84bc
commit 67a0056815
6 changed files with 182 additions and 16 deletions

View File

@@ -6,7 +6,7 @@
#define BITCOIN_COMPAT_BYTESWAP_H
#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
#include <config/bitcoin-config.h>
#endif
#include <stdint.h>
@@ -15,7 +15,7 @@
#include <byteswap.h>
#endif
#if defined(__APPLE__)
#if defined(MAC_OSX)
#if !defined(bswap_16)
@@ -35,9 +35,9 @@
#if HAVE_DECL_BSWAP_16 == 0
inline uint16_t bswap_16(uint16_t x)
{
return (x >> 8) | ((x & 0x00ff) << 8);
return (x >> 8) | (x << 8);
}
#endif // HAVE_DECL_BSWAP16
#endif // HAVE_DECL_BSWAP16 == 0
#if HAVE_DECL_BSWAP_32 == 0
inline uint32_t bswap_32(uint32_t x)
@@ -45,7 +45,7 @@ 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
#endif // HAVE_DECL_BSWAP32 == 0
#if HAVE_DECL_BSWAP_64 == 0
inline uint64_t bswap_64(uint64_t x)
@@ -59,8 +59,8 @@ inline uint64_t bswap_64(uint64_t x)
| ((x & 0x000000000000ff00ull) << 40)
| ((x & 0x00000000000000ffull) << 56));
}
#endif // HAVE_DECL_BSWAP64
#endif // HAVE_DECL_BSWAP64 == 0
#endif // defined(__APPLE__)
#endif // defined(MAC_OSX)
#endif // BITCOIN_COMPAT_BYTESWAP_H

View File

@@ -6,12 +6,12 @@
#define BITCOIN_COMPAT_ENDIAN_H
#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
#include <config/bitcoin-config.h>
#endif
#include <stdint.h>
#include <compat/byteswap.h>
#include "compat/byteswap.h"
#include <stdint.h>
#if defined(HAVE_ENDIAN_H)
#include <endian.h>
@@ -19,6 +19,51 @@
#include <sys/endian.h>
#endif
#ifndef HAVE_CONFIG_H
// While not technically a supported configuration, defaulting to defining these
// DECLs when we were compiled without autotools makes it easier for other build
// systems to build things like libbitcoinconsensus for strange targets.
#ifdef htobe16
#define HAVE_DECL_HTOBE16 1
#endif
#ifdef htole16
#define HAVE_DECL_HTOLE16 1
#endif
#ifdef be16toh
#define HAVE_DECL_BE16TOH 1
#endif
#ifdef le16toh
#define HAVE_DECL_LE16TOH 1
#endif
#ifdef htobe32
#define HAVE_DECL_HTOBE32 1
#endif
#ifdef htole32
#define HAVE_DECL_HTOLE32 1
#endif
#ifdef be32toh
#define HAVE_DECL_BE32TOH 1
#endif
#ifdef le32toh
#define HAVE_DECL_LE32TOH 1
#endif
#ifdef htobe64
#define HAVE_DECL_HTOBE64 1
#endif
#ifdef htole64
#define HAVE_DECL_HTOLE64 1
#endif
#ifdef be64toh
#define HAVE_DECL_BE64TOH 1
#endif
#ifdef le64toh
#define HAVE_DECL_LE64TOH 1
#endif
#endif // HAVE_CONFIG_H
#if defined(WORDS_BIGENDIAN)
#if HAVE_DECL_HTOBE16 == 0

View File

@@ -7,6 +7,14 @@
#endif
#include <cstddef>
#include <cstdint>
#include <errno.h>
#include <glob.h>
#include <poll.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/syscall.h>
#if defined(HAVE_SYS_SELECT_H)
#include <sys/select.h>
@@ -27,3 +35,116 @@ extern "C" FDELT_TYPE __fdelt_warn(FDELT_TYPE a)
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");
#elif defined(__riscv)
__asm(".symver log2f_old,log2f@GLIBC_2.27");
#endif
extern "C" float __wrap_log2f(float x)
{
return log2f_old(x);
}
extern "C" int glob_old(const char * pattern, int flags, int (*errfunc) (const char *epath, int eerrno), glob_t *pglob);
#ifdef __i386__
__asm(".symver glob_old,glob@GLIBC_2.0");
#elif defined(__amd64__)
__asm(".symver glob_old,glob@GLIBC_2.2.5");
#elif defined(__arm__)
__asm(".symver glob_old,glob@GLIBC_2.4");
#elif defined(__aarch64__)
__asm(".symver glob_old,glob@GLIBC_2.17");
#elif defined(__riscv)
__asm(".symver glob_old,glob@GLIBC_2.27");
#endif
extern "C" int __wrap_glob(const char * pattern, int flags, int (*errfunc) (const char *epath, int eerrno), glob_t *pglob)
{
return glob_old(pattern, flags, errfunc, pglob);
}
#if defined(__i386__) || defined(__arm__)
extern "C" int __wrap_glob64(const char * pattern, int flags, int (*errfunc) (const char *epath, int eerrno), glob_t *pglob)
{
return glob_old(pattern, flags, errfunc, pglob);
}
#endif
extern "C" int __poll_chk(struct pollfd *fds, nfds_t nfds, int timeout, size_t fdslen)
{
if(fdslen / sizeof(*fds) < nfds)
__chk_fail();
return poll(fds, nfds, timeout);
}
extern "C" void __explicit_bzero_chk(void *dst, size_t len, size_t dstlen)
{
if (__glibc_unlikely(dstlen < len))
__chk_fail();
explicit_bzero(dst, len);
}
extern "C" int getentropy(void *buf, size_t len)
{
int pre_errno = errno;
int ret;
if (len > 256)
return (-1);
do {
ret = syscall(SYS_getrandom, buf, len, 0);
} while (ret == -1 && errno == EINTR);
if (ret != (int)len)
return (-1);
errno = pre_errno;
return (0);
}
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
extern "C" void* reallocarray(void *optr, size_t nmemb, size_t size)
{
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
nmemb > 0 && SIZE_MAX / nmemb < size) {
errno = ENOMEM;
return NULL;
}
return realloc(optr, size * nmemb);
}

View File

@@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
#include <config/bitcoin-config.h>
#endif
#include <cstddef>
@@ -56,7 +56,7 @@ bool sanity_test_fdelt()
}
#endif
} // anon namespace
} // namespace
bool glibc_sanity_test()
{

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -38,7 +38,7 @@ bool sanity_test_list(unsigned int size)
return true;
}
} // anon namespace
} // namespace
// trigger: string::at(x) on an empty string to trigger __throw_out_of_range_fmt.
// test: force std::string to throw an out_of_range exception. Verify that

View File

@@ -1,9 +1,9 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
// Copyright (c) 2009-2018 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 <config/bitcoin-config.h>
#endif
#include <cstring>