Bitcoin ABC  0.22.12
P2P Digital Currency
glibc_compat.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2014 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #if defined(HAVE_CONFIG_H)
6 #include <config/bitcoin-config.h>
7 #endif
8 
9 #include <cstdarg>
10 #include <cstdint>
11 
12 #if defined(__i386__) || defined(__arm__)
13 
14 extern "C" int64_t __udivmoddi4(uint64_t u, uint64_t v, uint64_t *rp);
15 
16 extern "C" int64_t __wrap___divmoddi4(int64_t u, int64_t v, int64_t *rp) {
17  int32_t c1 = 0, c2 = 0;
18  int64_t uu = u, vv = v;
19  int64_t w;
20  int64_t r;
21 
22  if (uu < 0) {
23  c1 = ~c1, c2 = ~c2, uu = -uu;
24  }
25  if (vv < 0) {
26  c1 = ~c1, vv = -vv;
27  }
28 
29  w = __udivmoddi4(uu, vv, (uint64_t *)&r);
30  if (c1) w = -w;
31  if (c2) r = -r;
32 
33  *rp = r;
34  return w;
35 }
36 #endif
37 
38 extern "C" float log2f_old(float x);
39 #ifdef __i386__
40 __asm(".symver log2f_old,[email protected]_2.1");
41 #elif defined(__amd64__)
42 __asm(".symver log2f_old,[email protected]_2.2.5");
43 #elif defined(__arm__)
44 __asm(".symver log2f_old,[email protected]_2.4");
45 #elif defined(__aarch64__)
46 __asm(".symver log2f_old,[email protected]_2.17");
47 #endif
48 extern "C" float __wrap_log2f(float x) {
49  return log2f_old(x);
50 }
51 
52 /*
53  * Starting with GLIBC_2.28, the `fcntl()` function has a new variant
54  * `fcntl64()`:
55  * https://gitlab.com/freedesktop-sdk/mirrors/glibc/commit/06ab719d30b01da401150068054d3b8ea93dd12f
56  * (link to a mirror, glibc has no online source browser).
57  *
58  * See also the release notes for the 2.28 version:
59  * https://www.sourceware.org/ml/libc-alpha/2018-08/msg00003.html
60  *
61  * This is intended to fix a bug related to large file support on architectures
62  * where off_t and off64_t are not the same underlying type.
63  * To remain compatible with the previous versions, the GLIBC offers a
64  * compatibility symbol for these architectures. We can link the new `fcntl()`
65  * and `fcntl64()` against this symbol with the help of a wrapper.
66  */
67 #if defined(HAVE_CONFIG_H) && !defined(HAVE_LARGE_FILE_SUPPORT)
68 extern "C" int fcntl_old(int fd, int cmd, ...);
69 #ifdef __i386__
70 __asm(".symver fcntl_old,[email protected]_2.0");
71 #elif defined(__amd64__)
72 __asm(".symver fcntl_old,[email protected]_2.2.5");
73 #elif defined(__arm__)
74 __asm(".symver fcntl_old,[email protected]_2.4");
75 #elif defined(__aarch64__)
76 __asm(".symver fcntl_old,[email protected]_2.17");
77 #endif
78 
79 extern "C" int __wrap_fcntl(int fd, int cmd, ...) {
80  int ret;
81  va_list vargs;
82  va_start(vargs, cmd);
83  ret = fcntl_old(fd, cmd, va_arg(vargs, void *));
84  va_end(vargs);
85  return ret;
86 }
87 extern "C" int __wrap_fcntl64(int fd, int cmd, ...) {
88  int ret;
89  va_list vargs;
90  va_start(vargs, cmd);
91  ret = fcntl_old(fd, cmd, va_arg(vargs, void *));
92  va_end(vargs);
93  return ret;
94 }
95 #endif
float __wrap_log2f(float x)
float log2f_old(float x)