Skip to content

Commit 10552e4

Browse files
committed
[libm] Fix Building For ARM64 & Add Stubs
It really sucks that Apple no longer open sources `libm`... I'm not sure if we should replace `libm` with another macOS friendly math library, or try to implement the math stubs...
1 parent ad810d3 commit 10552e4

File tree

6 files changed

+111
-3
lines changed

6 files changed

+111
-3
lines changed

src/libm/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ if (TARGET_i386 OR TARGET_x86_64)
151151
Source/Intel/truncl.S
152152
Source/Intel/trunc.S
153153
)
154+
elseif (TARGET_ARM64)
155+
set(libm_sources ${libm_sources}
156+
Source/ARM/nan.c
157+
Source/ARM/fpclassify.c
158+
Source/ARM/logb.c
159+
Source/ARM/logbf.c
160+
Source/ARM/stub.c
161+
)
154162
endif ()
155163

156164
# Gross hack to rename symbols in $fenv_access_off variants
@@ -164,6 +172,10 @@ else ()
164172
endif ()
165173
make_fat(system_m_extra)
166174

175+
if (TARGET_i386 OR TARGET_x86_64)
176+
set (LIBM_ALIAS_LIST "-Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libm_Intel.a.alias -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libmathCommonIntel.alias")
177+
endif ()
178+
167179
set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_m.dylib")
168180
add_circular(system_m FAT
169181
SOURCES
@@ -174,7 +186,7 @@ add_circular(system_m FAT
174186
system_c
175187
system_dyld
176188
LINK_FLAGS
177-
"-Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libm_Intel.a.alias -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libmathCommonIntel.alias"
189+
"${LIBM_ALIAS_LIST}"
178190
)
179191
#set_property(TARGET system_m APPEND_STRING PROPERTY LINK_FLAGS
180192
# "-Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libm_Intel.a.alias -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libmathCommonIntel.alias")

src/libm/Source/ARM/stub.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
double scalbn(double x, int exp) {
2+
__builtin_trap();
3+
return 0.0;
4+
}
5+
6+
float scalbnf(float x, int exp) {
7+
__builtin_trap();
8+
return 0.0;
9+
}
10+
11+
long double scalbnl(long double x, int exp) {
12+
__builtin_trap();
13+
return 0.0;
14+
}
15+
16+
long double logbl(long double x) {
17+
__builtin_trap();
18+
return 0.0;
19+
}
20+
21+
long double nanl(const char *tagp) {
22+
__builtin_trap();
23+
return 0.0;
24+
}
25+
26+
double cos(double x) {
27+
__builtin_trap();
28+
return 0.0;
29+
}
30+
31+
float cosf(float x) {
32+
__builtin_trap();
33+
return 0.0;
34+
}
35+
36+
double pow(double x, double y) {
37+
__builtin_trap();
38+
return 0.0;
39+
}
40+
41+
double sin(double x) {
42+
__builtin_trap();
43+
return 0.0;
44+
}
45+
46+
float sinf(float x) {
47+
__builtin_trap();
48+
return 0.0;
49+
}
50+
51+
double acos(double x) {
52+
__builtin_trap();
53+
return 0.0;
54+
}
55+
56+
double asin(double x) {
57+
__builtin_trap();
58+
return 0.0;
59+
}
60+
61+
double atan(double x) {
62+
__builtin_trap();
63+
return 0.0;
64+
}
65+
66+
double atan2(double y, double x) {
67+
__builtin_trap();
68+
return 0.0;
69+
}
70+
71+
double log(double x) {
72+
__builtin_trap();
73+
return 0.0;
74+
}
75+
76+
double modf(double value, double *iptr) {
77+
__builtin_trap();
78+
return 0.0;
79+
}
80+
81+
double tan(double x) {
82+
__builtin_trap();
83+
return 0.0;
84+
}
85+
86+
double fmod(double x, double y) {
87+
__builtin_trap();
88+
return 0.0;
89+
}
90+
91+
double log2(double x) {
92+
__builtin_trap();
93+
return 0.0;
94+
}

src/libm/Source/fenv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "architecture/ppc/fenv.h"
2727
#elif (defined (__i386__) || defined( __x86_64__ ))
2828
#include "architecture/i386/fenv.h"
29-
#elif defined(__arm__)
29+
#elif defined(__arm__) || defined(__arm64__)
3030
#include "architecture/arm/fenv.h"
3131
#else
3232
#error Unknown architecture

src/libm/Source/math.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "architecture/ppc/math.h"
2727
#elif (defined (__i386__) || defined( __x86_64__ ))
2828
#include "architecture/i386/math.h"
29-
#elif defined(__arm__)
29+
#elif defined(__arm__) || defined(__arm64__)
3030
#include "architecture/arm/math.h"
3131
#else
3232
#error Unknown architecture
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../Source/ARM/fenv.h
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../Source/ARM/math.h

0 commit comments

Comments
 (0)