This patch eliminates 3 wrapper functions in libc/math/aliases.c and 3 week_alias macro defined symbols in libc/math/finite*.c using new linker symbol copy mechanism designed by Nadav.
I have also replaced 3 __finite*( functions with finite*( ones which will make it easy to drop all 3 libc/math/finite*.c files once we upgrade to musl 1.1.24 which provides the finite*( functions. Finally this patch also adds some simple unit tests to verify that modified functions still work. Signed-off-by: Waldemar Kozaczuk <[email protected]> --- Makefile | 3 +-- libc/aliases.ld | 13 +++++++++++++ libc/math/aliases.c | 36 ------------------------------------ libc/math/finite.c | 4 +--- libc/math/finitef.c | 4 +--- libc/math/finitel.c | 4 +--- tests/tst-math.cc | 15 +++++++++++++++ 7 files changed, 32 insertions(+), 47 deletions(-) delete mode 100644 libc/math/aliases.c diff --git a/Makefile b/Makefile index 9bab08c0..78590d40 100644 --- a/Makefile +++ b/Makefile @@ -1164,7 +1164,7 @@ musl += math/fminl.o musl += math/fmod.o musl += math/fmodf.o musl += math/fmodl.o -libc += math/finite.o +libc += math/finite.o #This 3 libc modules will go away once we upgrade to musl 1.1.24 libc += math/finitef.o libc += math/finitel.o musl += math/frexp.o @@ -1288,7 +1288,6 @@ musl += math/tgammal.o musl += math/trunc.o musl += math/truncf.o musl += math/truncl.o -libc += math/aliases.o # Issue #867: Gcc 4.8.4 has a bug where it optimizes the trivial round- # related functions incorrectly - it appears to convert calls to any diff --git a/libc/aliases.ld b/libc/aliases.ld index 89a87373..a44b7572 100644 --- a/libc/aliases.ld +++ b/libc/aliases.ld @@ -9,4 +9,17 @@ * address. */ +/* network */ __res_init = res_init; + +/* math */ +__exp_finite = exp; +__exp2_finite = exp2; +__log10_finite = log10; +__log2_finite = log2; +__log2f_finite = log2f; +__log_finite = log; +__pow_finite = pow; +__finite = finite; +__finitef = finitef; +__finitel = finitel; diff --git a/libc/math/aliases.c b/libc/math/aliases.c deleted file mode 100644 index b137d530..00000000 --- a/libc/math/aliases.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "libm.h" - -double __exp_finite(double x) -{ - return exp(x); -} - -double __exp2_finite(double x) -{ - return exp2(x); -} - -double __log10_finite(double x) -{ - return log10(x); -} - -double __log2_finite(double x) -{ - return log2(x); -} - -double __log2f_finite(double x) -{ - return log2f(x); -} - -double __log_finite(double x) -{ - return log(x); -} - -double __pow_finite(double x, double y) -{ - return pow(x, y); -} diff --git a/libc/math/finite.c b/libc/math/finite.c index f8465101..c49bf53b 100644 --- a/libc/math/finite.c +++ b/libc/math/finite.c @@ -1,9 +1,7 @@ #include <math.h> #include "libc.h" -int __finite(double x) +int finite(double x) { return isfinite(x); } - -weak_alias(__finite,finite); diff --git a/libc/math/finitef.c b/libc/math/finitef.c index 4dc548f7..57ab73f1 100644 --- a/libc/math/finitef.c +++ b/libc/math/finitef.c @@ -1,9 +1,7 @@ #include <math.h> #include "libc.h" -int __finitef(float x) +int finitef(float x) { return isfinite(x); } - -weak_alias(__finitef,finitef); diff --git a/libc/math/finitel.c b/libc/math/finitel.c index a73c3bc9..b9a19cda 100644 --- a/libc/math/finitel.c +++ b/libc/math/finitel.c @@ -1,9 +1,7 @@ #include <math.h> #include "libc.h" -int __finitel(long double x) +int finitel(long double x) { return isfinite(x); } - -weak_alias(__finitel,finitel); diff --git a/tests/tst-math.cc b/tests/tst-math.cc index 497ce69e..9f9f6ce7 100644 --- a/tests/tst-math.cc +++ b/tests/tst-math.cc @@ -10,6 +10,12 @@ #include <math.h> +extern "C" int __finite(double x); +extern "C" int __finitef(float x); +extern "C" int __finitel(long double x); + +extern "C" double __log10_finite(double x); + #include <iostream> static int tests = 0, fails = 0; @@ -38,6 +44,15 @@ int main(int argc, char **argv) expect(nearbyint(1.3), 1.0); expect(nearbyint(1.7), 2.0); + expect(finite(NAN), 0); + expect(__finite(NAN), 0); + expect(finitel(NAN), 0); + expect(__finitel(NAN), 0); + expect(finitef(NAN), 0); + expect(__finitef(NAN), 0); + + expect(__log10_finite(100), log10(100)); + std::cout << "SUMMARY: " << tests << " tests, " << fails << " failures\n"; return fails == 0 ? 0 : 1; } -- 2.25.1 -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/20200805233028.10528-1-jwkozaczuk%40gmail.com.
