Skip to content

Use architecture-specific version of math.h #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -18,8 +18,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: install Clang
# Note: picking LLVM 15 because that's the one currently included in
# macos-latest. This probably needs an update in the future.
run: brew install llvm@15
- name: Run tests
run: make test CLANG=$(brew --prefix llvm)/bin/clang
run: make test CLANG=$(brew --prefix llvm@15)/bin/clang
Test-Windows:
runs-on: windows-latest
steps:
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ include versions.inc

SYSROOTS = sysroot-macos-x86_64 sysroot-macos-arm64

CLANG ?= clang-13
CLANG ?= clang

DYLDFLAGS = \
-dynamiclib \
@@ -26,12 +26,16 @@ sysroot-%/usr/include: update.sh src/usr/include

sysroot-macos-x86_64: sysroot-macos-x86_64/usr/include sysroot-macos-x86_64/usr/lib/libSystem.dylib
sysroot-macos-x86_64/usr/lib/libSystem.dylib:
mkdir -p sysroot-macos-x86_64/usr/include
cp -rp src/usr/include/x86_64/* sysroot-macos-x86_64/usr/include
mkdir -p $(dir $@)
$(CLANG) $(DYLDFLAGS) --target=x86_64-apple-macos10.12 -o $(dir $@)/libSystem.B.dylib src/x86_64/libSystem.s
ln -sf libSystem.B.dylib $@

sysroot-macos-arm64: sysroot-macos-arm64/usr/include sysroot-macos-arm64/usr/lib/libSystem.dylib
sysroot-macos-arm64/usr/lib/libSystem.dylib:
mkdir -p sysroot-macos-arm64/usr/include
cp -rp src/usr/include/arm64/* sysroot-macos-arm64/usr/include
mkdir -p $(dir $@)
$(CLANG) $(DYLDFLAGS) --target=arm64-apple-macos11 -o $(dir $@)/libSystem.B.dylib src/x86_64/libSystem.s
ln -sf libSystem.B.dylib $@
3 changes: 2 additions & 1 deletion generate-stubs.py
Original file line number Diff line number Diff line change
@@ -36,7 +36,8 @@ def generateStubs(sysroot, outfile, target):

# Parse the src/libSystem.h file to get a list of functions declared in libSystem.
index = clang.cindex.Index.create()
args = args=['--sysroot='+sysroot, '-Werror', '--target='+target]
arch = target.split('-')[0]
args = args=['--sysroot='+sysroot, '-isystem', sysroot+'/usr/include/'+arch, '-Werror', '--target='+target]
tu = index.parse('src/libSystem.h', args=args)
if len(tu.diagnostics):
print('failed to extract function stubs using %s:' % args)
37 changes: 2 additions & 35 deletions src/arm64/libSystem.s
Original file line number Diff line number Diff line change
@@ -28,30 +28,18 @@ ___error:
.global ___fpclassify
___fpclassify:

.global ___fpclassifyd
___fpclassifyd:

.global ___fpclassifyf
___fpclassifyf:

.global ___inf
___inf:

.global ___inff
___inff:

.global ___infl
___infl:
.global ___fpclassifyl
___fpclassifyl:

.global ___math_errhandling
___math_errhandling:

.global ___mb_cur_max
___mb_cur_max:

.global ___nan
___nan:

.global ___opendir2
___opendir2:

@@ -415,9 +403,6 @@ _dprintf:
.global _drand48
_drand48:

.global _drem
_drem:

.global _dup
_dup:

@@ -631,9 +616,6 @@ _filesec_set_property:
.global _filesec_unset_property
_filesec_unset_property:

.global _finite
_finite:

.global _flock
_flock:

@@ -796,9 +778,6 @@ _futimens:
.global _fwrite
_fwrite:

.global _gamma
_gamma:

.global _gcvt
_gcvt:

@@ -1183,9 +1162,6 @@ _madvise:
.global _malloc
_malloc:

.global _matherr
_matherr:

.global _mblen
_mblen:

@@ -1618,9 +1594,6 @@ _rintf:
.global _rintl
_rintl:

.global _rinttol
_rinttol:

.global _rmdir
_rmdir:

@@ -1633,9 +1606,6 @@ _roundf:
.global _roundl
_roundl:

.global _roundtol
_roundtol:

.global _rpmatch
_rpmatch:

@@ -1804,9 +1774,6 @@ _signal:
.global _signgam
_signgam:

.global _significand
_significand:

.global _sin
_sin:

525 changes: 525 additions & 0 deletions src/usr/include/arm64/math.h

Large diffs are not rendered by default.

File renamed without changes.
2 changes: 2 additions & 0 deletions test/hello.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <math.h>

int main(void) {
printf("Hello world!\n");
printf("sqrt(3) = %f\n", sqrt(3));
return 0;
}
5 changes: 4 additions & 1 deletion update.sh
Original file line number Diff line number Diff line change
@@ -33,11 +33,14 @@ wget -P download --no-clobber --no-verbose \
# Order matters: some files are duplicated in different tarballs.
rm -rf $include
mkdir -p $include/sys
mkdir -p $include/x86_64
mkdir -p $include/arm64
mkdir -p $sysroot/usr/local/libexec
tar -C $sysroot/usr/local/libexec --strip-components=1 -xf "download/$AvailabilityVersions.tar.gz" "AvailabilityVersions-$AvailabilityVersions/availability.pl"
tar -C $include --strip-components=1 -xf "download/$CarbonHeaders.tar.gz" "CarbonHeaders-$CarbonHeaders/TargetConditionals.h"
tar -C $include --strip-components=2 -xf "download/$Libc.tar.gz" "Libc-$Libc/include"
tar -C $include --strip-components=3 -xf "download/$Libm.tar.gz" "Libm-$Libm/Source/Intel/math.h"
tar -C $include/x86_64 --strip-components=3 -xf "download/$Libm.tar.gz" "Libm-$Libm/Source/Intel/math.h"
tar -C $include/arm64 --strip-components=3 -xf "download/$Libm.tar.gz" "Libm-$Libm/Source/ARM/math.h"
tar -C $include --strip-components=2 -xf "download/$libmalloc.tar.gz" "libmalloc-$libmalloc/include/malloc"
tar -C $include/sys --strip-components=3 -xf "download/$libpthread.tar.gz" "libpthread-$libpthread/include/sys/_pthread"
tar -C $include --strip-components=3 -xf "download/$xnu.tar.gz" "xnu-$xnu/libsyscall/wrappers/gethostuuid.h"