From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

libc: replace weak_alias and wrapper functions with linker symbol copy mechanism

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 <jwkozac...@gmail.com>
Message-Id: <20200805233028.10528-1-jwkozac...@gmail.com>

---
diff --git a/Makefile b/Makefile
--- 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
--- 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
--- a/libc/math/aliases.c
+++ b/libc/math/aliases.c
@@ -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
--- 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
--- 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
--- 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
--- 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;
 }

-- 
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 osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/00000000000036aaba05ac30b8e8%40google.com.

Reply via email to