From 3005d9e3487a40c6e5bba99bc37e0944a2c25e3f Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Thu, 5 Jan 2023 00:22:48 -0800 Subject: Really fix #1722 --- src/bun.js/bindings/glibc-versions-hack.cpp | 42 +++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/bun.js/bindings/glibc-versions-hack.cpp') diff --git a/src/bun.js/bindings/glibc-versions-hack.cpp b/src/bun.js/bindings/glibc-versions-hack.cpp index 1cfce5fb4..1be279202 100644 --- a/src/bun.js/bindings/glibc-versions-hack.cpp +++ b/src/bun.js/bindings/glibc-versions-hack.cpp @@ -40,8 +40,41 @@ extern "C" int __wrap_statx(int fd, const char* path, int flags, } extern "C" int __real_fcntl(int fd, int cmd, ...); -extern "C" double __real_exp(double x); -extern "C" double __real_log(double x); +typedef double (*MathFunction)(double); + +static inline double __real_exp(double x) +{ + static MathFunction function = nullptr; + if (UNLIKELY(function == nullptr)) { + function = reinterpret_cast(dlsym(nullptr, "exp")); + if (UNLIKELY(function == nullptr)) + abort(); + } + + return function(x); +} +static inline double __real_log(double x) +{ + static MathFunction function = nullptr; + if (UNLIKELY(function == nullptr)) { + function = reinterpret_cast(dlsym(nullptr, "log")); + if (UNLIKELY(function == nullptr)) + abort(); + } + + return function(x); +} +static inline double __real_log2(double x) +{ + static MathFunction function = nullptr; + if (UNLIKELY(function == nullptr)) { + function = reinterpret_cast(dlsym(nullptr, "log2")); + if (UNLIKELY(function == nullptr)) + abort(); + } + + return function(x); +} extern "C" int __wrap_fcntl(int fd, int cmd, ...) { @@ -79,6 +112,11 @@ extern "C" double __wrap_log(double x) return __real_log(x); } +extern "C" double __wrap_log2(double x) +{ + return __real_log2(x); +} + #ifndef _MKNOD_VER #define _MKNOD_VER 1 #endif -- cgit v1.2.3