Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ if test x$ac_cv_sys_large_files != x &&
fi

if test x$use_glibc_compat != xno; then
AX_CHECK_LINK_FLAG([-Wl,--wrap=fcntl64], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=fcntl64"])
AX_CHECK_LINK_FLAG([[-Wl,--wrap=__divmoddi4]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=__divmoddi4"])
AX_CHECK_LINK_FLAG([[-Wl,--wrap=log2f]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=log2f"])
case $host in
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,6 @@ endif
bitcoin_bin_ldadd = \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_UTIL) \
$(LIBUNIVALUE) \
$(LIBBITCOIN_ZMQ) \
$(LIBBITCOIN_CONSENSUS) \
Expand All @@ -656,6 +655,7 @@ bitcoin_bin_ldadd = \
$(LIBSECP256K1)

bitcoin_bin_ldadd += $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS) $(SQLITE_LIBS)
bitcoin_bin_ldadd += $(LIBBITCOIN_UTIL)

bitcoind_SOURCES = $(bitcoin_daemon_sources) init/bitcoind.cpp
bitcoind_CPPFLAGS = $(bitcoin_bin_cppflags)
Expand Down
120 changes: 120 additions & 0 deletions src/compat/glibc_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,126 @@
#include <cstddef>
#include <cstdint>

// See https://stackoverflow.com/a/58472959
#if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 28)
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>

#ifdef __i386__
__asm(".symver fcntl64,fcntl@GLIBC_2.1");
#elif defined(__amd64__)
__asm(".symver fcntl64,fcntl@GLIBC_2.2.5");
#elif defined(__arm__)
__asm(".symver fcntl64,fcntl@GLIBC_2.4");
#elif defined(__aarch64__)
__asm(".symver fcntl64,fcntl@GLIBC_2.17");
#elif defined(__powerpc64__)
# ifdef WORDS_BIGENDIAN
__asm(".symver fcntl64,fcntl@GLIBC_2.3");
# else
__asm(".symver fcntl64,fcntl@GLIBC_2.17");
# endif
#elif defined(__riscv)
__asm(".symver fcntl64,fcntl@GLIBC_2.27");
#endif
extern "C" int __wrap_fcntl64(int fd, int cmd, ...)
{
int result;
va_list va;
va_start(va, cmd);

switch (cmd) {
//
// File descriptor flags
//
case F_GETFD: goto takes_void;
case F_SETFD: goto takes_int;

// File status flags
//
case F_GETFL: goto takes_void;
case F_SETFL: goto takes_int;

// File byte range locking, not held across fork() or clone()
//
case F_SETLK: goto takes_flock_ptr;
case F_SETLKW: goto takes_flock_ptr;
case F_GETLK: goto takes_flock_ptr;

// File byte range locking, held across fork()/clone() -- Not POSIX
//
case F_OFD_SETLK: goto takes_flock_ptr;
case F_OFD_SETLKW: goto takes_flock_ptr;
case F_OFD_GETLK: goto takes_flock_ptr;

// Managing I/O availability signals
//
case F_GETOWN: goto takes_void;
case F_SETOWN: goto takes_int;
case F_GETOWN_EX: goto takes_f_owner_ex_ptr;
case F_SETOWN_EX: goto takes_f_owner_ex_ptr;
case F_GETSIG: goto takes_void;
case F_SETSIG: goto takes_int;

// Notified when process tries to open or truncate file (Linux 2.4+)
//
case F_SETLEASE: goto takes_int;
case F_GETLEASE: goto takes_void;

// File and directory change notification
//
case F_NOTIFY: goto takes_int;

// Changing pipe capacity (Linux 2.6.35+)
//
case F_SETPIPE_SZ: goto takes_int;
case F_GETPIPE_SZ: goto takes_void;

// File sealing (Linux 3.17+)
//
case F_ADD_SEALS: goto takes_int;
case F_GET_SEALS: goto takes_void;

// File read/write hints (Linux 4.13+)
//
case F_GET_RW_HINT: goto takes_uint64_t_ptr;
case F_SET_RW_HINT: goto takes_uint64_t_ptr;
case F_GET_FILE_RW_HINT: goto takes_uint64_t_ptr;
case F_SET_FILE_RW_HINT: goto takes_uint64_t_ptr;

default:
fprintf(stderr, "fcntl64 workaround got unknown F_XXX constant: %d\n", cmd);
exit(1);
}

takes_void:
va_end(va);
return fcntl64(fd, cmd);

takes_int:
result = fcntl64(fd, cmd, va_arg(va, int));
va_end(va);
return result;

takes_flock_ptr:
result = fcntl64(fd, cmd, va_arg(va, struct flock*));
va_end(va);
return result;

takes_f_owner_ex_ptr:
result = fcntl64(fd, cmd, va_arg(va, struct f_owner_ex*));
va_end(va);
return result;

takes_uint64_t_ptr:
result = fcntl64(fd, cmd, va_arg(va, uint64_t*));
va_end(va);
return result;
}
#endif

#if defined(__i386__) || defined(__arm__)

extern "C" int64_t __udivmoddi4(uint64_t u, uint64_t v, uint64_t* rp);
Expand Down
1 change: 1 addition & 0 deletions test/lint/lint-locale-dependence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export LC_ALL=C
KNOWN_VIOLATIONS=(
"src/bitcoin-tx.cpp.*stoul"
"src/bitcoin-tx.cpp.*trim_right"
"src/compat/glibc_compat.cpp:.*fprintf"
"src/dbwrapper.cpp.*stoul"
"src/dbwrapper.cpp:.*vsnprintf"
"src/httprpc.cpp.*trim"
Expand Down